ubuntu搭建LEMP环境,解决 fpm监听失败

1.安装mysql

  1. sudo apt-get install mysql-server mysql-client

安装过程中要输入root用户的密码。

2.安装nginx

  1. sudo apt-get install nginx

2.安装php

   1.  sudo apt-get install php5-fpm php5-cgi php5-mysql php5-fpm php5-curl php5-gd  php-pear php5-imagick php5-imap  php5-memcache   php5-sqlite php5-tidy php5-mongo

这是常用的扩展

一路安装下来后配置nginx

cd  /etc/nginx/ #配置文件默认在此

通过nginx.conf可以看到引入了 sites-available/文件夹下文件,

vi sites-available/default

可以看到这是本地默认的localhost配置,这就是为什么你在nginx.conf里再加入一个localhost的server  nginx会有waring的原因了,因为它已经定义了。

修改default文件为:

server {
listen 80;
listen [::]:80 default_server ipv6only=on;

root /data/www/;

server_name localhost;

location / {
index index.php index.html index.htm;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /data/www/$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}

}

然后重启nginx和php-fpm

service nginx restart

service php5-fpm restart

在网站根目录编写:

info.php:

<?php

    phpinfo() ;

?>

访问,不成功,查看nginx错误日志,默认是放在/var/log/nginx下

cd /var/log/nginx

tail -fn100  error.log

发现:[error] 15980#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: “GET /info.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “127.0.0.1”

可知是php-fpm的问题

netstat -lnp|grep 9000 (查看9000端口是否被监听)

无内容

解决方法

1 . 按照/etc/php5/fpm/pool.d/www.conf的默认配置使用php5-fpm

# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;

2 . 修改/etc/php5/fpm/pool.d/www.conf里的修改为listen=9000

# # With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;

重启php-fpm

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Time limit is exhausted. Please reload CAPTCHA.