The cloud has led to many improvements in LAMP architecture. No client wants to throw tin at performance problems anymore. seems there is always a way to work smarter. So my acronyms may be screwed (who want's to install a LNMPC?) - but if Carlsberg made software stacks for CMS, they'd probably use this...
Nginx is a relatively new (2004), ultra fast, lightweight websever. Well, it started as a mail server, then became a reverse proxy and now runs over 4% of the worlds sites. Where apache uses serious amounts of ram and a threaded model, Nginx (pronounced 'EngineX') uses an asynchronous event driven model which gives predictable performance under load, rather than the apache bloat...A lean mean ruskie serving machine, as opposed to Apaches fat 'merkhin bloat.First off grab the latest stable copy of nginx from here and compile it
$ tar zxvf nginx-0.8.54.tar.gz
$ cd nginx-0.8.54 sudo ./configure --sbin-path=/usr/local/sbin --with-http_ssl_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module
$ sudo make
$ sudo make install Grab the latest copy of php 5.2 from php.net adn the php-fpm patches from http://php-fpm.org/ (for 5.3 its essentially the same, but no patching required)
$ gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1 download some libraries you'll need (obviously depends on what you want to compile in
$ sudo apt-get install libxml2-dev libbz2-dev libcurl4-openssl-dev libmcrypt-dev libmhash2 libmhash-dev If you're using mariadb instead of mysql (no reason you shouldn't, see this post then you also need to install the mariadb client libraries. If you don't you may get error messages like this
checking whether to enable embedded MySQLi support...
no mysql_config not found
configure: error: Please reinstall the mysql distribution Which is no help to man nor beast. especially if you spend 30 mins trying to work out how to get mysql libraries installed without breaking mariadb ...ahem.
$ sudo apt-get install libmariadbclient16-dev So change to your php source directory and run a config command not unlike the one below:
./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-zip --with-pcre-regex --with-mysqli
$ sudo make all
$ sudo make test
$ sudo make installThe make test is optional. One thing i learnt on this mission was how to use the strip command. This removes all detritus from the binaries, so for php running
$ ls -lh /usr/local/bin/php-cgi
-rwxr-xr-x 1 root root 15M 2011-01-30 13:04 /usr/local/bin/php-cgi
$ sudo strip /usr/local/bin/php-cgi
$ ls -lh /usr/local/bin/php-cgi
-rwxr-xr-x 1 root root 5.3M 2011-01-30 17:27 /usr/local/bin/php-cgiThis should yield a smaller footprint in ram, huzzah! Its not as stark as the difference on disk, but meh. Smaller is better. Or so I maintain for my girlfriends sake...
using sockets with php-fpm
You can get a 10-15% improvement in performance by using sockets (if you're on the same host) instead of using tcp. This is because you don't need the tcp overhead. In the php-fpm.conf file, set the following to listen to a file socket instead of a network port. Obviously you don't do this if the php-cgi process is on a different machine.
<value name="listen_address">/tmp/php-fpm.socket</value> Configure Nginx
Better men than me have configured this already - check out the Nginx site wiki http://wiki.nginx.org/Drupal Ensure you have the correct parameters etc, and then start php-fpm
$ sudo /usr/local/bin/php-cgi --fpm and start nginx and away you go! Russian bear taking names and kicking asses! Budem!

1 Comment
Thank you for the Socket
Submitted by Ekrem Yilmaz on
Thank you for the Socket hint.
It really makes a small difference in performance.
Add new comment