Post navigation

By searching the web how to install nginx with PHP5 on Debian, one can find different tutorials, but many require a lot of manual work.

At first some background information: nginx (wikipedia) is a very fast webserver with efficient use of system resources. Because of debian's security policy you can't install the current up to date version of out of the box, therefore you have to compile it on your own. Or one can use the dotdeb service, which offers a slightly older version of nginx. Furthermore you can use some strange setup scripts if you trust them.

But if you do not need the most up to date version of nginx and don't want to break your systems securety with different thirdparty stuff you can follow this short guide.

Install required packages

apt-get install php5-cgi php5-suhosin spawn-fcgi nginx

Start nginx afterwards:

/etc/init.d/nginx start

Type in your web server's IP address and you should see some error-webpage. On my system the /var/www directory was missing, so i have to create it:

mkdir -p /var/www
chown www-data:www-data /var/www

For testing you can create a index.html file inside /var/www with some "Hello World" or something like that so.

Setting up php parsing

Edit the file /etc/rc.local and put the following line above the "exit 0":

Make sure that there are some spaces between include and fastcgi_params in the default file this is written as one word which is a bug.

For testing you can create a /var/www/info.php with

<?php
phpinfo();
?>

and after a restart of your webserver you should see the php-infopage

/etc/init.d/nginx restart

As you see, PHP5 is working, and it's working through FastCGI, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5, also for security reasons we installed already Suhosin module.