Introduction
Since i made the plan to change from a rather expensive dedicated server to a much cheaper VPS solution, i started thinking about moving away from the sluggish apache2 stack. Fed by the fact that the PHP developers surprised me by suddenly announcing that the support for the php 5.2.x is going into security fixes when needed mode, i decided i might as well go all the way then. Moving to PHP 5.3.3 running a much leaner and faster NGINX HTTP server under Ubuntu 10.4 LTS using the new PHP-FPM instead of fastcgiOn that server I am most likely going to run a few sites in Drupal 7, i sat down to configure a small development environment under virtual box.Downloaded the 64Bit ISO of ubuntu server, installed a basic server without any preconfigured extensions except sshd and mysql-server.After installing, updating and such, had plenty of time reading myself into configuring nginx, compiling php and creating an image cache friendly version of the default nginx setup.
(please do note i once again assume the shell user is either root via the sudo bash method, or you need to type sudo in front of most commands)
Step 1, the easy one
apt-get install nginx
Step 2, compile php 5.3.3 from source
cd /usr/local/source/ wget http://nl3.php.net/get/php-5.3.3.tar.gz/from/nl2.php.net/mirror tar -xzf php-5.3.3.tar.gz
Get the rest of the needed libraries and compiler trough apt-get
apt-get install autoconf2.13 libssl-dev libcurl4-gnutls-dev libjpeg62-dev libpng12-dev libmysql++-dev libfreetype6-dev libt1-dev libc-client-dev mysql-client libevent-dev libxml2-dev libtool libmcrypt-dev cd php-5.3.3 ./configure --enable-fpm --with-mcrypt --enable-mbstring --with-openssl --with-mysql --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --with-pdo-mysql --with-libxml-dir=/usr/lib --with-mysqli=/usr/bin/mysql_config --with-curl --enable-zip --enable-sockets --with-zlib --enable-exif --enable-ftp --with-iconv --with-gettext --enable-gd-native-ttf --with-t1lib=/usr --with-freetype-dir=/usr --prefix=/usr/local/php --with-fpm-user=www-data –with-fpm-group=www-data
As you can see, rather basic version. No SQLite, just GD, MYSQL and some multibyte, crypt stuff etc.
Do note that the “–with-fpm-user=www-data –with-fpm-group=www-data” is different with the latest build of php 5.3.3, previous versions you needed the php-fpm patch, but from this version on it is included as a beta option
No errors occurred, fired up my nespresso machine, and started the compiling of PHP
make make install
And while you are at it, you could do the make test as well, so the php people receive yet an other compiling log ;))
After compiling and few nespresso’s (fortissio lungo if you really want to know :)) it was time to copy some files into their appropriate place.
Since it is a dev box, I preferred the development php.ini, you could substitute php.ini.development with php.ini.production if you wanted to
cp php.ini-development /usr/local/lib/php/php.ini chmod 644 /usr/local/php/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod 755 /etc/init.d/php-fpm update-rc.d -f php-fpm defaults touch /var/run/php-fpm.pid
Step 3, configure nginx and php-fpm
Starting with php-fpm, I like my PID files in one place, so i altered the /etc/init.d/php-fpm a little by changing
php_fpm_PID =${prefix}/var/run/php-fpm.pid into php_fpm_PID=/var/run/php-fpm.pid
Then a few lines in the /usr/local/etc/php-fpm.conf, which is a rather large file so i just sum up the changes i made assuming you know how to search/replace etc by yourself since you are reading this not so noobisch point and click blogpost anyway.
error_log = /var/log/php-fpm.log pm = dynamic pm.max_children = 50 pm.start_servers = 10 pm.min_spare_servers = 5 pm.max_spare_servers = 35
Next up was configuring nginx, and must warn you upfront. I have NO idea if this is the correct way of doing it. It seemed the most logically way after reading the manual and some posts in the ground-squirrel/nginx.
This is the config chunk i ended up with, and i know that some parts can be moved into a own designated include file, but that is for next time :)
My site is in the /var/www/drupal7 and the log files go into /var/log/
server {
listen 80 default;
root /var/www/drupal7/;
index index.php;
access_log /var/log/drupal7_access.log;
error_log /var/log/drupal7_error.log;
# if the file is not physical there, loop trough drupal
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
# if the file is not imagecached, create one
location ~ /files/imagecache/ {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
# just send a empty response if the favicon.ico is m.i.a
location = /favicon.ico {
try_files /favicon.ico =204;
}
# hide protected files
location ~*.(.htaccess|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(.php)?|xtmpl)$ {
deny all;
}
# enable robots.txt
location = /robots.txt {}
# hide backup_migrate files
location ~* ^/files/backup_migrate {
deny all;
}
# Allow all files in this location to be downloaded
location ~ ^.*/files/.*$ {}
# setup the php-fpm pass-trough
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
Final step, tested the config files and uploaded drupal7-dev in place
service nginx configtest
If no errors occurred, start up php-fpm and nginx
service php-fpm start service nginx start
Upload drupal into the correct, folder do what you normally would do, like copy the settings.php, create a mysql database and in this case remove the .htaccess since it is not needed by nginx.
Point your browser to the correct server, and if all went well you should see a rather familiar picture :)

Utkarsh
01/08/2010 at 19:43
Hey,
Just a small note here – if you are changing the php-fpm.pid path in /etc/init.d/php-fpm, it should also be changed in the php-fpm.conf file at the top.
PHP 5.3.3 Adds PHP-FPM
18/08/2010 at 12:15
[...] managed to find one decent guide to compiling and setting it up so far. It looks fairly simple. I might have to give it a try sometime, as my current setup (which [...]