ITPub博客

首页 > IT职业 > IT生活 > ubuntu14.04安装nginx+php5-fpm

ubuntu14.04安装nginx+php5-fpm

IT生活 作者:freewill 时间:2021-09-09 09:19:13 0 删除 编辑

安装php5-fpm

# apt-get install php5-fpm

安装完成以后修改/etc/php5/fpm/conf.d/:

;listen = /var/run/php5-fpm.sock

listen = 127.0.0.1:9000

重载php5-fpm配置

# /etc/init.d/php5-fpm reload

检查一下是否监听了9000端口:

# netstat -tln 

如果出现了9000端口,说明php5-fpm正常启动。


安装nginx(参考Ubuntu 14.04安装Nginx1.60)

安装完成之后配置/etc/nginx/conf.d/default.conf:

要执行php关键要修改如下部分:

#location ~ .php$ {

#        root           html;

#        fastcgi_pass   127.0.0.1:9000;

#        fastcgi_index  index.php;

#        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#        include        fastcgi_params;

#    }

去掉前面的#号,修改root为你自己目录,修改/scripts$fastcgi_script_name为$document_root$fastcgi_script_name。修改之后如下:

location ~ .php$ {

        root           /var/www;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

   }

注意:

root如果不指定会出现找不到文件的错误。

/scripts如果不修改会出现如下错误

[error] 5152#0: *7 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

也可以不指定root直接把$document_root写成真实地址。

如果不修改/etc/php5/fpm/conf.d/的话,也可以设置fastcgi_pass  后的127.0.0.1:9000;为unix:/var/run/php5-fpm.sock;

然后重载nginx配置:

# /etc/init.d/nginx reload

在/var/www目录中新建一个index.php文件,在浏览器地址栏输入localhost,回车!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1594/viewspace-2802145/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    113
  • 访问量
    1012