I decided to switch from apache2 to nginx. apache2 is a very good webserver and never failed on me, but i wanted to give nginx a try. Another reason for me was apache2s overall memory consumption.
I used two Tutorials for the setup, so all you read here is based on this two howtos:
The first tutorial recommends to install lighttpd to install spawn-fcgi and then disable lighttpd. So i decided to use php5-fpm instead.
Don’t forget to replace www.wokurka.net with your fqdn!
1. Add the dotdeb.org repository to your /etc/apt/sources.list
echo "deb http://packages.dotdeb.org stable all" >> /etc/apt/sources.list
2. Add the Repos Key to your keyring
wget http://www.dotdeb.org/dotdeb.gpg cat dotdeb.gpg | apt-key add - && rm dotdeb.gpg
3. Update & Upgrade
apt-get update && apt-get upgrade
4. Install the needed packages
apt-get install nginx mysql-server php5-cgi php5-mysql php5-curl \ php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt \ php5-memcache php5-ming php5-pspell php5-recode php5-snmp \ php5-sqlite php5-tidy php5-xmlrpc php5-xsl php-apc php5-fpm
You should now have mysql, nginx and php5-fpm servers running. Now let’s configure and glue them together.
5. Add the following to /etc/php5/fpm/php-fpm.conf
pm.max_children = 50 pm.start_servers = 8 pm.min_spare_servers = 4 pm.max_spare_servers = 20 pm.max_requests = 1000 request_terminate_timeout = 30s
6. Add the following to /etc/nginx/nginx.conf (after http {)
client_max_body_size 20M; client_body_buffer_size 128k;
7. Remove the default site config
rm /etc/nginx/sites-enabled/default
8. Create a docroot (in this case www.wokurka.net)
mkdir -p /var/www/www.wokurka.net
9. Create a config for your Site (/etc/nginx/sites-available/www.wokurka.net)
server {
listen 80;
server_name wokurka.net www.wokurka.net;
access_log /var/log/nginx/www.wokurka.net.access_log;
error_log /var/log/nginx/www.wokurka.net.error_log;
root /var/www/www.wokurka.net;
index index.php index.htm index.html;
location ~ .php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/www.wokurka.net$fastcgi_script_name;
include fastcgi_params;
}
}
10. Link the config to /etc/nginx/sites-enabled
ln -s /etc/nginx/sites-available/www.wokurka.net /etc/nginx/sites-enabled/www.wokurka.net
11. Create an index.php in your documentroot containing some php code
vi /var/www/www.wokurka.net/index.php
<?php phpinfo(); ?>
12. Restart the Services
/etc/init.d/php5-fpm restart && /etc/init.d/nginx restart
13. You’re done. Open your Browser and see if everything works.