Solved: Debian Squeeze + Nginx + PHP5-FPM

After tiresomely testing the config – I eventually got it to work.

Once you know how it’s really easy but I kept getting a “502 Bad Gateway” error that confused me.

Benefits of sockets over TCP:

  • Faster connection over sockets than TCP; 20% boost
  • More secure as sockets are harder to break their permissions

Anyway, here’s what you need to do. All config locations are the defaults installed by Debian Squeeze.

Add Dotdeb’s sources in your Debian /etc/apt/source.list

## PHP5-FPM
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all

Then install php5-fpm:

apt-get update
apt-get install php5-fpm

Change the settings in /etc/php5/fpm/php-fpm.conf

pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
daemonize = yes
include=/etc/php5/fpm/pool.d/*.conf

Recommended settings in /etc/php5/fpm/pool.d/www.conf

;listen = 127.0.0.1:9000
listen = /var/run/php5-fpm.sock

listen.owner = www-data
listen.group = www-data
listen.mode = 0666

user = www-data
group = www-data

php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
php_admin_value[error_reporting] = 0
php_admin_value[memory_limit] = 128M
php_admin_value[date.timezone] = Europe/London

Start/Restart Nginx and PHP5-FPM and voila

/etc/init.d/nginx restart
/etc/init.d/php5-fpm start

Everything should be running smoothly. Enjoy your new faster server!

Thanks to the people below who wrote about it first.

Installing the latest Nginx on Debian Squeeze

I just updated my Nginx on Debian 6 (Squeeze) from 0.7.x.x to 1.0.6 by altering my source list.

Edit your /etc/apt/sources.list to include the following lines:

deb http://nginx.org/packages/debian/ squeeze nginx
deb-src http://nginx.org/packages/debian/ squeeze nginx

Then run `apt-get update` and `apt-get upgrade`.

Follow the on-screen instructions and BOOM! You’re running the latest version of Nginx! My preference is to use Nginx these days instead of Apache2 purely because of the extra performance you gain out of it. Much higher requests per second (rpp).

I highly recommend trying it if you haven’t already.

HowTo Forge: Getting the most out of your Webserver

I’ve always enjoyed tweaking my Web Servers, trying to get the most out of them, but sometimes it can be very tedious and frustrating… long, late hours of troubleshooting problems. Enter HowTo Forge!

HowTo Forge is website that provides pre-compiled virtual images of (pretty much) every UNIX platform already configured for you.

Continue reading