V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
1dian01
V2EX  ›  问与答

按照 digitalocean 上的教程在 ubunte 上安装 Nginx+PHP+MYSQL 到最后一步 访问 http://ip/info.php , 无法出现 phpinfo 页面,求助!

  •  
  •   1dian01 · 2014-07-20 23:18:09 +08:00 · 7160 次点击
    这是一个创建于 3573 天前的主题,其中的信息可能已经有所发展或是发生改变。
    笔记如下:
    1. 更新源
    sudo apt-get update
    sudo apt-get upgrade
    2. 安装 MySQL
    sudo apt-get install mysql-server php5-mysql

    sudo mysql_install_db
    3. MySQL安全设置
    sudo /usr/bin/mysql_secure_installation
    系统提示输入MySQL的密码,并按照如下操作
    Remove anonymous users? [Y/n] y
    Disallow root login remotely? [Y/n] y
    Remove test database and access to it? [Y/n] y
    Reload privilege tables now? [Y/n] y
    4. 安装NGINX
    sudo apt-get install nginx
    安装成功后启动NGINX sudo service nginx start
    然后在浏览器中输入IP地址检查NGINX是否启动
    5. 安装PHP
    sudo apt-get install php5-fpm
    6. 配置PHP
    修改/etc/php5/fpm/php.ini文件中的cgi.fix_pathinfo=0,把1改为0
    **同时注意去掉这句话前面的分号 ;,不然这句话就没有工作,在后面配置NGINX时文件中会有一句话# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini**
    7. 修改PHP监听方式
    打开/etc/php5/fpm/pool.d/www.conf 把listen = 127.0.0.1:9000 修改为listen = /var/run/php5-fpm.sock
    **fpm分为端口监听和unix socket监听方式,前者对应你的IP端口,后者对应文件路径,nginx配置一致才能解决问题! 包管理默认的PHP-FPM的配置在 /etc/php5/fpm/pool.d/www.conf 里面可以改监听方式,只要nginx和www.conf两者的设定相同就不会出问题 参考:[http://www.v2ex.com/t/89653] **

    然后重启php-fpm
    sudo service php5-fpm restart
    8. 配置NGINX
    打开/etc/nginx/sites-available/default修改下面的配置来开启PHP
    #location ~ \.php$ {
    ---->去掉#
    # fastcgi_split_path_info ^(.+\.php)(/.+)$;
    ---->去掉#
    # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    # # With php5-cgi alone:
    # fastcgi_pass 127.0.0.1:9000;
    # # With php5-fpm:
    # fastcgi_pass unix:/var/run/php5-fpm.sock;
    ---->去掉#,与/etc/php5/fpm/pool.d/www.conf一致即可
    # fastcgi_index index.php;
    ---->去掉#
    # include fastcgi_params;
    ---->去掉#
    #}
    ---->去掉#

    修改保存之后重启Nginx:
    sudo service nginx restart

    10. 测试PHP是否正常工作
    创建一个简单的PHP文件phpinfo.php,放入/etc/nginx/sites-available/default中root所示位置 root /usr/share/nginx/www;中

    内容为 <?php phpinfo(); ?>

    访问 http://ip/info.php , 如果出现 phpinfo 页面,则大功告成。

    最后这步无法访问info.php,马化腾127-702-26-92,求帮忙,谢谢
    第 1 条附言  ·  2014-07-21 02:20:08 +08:00
    日志
    2014/07/21 02:05:23 [crit] 12824#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 113.118.245.112, server: localhost, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "42.121.96.188"

    修改为etc/php5/fpm/pool.d/www.conf中的listen = 127.0.0.1:9000 与etc/nginx/sites-available/default中的fastcgi_pass 127.0.0.1:9000;正常工作了

    但是如果是etc/php5/fpm/pool.d/www.conf中的listen = /var/run/php5-fpm.sock与etc/nginx/sites-available/default中的fastcgi_pass unix:/var/run/php5-fpm.sock;就不能工作,求解...
    28 条回复    2014-07-21 14:49:26 +08:00
    1dian01
        1
    1dian01  
    OP
       2014-07-20 23:29:00 +08:00
    TakanashiAzusa
        2
    TakanashiAzusa  
       2014-07-20 23:30:29 +08:00   ❤️ 1
    端口?
    1dian01
        3
    1dian01  
    OP
       2014-07-20 23:35:48 +08:00
    @TakanashiAzusa
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 4774/mysqld
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7085/nginx
    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 626/sshd
    feiyuanqiu
        4
    feiyuanqiu  
       2014-07-20 23:53:04 +08:00 via Android
    一直是在win下弄php,对linux不熟,但是你这个情况,
    1、host有没有把ip指向127?
    2、好像你的nginx也没有配置重写,那为什么访问phpinfo.php地址会是info.php?试试把改成phpinfo.php?
    确实不懂linux这些东西,不对的地方请大大们指正
    Roboo
        5
    Roboo  
       2014-07-20 23:53:05 +08:00 via Android
    把各项服务都先重启一下 再试一次 还不行 然后看看日志文件
    我记得Nginx默认网站路径是什么/HTML 不是www 可能是版本不一样 你先重启服务看下日志
    Roboo
        6
    Roboo  
       2014-07-20 23:55:23 +08:00 via Android
    对 还有ls说的文件的问题 可能是这个
    LiJie
        7
    LiJie  
       2014-07-21 00:10:40 +08:00
    路径是 /usr/share/nginx/html
    tjmao
        8
    tjmao  
       2014-07-21 03:37:32 +08:00 via iPhone
    你自己创建的是phpinfo.php,自然得读出phpinfo.php的内容,方能看到phpinfo.php的输出。

    看看 http://ip/phpinfo.php 有没有输出?如果还没有,继续挖日志。
    binux
        9
    binux  
       2014-07-21 03:46:00 +08:00 via Android   ❤️ 1
    13: Permission denied
    zjgood
        10
    zjgood  
       2014-07-21 06:45:09 +08:00 via Android   ❤️ 1
    @1dian01 我想你需要 tail -f /var/log/nginx/error.log 看看错误
    kennedy32
        11
    kennedy32  
       2014-07-21 09:43:18 +08:00   ❤️ 1
    很早以前遇到过这个问题,之后差不多一年没有遇到过。

    一般情况下(一个服务器只有一个php5-fpm+nginx实例,使用默认的www-data用户),应该是不需要修改php5-fpm的ini文件的。

    我建议安装顺序改成nginx,php,mysql ,然后修改nginx使php能够运行,然后写一个phpinfo.php
    jakehu
        12
    jakehu  
       2014-07-21 09:57:43 +08:00
    装个面板不就完事了吗? wdcp 也可以啊
    1dian01
        13
    1dian01  
    OP
       2014-07-21 10:20:54 +08:00
    @binux 请问这个改如果修改?
    1dian01
        14
    1dian01  
    OP
       2014-07-21 10:25:46 +08:00
    @binux 找到下面这个答案,为啥这样,看不明白,帮忙看看是啥情况
    After upgrading to Nginx 1.4.7 and PHP 5.4.28 (or 5.5.12), you may start seeing errors like the following:

    2014/05/03 13:27:41 [crit] 4202#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: xx.xxx.xx.xx, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "xx.xx.xx.xx"

    The fix is to edit /etc/php5/fpm/pool.d/www.conf and set the listen.mode to 666 (be sure to uncomment the line as well):

    listen.mode = 0666
    binux
        15
    binux  
       2014-07-21 10:26:45 +08:00   ❤️ 1
    @1dian01 看看这个文件的owner和权限,保证nginx设置的user有权限
    binux
        16
    binux  
       2014-07-21 10:27:13 +08:00   ❤️ 1
    @1dian01
    The fix is to edit /etc/php5/fpm/pool.d/www.conf and set the listen.mode to 666 (be sure to uncomment the line as well):

    listen.mode = 0666
    ooxxcc
        17
    ooxxcc  
       2014-07-21 10:40:45 +08:00   ❤️ 1
    注意www.conf里面的

    listen.owner = www-data
    listen.group = www-data
    listen.mode = 0666
    1dian01
        18
    1dian01  
    OP
       2014-07-21 10:43:18 +08:00
    @ooxxcc 可以讲讲为啥要这样设置不?
    1dian01
        19
    1dian01  
    OP
       2014-07-21 10:44:34 +08:00
    It's indeed caused by a recent update of PHP that fixes this (security related) bug: https://bugs.php.net/bug.php?id=67060
    Everyone who's running PHP >= 5.5.12 or >= 5.4.28 is affected.

    It can only be fixed in PuPHPet by changing the listen.mode back to 0666 (not recommended) or making sure the correct user is using the socket.
    This must be changed in the PuPHPet configuration.
    ooxxcc
        20
    ooxxcc  
       2014-07-21 10:49:21 +08:00   ❤️ 1
    @1dian01 php-fpm监听的sock的owner group和权限,让nginx可以读写
    ooxxcc
        21
    ooxxcc  
       2014-07-21 10:49:54 +08:00   ❤️ 1
    %s,sock,socket,g
    1dian01
        22
    1dian01  
    OP
       2014-07-21 10:57:56 +08:00
    @ooxxcc 下面是不是说这是一个bug?为啥不建议把listen.mode修改为0666,谢谢

    It's indeed caused by a recent update of PHP that fixes this (security related) bug: https://bugs.php.net/bug.php?id=67060
    Everyone who's running PHP >= 5.5.12 or >= 5.4.28 is affected.

    It can only be fixed in PuPHPet by changing the listen.mode back to 0666 (not recommended) or making sure the correct user is using the socket.
    This must be changed in the PuPHPet configuration.
    coolicer
        23
    coolicer  
       2014-07-21 11:02:21 +08:00
    有这么难吗,我装下来都没有问题。
    1dian01
        24
    1dian01  
    OP
       2014-07-21 11:28:21 +08:00
    @coolicer 真了不起!佩服!
    lsylsy2
        25
    lsylsy2  
       2014-07-21 11:33:00 +08:00   ❤️ 1
    @1dian01 0666的话,本机上的所有用户都可以以这个用户的身份调用PHP,主要是在虚拟主机一样用户隔离的系统里面
    举个例子:用户A写了个PHP,内容是ls /home/b,本来这个是执行不了的(没有权限),但是他把这个PHP发给了/var/run/userb/php.socket,于是就可以查看B的home了
    BOOM
        26
    BOOM  
       2014-07-21 11:40:22 +08:00
    装个LNMP。或者直接把LNMP的代码拿来看看不就行。
    hiths
        27
    hiths  
       2014-07-21 14:15:21 +08:00
    我也是这个问题,sock监听http返回200,页面却是空白,端口就正常。
    5dkgansm
        28
    5dkgansm  
       2014-07-21 14:49:26 +08:00
    @1dian01
    不想折腾的话直接下phpstudy,有linux版本的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2211 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 09:41 · PVG 17:41 · LAX 02:41 · JFK 05:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.