I new with Debian. I want to use php on Debian. I do:

apt-get install php5-cli php5-cgi spawn-fcgi

Create file /usr/bin/php-fastcgi:

#! /bin/sh
exec /usr/bin/php5-cgi

Create file /etc/init.d/init-fastcgi:

PHP_SCRIPT="/usr/bin/spawn-fcgi -a -p 9000 -u www-data -g www-data -f     /usr/bin/php-fastcgi"
case "$1" in
killall -9 php5-cgi
killall -9 php5-cgi
echo "Usage: sudo /etc/init.d/init-fastcgi {start|stop|restart}"
exit 1
exit $RETVAL

Ater do:

chmod 755 /usr/bin/php-fastcgi
chmod 755 /etc/init.d/init-fastcgi 

Into /etc/nginx/sites-enabled/default add:

location ~\.php$ {
 root /srv/www/ekb.mydomain.com/public_html;
 include /etc/nginx/fastcgi_params;
 fastcgi_index index.php;
 fastcgi_param QUERY_STRING $query_string;
 fastcgi_param SCRIPT_FILENAME /srv/www/ekb.mydomain.com/public_html$fastcgi_script_name;

Create directories:


Create file /srv/www/ekb.mydomain.com/public_html/test.php


Start serice:

/etc/init.d/init-fastcgi start
/etc/init.d/nginx start

In browser:


but get 404 error.

What i can do wrong?

  • 1
    Go with PHP-FPM instead of fastcgi and use unix-socket instead of localhost. – r004 Mar 24 '14 at 15:06
  • +1. THere is no reason to do this instead of simply installing php5-fpm package. – phoops Mar 24 '14 at 19:56
  • nginx killing me.I war remove nginx,php5,php5-cgi and install it again, after do all configs from my question and php start to work. Magik. – Kliver Max Mar 26 '14 at 7:25

You should really configure nginx with php-fpm. It's easier to install, configure and manage and is as fast.

$ apt-get install nginx php5-fpm
$ nano /etc/nginx/nginx.conf

worker_processes  4;
keepalive_timeout   2;

$ nano /etc/nginx/sites-available/default

server {
    listen   80; ## listen for ipv4; this line is default and implied
    listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules

    location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            allow ::1;
            deny all;

    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #       proxy_pass;

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/www;

    # pass the PHP scripts to FastCGI server listening on
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

            # With php5-cgi alone:
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    location ~ /\.ht {
            deny all;

Start nginx and php-fpm:

$ service nginx start
$ service php5-fpm start
  • I try install php5-fpm but apt-get says that can't find this package. – Kliver Max Mar 26 '14 at 4:40

Try editing /etc/hosts and add to the localhost line as below:    localhost ekb.maydomain.com

In other words, add ekb.maydomain.com to whichever line begins -- it may not look exactly like this one.

The problem is that "www.ekb.maydomain.com" is a real www address and the DNS resolver can't find it. By adding that line to /etc/hosts, you skip DNS resolution for that domain and instead use it as an alias for localhost, which is where your browser can actually find a web server running on the same machine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.