2

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?

2
  • 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. Sep 12, 2010 at 11:00
  • Wondering if any reply here has helped you? Jan 5, 2013 at 15:23

2 Answers 2

1

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.

0

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.

1
  • 3
    Sorry but this hasn't been true for a while now. PHP-FPM is suggested instead of spawn-fcgi. Sep 12, 2010 at 10:58

You must log in to answer this question.