Here is this article we are going to see how we can install WordPress on NGINX with latest and super fast PHP7 with PHPMyAdmin on Ubuntu 16.04 which is the newest Debian/Ubuntu distribution as of now. We will use MariaDB in replacement of MySQL for database uses and will also install Postfix service to basic internal contact form support. Here is a quick list of what we are going to use…
- Debian 9 / Ubuntu 16.04 LTS
- NGINX (Latest version 1.9.15)
- PHP7.0-FPM (Lightweight PHP)
- MariaDB (Latest version 10.0.24)
- PHPMyAdmin (For easy database access and management)
- Postfix (Basic: Needed for contact forms to work)
Let’s set up a VPS or Dedicated machine which is running on Ubuntu 16.04 LTS, I will suggest LTS only because they have a long-term support and stable enough to secure your machine. I personally like DigitalOcean as it is best and leading cloud hosting company based on Fast SSD hard drive which makes things get processed super fast.
Update the Server for Security Patches
sudo apt-get update
Install NGINX
sudo apt-get install nginx
Install PHP7
sudo apt-get install php7.0-fpm php7.0-cli php7.0-common php7.0-curl php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-xml php7.0-xmlrpc php7.0-zip sudo phpenmod mbstring sudo phpenmod mcrypt
Now here we need to secure the PHP7.0 since it has a small loop for hackers (don’t be panic) by default for which we need to edit PHP.ini file. We can use any text editor like nano or vim. In our case, we are using my favorite editor nano.
sudo nano /etc/php/7.0/fpm/php.ini
Now find “cgi.fix_pathinfo” without quotation mark. Use Ctrl+W to activate the search function in nano editor. Now you will see that its value is set to 1 by default like this cgi.fix_pathinfo=1, so change its value to 0 like this: cgi.fix_pathinfo=0 and save it via Ctrl+O.
Install MariaDB
sudo apt-get install mariadb-client mariadb-server
Since we need to tough the security loopholes let’s make MySQL more secure…
sudo mysql_secure_installation
In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.Enter current password for root (enter for none):
OK, successfully used password, moving on…Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.Remove anonymous users? [Y/n] Y
… Success!Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] Y
… Success!By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.Remove test database and access to it? [Y/n] Y
– Dropping test database…
ERROR 1008 (HY000) at line 1: Can’t drop database ‘test’; database doesn’t exist
… Failed! Not critical, keep moving…
– Removing privileges on test database…
… Success!Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.Reload privilege tables now? [Y/n] Y
… Success!Cleaning up…
All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.Thanks for using MariaDB!
Now here we have successfully installed MariaDB. Since managing database from command line interface is time-consuming we are going to install PHPMyAdmin here which will let you manage the database from a Graphical User Interface.
Install PHPMyAdmin
sudo apt-get install phpmyadmin sudo service nginx restart
While setup you will be asked to choose web server (Apache or Lighttpd) where we will choose none (use tab to navigate) and select Okay. Then we will be asked for configuring database we will choose Yes there and then we will be asked for a password for accessing PHPMyAdmin.
Since root user is disabled in this setup we need to create another root user which we can use to login in PHPMyAdmin, here is how to set up a new root user.
mysql -u root -p CREATE USER 'user'@'localhost' IDENTIFIED BY 'userPassword'; GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES; exit
Here ‘user‘ can be any user you want to choose and use a strong password for that user.
PHPMyAdmin will be accessible from http://IP_or_DomainName/phpmyadmin just make sure that you have pointed your domain name in advance while accessing PHPMyAdmin by the domain name.
Install Postfix
sudo apt-get install postfix
Without Postfix we won’t be able to interact with email functions like forget password email and contact us forms so we need to install one client software and postfix is one which we used here and while setup we do not have to configure anything here just hit okay and let all the value set to default.
Configure NGINX’s Server Blocks
sudo nano /etc/nginx/sites-available/default
Now delete everything using control+k and paste the following configuration which I have made easy to use.
server { listen 80 default_server; root /var/www/html; index index.php index.html index.htm; server_name atulhost.com www.atulhost.com; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { try_files $uri =404; fastcgi_index index.php; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|otf|ttf|woff)$ { add_header Access-Control-Allow-Origin *; add_header Cache-Control "public, max-age=31536000, immutable"; access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } location ~ /\. { deny all; access_log off; log_not_found off; } location /phpmyadmin { root /usr/share/; index index.php; location ~ ^/phpmyadmin/(.+\.php)$ { try_files $uri =404; fastcgi_index index.php; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; } } }
Do not forget to change the domain name from the above configurations. I have used non-www as well as www version of the domain name because we can set anyone default in WordPress itself in Settings » General under WordPress Address (URL) and Site Address (URL) sections.
At the end restart all the services once.
sudo service nginx restart sudo service php7.0-fpm restart sudo service mysql restart
Now the most difficult past…
Install WordPress
Now the WordPress Download… and further configs.
cd /var/www/html sudo wget https://wordpress.org/latest.zip sudo apt-get install zip sudo unzip latest.zip cd wordpress sudo mv * /var/www/html cd .. sudo rm -rf wordpress sudo chown -R www-data:www-data /var/www/
Now we have WordPress files ready and now need to connect it with a Database.
- Open PHPMyAdmin in a browser and create a database over there. Enter into that database and move to Privileges Tab and click on Add User.
- In login information give a username to the database, set host to localhost and give a password. (Better you use a Password Generator option there)
- Not down Database name, Username, and Password. (We need to add them in wp-config.php file)
- Under Database for user section Check/Tick on Grant all privileges on database “DATABASE_NAME”.
- Now click on Go. (Do not check/tick anything under Global privileges section)
Now we have a database ready. Let’s connect WordPress to Database.
sudo mv wp-config-sample.php wp-config.php sudo nano wp-config.php
Edit database name, username, and password; once done save the file. Now go ahead in run WordPress setup from the browser via IP or Domain Name if you have pointed that in advanced.
Finally, we have installed WordPress on NGINX PHP7 with PHPMyAdmin on latest Ubuntu 16.04.
Recommended Tutorials
- Make sFTP Account: How to Create www-data sFTP User Account
- Add Server-Side Cache: How to Enable FastCGI Cache in WordPress
- Free SSL Certificate: Install Let’s Encrypt SSL Certificate in Nginx
- Manage Redirects: 301 Redirect in Nginx
I hope you liked our work if you have any doubt or query regarding this setup let me know by leaving them in the comment section below.
Leave a Reply