Nginx + PHP-FPM,php脚本不能运行

我使用其提供的堆栈脚本之一在Linode上安装了LEMP堆栈。 我其实并没有在启动时运行它,而是手动input命令,因为它似乎没有正确地安装一切。

无论如何,安装完所有的东西,并启动服务器和php-fpm没有错误,我创build了一个phpinfo(); 页面在默认的nginx位置( /var/www/index.php )。 问题是它没有执行脚本,而是显示为一个静态文件。 任何人都知道我可以如何处理这个?

让我发布一些相关的“nginx-php-fpm-php-apc-postgres”教程的相关摘录,希望对你有帮助。

首先安装所需的软件包:

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

我假设你已经安装了相关的软件包,比如php5-fpm。

现在configuration“虚拟主机”:

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

以下将向您展示我的示例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; } } 

确保之后正确的进程正在运行:

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

看到完整的教程在这里: http : //www.xenuser.org/2011/08/28/running-phpbb3-on-a-high-performance-monster-or-how-nginx-php-fpm-php-apc- Postgres的,将发球,你阱/

我想你的configuration文件的虚拟主机缺less一些我张贴上面的部分或php5-fpm没有运行。

Erm,在nginx中使用PHP相当简单,你只需要使用FastCGI for PHP。

  1. 我使用spawn-fcgi为PHP启动FastCGI运行时:

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

    确保所有权限都是正确的。

  2. 然后,这转到我的nginxconfiguration:

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

    这是http上下文的一部分。

    server上下文中,定义你的虚拟主机,可以这样说:

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

    注意/etc/nginx/fastcgi.conf文件。 这个文件应该出现在我目前看到的每个nginx包中,如果没有的话,google它。 你会发现无处不在。

使用spawn-fcgi(这是lighttpd的一部分)看起来是非正统的,但这是nginx人推荐的解决scheme。