Nginx is an open source web server. Users have been moving to Nginx because of the high performance and stability and as of February 2014, Nginx is hosting around 15% of all web servers according to Netcraft’s Web Server Survey. Nginx is a great option for hosting WordPress sites.

It’s assumed that you have already installed Nginx with PHP-FPM. If you haven’t already done that, you can use this tutorial: How to install Nginx with PHP and MySql support on wheezy

1. Create the database for WordPress

mysql -u root -p
CREATE DATABASE {database};
CREATE USER {username}@localhost;
GRANT ALL PRIVILEGES ON {username}.* TO {database}@localhost IDENTIFIED BY '{password}';
FLUSH PRIVILEGES;
exit

Replace {database}, {username} and {password} with the database name and credentials you want to use. You will use this in the WordPress installer.

2. Download the latest version of WordPress

cd /usr/share/nginx/www
wget http://wordpress.org/latest.tar.gz

In this tutorial, I’m using /usr/share/nginx/www/wordpress but you probably want to change that into something else.

3. Extract WordPress

cd wordpress
tar zxvf latest.tar.gz

4. Make wp-content writable and the root directory temporarily writable to allow WordPress to create the config file

chmod o+w ./
chmod 777 wp-content -R

5. Change the directory owner and group to www-data

chown www-data.www-data ./ -R

6. Create a Nginx virtual host (pico /etc/nginx/sites-available/wordpress)

The contents should be similar to the text below, you may need to adjust the root and host name

server {
        listen 80;
 
        root /usr/share/nginx/www/wordpress;
        index index.php;
 
        server_name {domain};
 
        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }
 
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

Change {domain} to the domain or host that you want to use for the new WordPress site

7. Enable the new virtual host

ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress

8. Restart Nginx

/etc/init.d/nginx restart

9. Run the WordPress installer by opening this location in a web browser. You will have to provide the database credentials and some more information for the setup.

http://{domain}

Change {domain} to the server name used in the Nginx virtual host file

10. When the installer has completed, change the permissions of the root directory

chmod o-w ./