Install WordPress 4.7 using Nginx in Debian, Ubuntu and Linux Mint

NGINX (pronounced engine-x) is an Open Source powerful, light and flexible HTTP server that has increased in popularity on last years and now is the main server interface that powers some of the most huge-traffic websites this days, like Facebook, WordPress, Sourceforge or others.

What makes it so fast and reliable is the fact that it uses the same modular design as Apache, but has a different approach regarding web sockets, using an event-driven – asynchronous architecture that does not spawn processes as fast as it receives requests and also uses simple configuration files.

For Ubuntu and Debian based systems, Nginx is already compiled as a package in their repositories and can be installed through apt-get Package Utility.

Suggested Read: How to Install WordPress 4.7 Using Apache or Nginx on RHEL/CentOS/Fedora

It also supports Virtual Hosts like Apache and uses a Fastcgi channel to communicate with PHP files on server through PHP5 FPM.

This tutorial covers installing and basic file configurations for Nginx to host a WordPress CMS website on a Virtual Host and setting applies to Ubuntu versions from 12.04-16.10, Debian 7-9 and Linux Mint 17-18.

Requirements

The previous tutorial on Installing WordPress with Apache on Ubuntu, Debian and Linux Mint systems, all steps mandatory, except Apache and PhpMyAdmin configurations.

  1. Installing WordPress 4.7 on Ubuntu, Debian and Linux Mint

Installation of Nginx Web Server

1. Nginx installation for Ubuntu, Debian or Linux Mint is as straight as any other packages and can be installed with just a simple command.

$ sudo apt-get install nginx

2. To verify status, stop it or start Nginx use the following commands.

$ sudo service nginx status

OR

$ sudo /etc/init.d/nginx start|stop|restart|status
Install Nginx Server in Linux

Install Nginx Server

3. For nginx to be able to run WordPress or other related PHP interpreted files you need to install PHP5 FPM package.

$ sudo apt-get install php5-fpm
Install PHP FPM in Linux

Install PHP FPM

4. In order to communicate with fastcgi backend, PHP FPM service must be active on server. Start it with the following command.

$ sudo service php5-fpm start
Start PHP FPM Service

Start PHP FPM Service

5. Now is time to install and configure PhpMyadmin to collaborate with Nginx. Install phpmyadmin package by selecting any web server you like it and choose No on Configure database for phpmyadmin with dbconfig-common.

$ sudo apt-get install phpmyadmin
Configure Web Server for PhpMyAdmin

Configure Web Server for PhpMyAdmin

Configure Database for PhpMyAdmin

Configure Database for PhpMyAdmin

6. To make PhpMyAdmin file scripts available for Nginx create a symlink for /usr/share/phpmyadmin path to Nginx default root.

$ ln -s /usr/share/phpmyadmin  /usr/share/nginx/www
Create a Symlink for PhpMyAdmin

Create a Symlink for PhpMyAdmin

7. We are not done yet, we also need to enable fastcgi gateway for Nginx to pass php files. To accomplish this issue, edit default sites-available file by locating and uncomment the following lines.

$ sudo nano /etc/nginx/sites-available/default
## Uncomment this lines ##
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Enable Fastcgi Gateway for Nginx

Enable Fastcgi Gateway for Nginx

Also append index.php on root path (you can find it at the beginning of file).

Add index.php on root Path

Add index.php on root Path

8. After you’re done with configuring, restart Nginx service, open a browser and pointed to your server’s IP or Virtual domain name.

Access PhpMyAdmin Dashboard

Access PhpMyAdmin Dashboard

As you can see PhpMyAdmin is accessible and you can now connect to MySQL database server and manage your wordpress database on web interface.

One note here is that after you create your first Virtual Host, PhpMyAdmin will only be available from localhost, which is a good security issue, but if you want remote control for phpmyadmin you should change server_name directive from localhost to your IP address or another subdomain especially configured for this, or create another symlink for /usr/share/phpmyadmin/ to whatever Virtual Host root you will later setup.

9. Now is time to create a basic Virtual Host for WordPress website on Nginx server. Run the following command to create wordpress server configuration file.

sudo nano /etc/nginx/sites-available/wordpress

Then add the following content.

server {
                listen 80;
                root /srv/www/html;
                index index.php index.html index.htm;
                # Make site accessible from http://wordpress.lan/
                server_name wordpress.lan;
                access_log /var/log/nginx/wordpress.lan-access.log;
    error_log /var/log/nginx/wordpress.lan-error.log;  
                location / {
                                try_files $uri $uri/ =404;
                }
error_page 404 /404.html;
                location ~ \.php$ {
                                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                                # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini        
                                # With php5-cgi alone:
                                #fastcgi_pass 127.0.0.1:9000;
                                # With php5-fpm:
                                fastcgi_pass unix:/var/run/php5-fpm.sock;
                                fastcgi_index index.php;
                                include fastcgi_params;
                }
location ~ /\.ht {
deny all;
               }
}
Create Nginx Virtual Host

Create Nginx Virtual Host

10. By default Nginx loads webserver’s file configurations from sites-available directory path. The only thing you need to do for enabling wordpress config file is to create a symbolic link to sites-enabled path and restart Nginx daemon to apply changes.

$ ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
Enable Virtual Host Configuration

Enable Virtual Host Configuration

11. Now is time to create WordPress Virtual Host root path, download WordPress archive, extract it then issue a recursive copy to /srv/www/html.

$ sudo mkdir -p /srv/www/html
$ wget http://wordpress.org/latest.tar.gz
$ tar xfvz latest.tar.gz
$ sudo cp -r wordpress/* /srv/www/html
Create Virtual Host Directory

Create Virtual Host Directory

Download WordPress

Download WordPress

Copy WordPress Files

Copy WordPress Files

12. For a smooth WordPress installation without any wp-config.php creation file errors, grant Nginx www-data system user with write permission over /srv/www/html path and revert changes after installing WordPress.

$ sudo chown -R www-data /srv/www/html/
$ sudo chmod -R 755 /srv/www/html
Grant Permissions

Grant Permissions

13. To further install WordPress 4.7 follow the detailed steps on Installing WordPress with Apache on Ubuntu and Debian systems.

14. After installation completes undo permissions by issuing the following command.

$ sudo chown -R root /srv/www/html/

15. To automatically start Nginx and Php-FPM daemon after reboot run this commands.

$ sudo upadte-rc.d php-fpm enable
$ sudo upadte-rc.d nginx enable

Alternatively, you can install and use Sysv-rc-conf utility package.

$ sudo apt-get install sysv-rc-conf
$ sudo sysv-rc-conf

Congratulations! You have now installed the one of the most popular Blogging platforms this days on a very fast and reliable HTTP server – NGINX.

Although some claim that running Nginx in combination with MySQL databases, this involving WordPress to, has the same performance as Apache due to fact that MySQL is the bottleneck, some tests revealed that Nginx is much faster in terms of speed, transfer rate, requests per second and wait-time.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Matei Cezar

I'am a computer addicted guy, a fan of open source and linux based system software, have about 4 years experience with Linux distributions desktop, servers and bash scripting.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

5 Responses

  1. Albert Yang says:

    Hey great guide but im stuck at step 8 I did everything but when I point to my IP in my case its 192.168.3.130 it shows the welcome screen of “Welcome to nginx!” when i try 192.168.3.130/phpmyadmin/ it shows the 404 Not Found i then went to winscp to see if theres a symlink and i did see /usr/share/nginx/www which is the symlink to /usr/share/nginx not sure what im doing wrong

    Thank you

    • Matei Cezar says:

      If the root location of your vhost points to /srv/www/html, then make a symlik to phpmyadmin with the following command: ln -s /usr/share/phpmyadmin /srv/www/html/

  2. shgn says:

    Thanks for this post. That’s so simple and useful.

  3. Chirag says:

    You can automate this using EasyEngine
    EasyEngine setup and tune nginx php5-fpm mysql and postfix also provide 12 different caching options for WordPress

    EasyEngine: https://github.com/rtCamp/easyengine/

  4. Pepe says:

    Thanks!!

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.