Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I installed a LEMP stack on Linode using one of the stack scripts they offer. I actually didn't run it on boot but instead entered the commands manually since it seemed to not install everything correctly.

Anyway, after installing everything and starting both the server and php-fpm without error, I created a phpinfo(); page on the default nginx location (/var/www/index.php). Problem is that it's not executing the script and instead displays as a static file. Anyone know how I could approach this?

share|improve this question
2  
It's impossible to tell since you have provided basically no info at all. You need to edit the configuration files for both php-fpm and nginx. Read the answer by polemon and ignore the whole spawn-fcgi aspect of it, if that doesn't help then give a link to your configuration file. –  Martin Fjordvald Sep 12 '10 at 11:00
    
Wondering if any reply here has helped you? –  Valentin Jan 5 '13 at 15:23

2 Answers 2

Let me post you some relevant excerpts of my "nginx-php-fpm-php-apc-postgres"-tutorial, hopefully that will help you.

At first install the required packages:

apt-get install nginx php5-fpm php5-pgsql php5-gd php5-curl php-apc postgresql imagemagick

I assume that you have the relevant packages, such as php5-fpm, installed.

Now configure the "vhost":

vim /etc/nginx/sites-available/www.domain.tld

The following will show you my example configuration:

server {
listen 80;
server_name domain.tld www.domain.tld;

access_log /var/log/nginx/domain.access_log;
error_log /var/log/nginx/domain.error_log;

root /var/www/www.domain.tld;
index index.php index.htm index.html;

location ~ .php$ {
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME /var/www/www.domain.tld$fastcgi_script_name;
include fastcgi_params;
try_files $uri =404;
}
}

Make sure that the right processes are running afterwards:

/etc/init.d/php5-fpm restart
/etc/init.d/nginx start

See the full tutorial here: http://www.xenuser.org/2011/08/28/running-phpbb3-on-a-high-performance-monster-or-how-nginx-php-fpm-php-apc-postgres-will-serve-you-well/

I guess your configuration file for the vhost is missing some of the parts I posted above or php5-fpm is not running.

share|improve this answer

Erm, using PHP in nginx is fairly simple, you just need to use FastCGI for PHP.

  1. I'm starting a FastCGI runtime for PHP with spawn-fcgi:

    spawn-fcgi -C 3 -u www-data -s /var/run/php-fcgi.sock -P /var/run/php-fcgi.pid -- /usr/bin/php5-cgi
    

    Make sure all permissions are correct.

  2. Then, this goes to my nginx configuration:

    upstream php-fcgi {
      server unix:/var/run/php-fcgi.sock;
    }
    

    This is part of the http context.

    Inside a server context, that defines your vhost, so to say, goes this:

    location ~ \.php$ {
      fastcgi_pass php-fcgi;
      include /etc/nginx/fastcgi.conf;
    }
    

    Notice the /etc/nginx/fastcgi.conf file. The file should be present in every nginx package I've seen so far, if not, google it. You'll find it everywhere.

Using spawn-fcgi, which is part of lighttpd seem unorthodox, but it's the recommended solution by nginx people.

share|improve this answer
3  
Sorry but this hasn't been true for a while now. PHP-FPM is suggested instead of spawn-fcgi. –  Martin Fjordvald Sep 12 '10 at 10:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.