Raspberry Pi3(Raspbian/Ubuntu) as Webserver – Complete Guide-Installing (NGINX,CLOUDFLARE,WORDPRESS) - part 2



As we have seen the php sync with nginx, we need to providing some features for wordpress on php, so we are here to change 2 things on php.ini file.
Open the php.ini file which is stored at /etc/php/7.0/fpm. :
sudo nano /etc/php/7.0/fpm/php.ini
Search(CTRL+W) the following line and change the value of upload_max_filesize
upload_max_filesize = 16mSearch for the cgi.fix_pathinfo parameter. We need to uncomment(remove semicolon) the line and change the value from “1′ to “0”:
cgi.fix_pathinfo=0
Hit Control-X and Y to save the configuration.All is Done with php and Nginx
Now,lets move towards database, the ultimate reason for choosing self hosting.
Install MariaDBif you are familiar with MySQL, you will find that MariaDB installation looks almost identical:
sudo apt-get install mariadb-server mariadb-clientOnce installation is completed, we can login using the root account
sudo mysqlIt is not a good idea to use root account for daily operation. So we want to create a super user with all the privileges as root for administration purpose, and disable the remote access of root account later.
CREATE USER ‘username’@’localhost’ IDENTIFIED BY ‘password’;Please replace the username and password of your choice.
GRANT ALL PRIVILEGES ON . TO ‘username’@’localhost’;
FLUSH PRIVILEGES;
exit

Quit the mariaDB and login with the newly created username and password and check if the user has all the privileges settings correctly.
We now need to tighten the security of mariaDB access.
sudo mysql_secure_installation
Answer all the questions with y or n with your required style.Probably choose yynny for simple one.

In order to be able to manage the database table easily via web interface, we install Admineras it is much cleaner and simpler to use than phpmyadmin. Setup Adminer is very straightforward.
sudo mkdir /var/www/html/admin
cd /var/www/html/admin
sudo wget https://www.adminer.org/static/download/4.3.1/adminer-4.3.1-mysql-en.php

Rename the file to adminer.php for easier access.
sudo mv adminer-4.3.1-mysql-en.php adminer.phpTo use the Adminer, run the browser with http://localhost/admin/adminer.php
We don’t want others to access the directory without permission, it would be good to only allow for accessing via internal IP but block access from public IP.
To do that, we need to configure the nginx for the /admin directory access:
sudo nano /etc/nginx/sites-available/defaultInsert the following section within the server section, right after the rest of location directives:
# Only allow access of /admin and wp-admin via internal IP
location ~ /admin/.*\.php$ {
   allow 192.168.0.0/24;
   deny all;
   include snippets/fastcgi-php.conf;
   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
Once the file is saved, we need to restart the server for the new setting to take effect, but would be good to test the setting prior restart.
sudo nginx -t
sudo service nginx restart
Incase you find any error, dont worry about it now, i will share all configuration file in the later half so that you could easily cross check.
We are ready to install WordPress. First we want to delete the index.php that we previously created for testing php activation as well as the default Nginx index.html file before downloading WordPress.
cd /var/www/html/
sudo rm index.*
sudo wget https://wordpress.org/latest.tar.gz

Upzip the file which will create a folder called wordpress, and we want to move all the content to the current directory, and then delete the empty director left over as well as the downloaded source file.
sudo tar xzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz
Add a robots.txt file to inform crawlers not to crawl certain directories, create the file using:
sudo nano robots.txtInput the follow lines:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-includes/
Allow: /wp-includes/js/*
Disallow: /admin/

Press Control-x to save file and exit the editor.
The files downloaded belong to user ‘nobody’, we should change the ownership of the html directory to Nginx user www-data:
sudo chown -R www-data: .
create a database which will be used by WordPress. Login to mariaDB with username and password:
mysql -u username -pCreate a database and then exit the mariaDB.(Username of yours and password in the next step)
CREATE DATABASE wordpress;
exit
Everything is done except link update hence we are going to install wordpress via localhost
Goto localhost and install wordpress
wordpress on rpi3
To eliminate permalink errors, do this
sudo nano /etc/nginx/sites-available/defaultScroll down to find the location / section, and comment out (add a # in front of the line) the original try_files directive and add a new try_files directive as following line.
#try_files $uri $uri/ =404;(Comment this line)
try_files $uri $uri/ /index.php?$args;
Now save the file and reload the nginx server.
sudo service nginx reload
Everything is done between php and wordpress, now its time for cloudflare sync.

Post a Comment

0 Comments