Techminded

Apacheless web-server on Debian Squeeze with nginx and php-fpm

Threre are tons of information on now to setup "parts" that making fully functional web server plaftorm, but usually without giving summary view. We're going to explain all steps on you how to get your LAMP web server up. Things you should have:

Virtual or real personal (dedicated) server hosting. You'd better have 5Gb of disk space and 256 RAM. Not really enough for Apache but ok for Nginx

Root (Administrator) access to server via Secure Shell (SSH)

Domain name and control access to it (usually provided by domain name registration services)

We are going to setup web server to be able run Drupal7 (or any other PHP CMS/Website)

1. System Preparation

We will need to install php5-fpm package. For debian you may find it in dotdeb.org repository. Add it to your /etc/apt/sources.list by following command:

We should also set stack size usually it's set to 10 Megabytes and stack is not used, lets reduce stack to 1 Megabyte in file /etc/security/limits.conf:

* soft stack 1024

This means that our stack is more "soft" now.

Now lets tune MySQL. Install performance checker first:

$sudo apt-get install mysqltuner

run it and see the results. You can also disable InnoDB that is slower on queries, but gives you transactions and some other quite helpful stuff, google and decide what engine you want to use. To use MyISAM engine write skip-innodb option to [mysqld] section of file /etc/mysql/my.cnf

You can also install cache and accellerator for PHP:

$sudo apt-get install php-apc

It has lots of options but even byt default it can speed up PHP up to 1.5-2 times

Lets get back to php-fpm and add some more options to file /etc/php5/fpm/pool.d/www.conf

# dynamic process creation, the number of processes will depent on load level
pm = dynamic
# maximum number of process, 7 is for weak servers
pm.max_children = 7
# creating new process takes tim and we will run some on server start
pm.start_servers = 3
# Minimum number of processes allowed for hold. Should be less than max
#pm.start_servers =pm.min_spare_servers is ok for us
pm.min_spare_servers = 3
# Maximum number of process allowed on hold
pm.max_children
# should not be less than pm.min_spare_servers
pm.max_spare_servers = 4

You should rely on trying and testing with this option. For example the following configuration:

has eated up to 12 Gb of RAM and 2-3 Gb of swap. Keep your options actuall to your load level.

It's also helpful to install and setup log rotation (e.g. with package logrotate) as logs are grown very fast.

Summary

I've performed some testing and have the following thoughts:

Apache eats less memory initially but usage growth fater, Nginx can eat more that Apache without load but will no increase usage so drammatically

Don't know why but Nginx swaped more actively

If load is extremely high Apache freezes but Nginx just starts to work slower

Nginx is fater with freeing recources

To make your own tests and assumtions you cat use http://loadimpact.com service that allows you to emulate up to concurent 50 users for free. There is also siege measurement utility it's quite simple to use.