Niels Hoffmann

Installing Wordpress on NGINX via php-fpm

This is a short tutorial on how to install php-fpm on debian squeeze and how to configure nginx so it will serve a wordpress installation.

Install php-fpm by adding a new apt source:

sudo echo "deb http://packages.dotdeb.org stable all" >> /etc/apt/sources.list
apt-get update

Apt will probably complain about a missing key for the just added repository. This can be fixed by adding the key to apts keyring. Please make sure that you get the right key and compare the fingerprints.

gpg --export <PUBLIC_KEY> | apt-key add -

Now install php-fpm

apt-get update
apt-get install php5-fpm php5-suhosin php5-mysql

By default php-fpm listens on http://127.0.0.1:9000. Since we are on a unix system, we like to make use of sockets. Open fpm pool configuration and search for the listen directive. Then adapt it to your needs.

# /etc/php5/fpm/pool.d/www.conf
listen = /tmp/php-fpm.sock

Add an upstream server for php to nginx.conf so it is available for all configurations:

# /etc/nginx/nginx.conf
# Upstream to abstract backend connection(s) for PHP.
upstream php {
    server unix:/tmp/php-fpm.sock
    # or whatever you configured php-fpm to listen to
}

Add these global configurations for nginx to /etc/nginx/global

Download wordpress and unpack

cd /var/www/mydomain
wget http://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz

All that is needed now is the nginx configuration

server {
        listen       80;
        server_name  mydomain.com;

        access_log /var/log/nginx/mydomain.access_log;
        error_log /var/log/nginx/mydomain.error_log;

        index              index.php index.html index.htm;

        root         /var/www/mydomain/wordpress;

        include global/restrictions.conf;
        include global/wordpress-ms-subdir.conf;
}

I am Niels Hoffmann, software developer, music afficionade, sailor.
Take a look at my CV and check out my projects.
You can follow me on Twitter at @zentralmaschine, get in touch via email to niels@zentralmaschine.net and find me on Github or LinkedIn.