设为首页 收藏本站
查看: 1341|回复: 0

[经验分享] 解决phpMyAdmin在nginx+php-fpm模式下无法使用的问题

[复制链接]

尚未签到

发表于 2018-11-11 09:07:12 | 显示全部楼层 |阅读模式
  昨天接到一个网友的问题,说yum安装nginx+php-fpm+mysql+phpMyAdmin后,发现phpMyAdmin无法打开,一直报502错误已经抓狂半天了,本着帮助别人快乐自己的原则,远程帮他看了一下, 现记录和总结如下,问题解决思路的总结放在文章最后,问题解决思路总结也是本文的重点。
  问题环境:CentOS6通过yum安装的nginx+php-fpm+mysql+phpMyAdmin
  问题描述:安装完成后发现nginx没有问题,而phpMyAdmin无法打开,提示502错误
  问题解决过程
  查看问题环境的安装包:
nginx-filesystem-1.0.15-12.el6.noarchnginx-1.0.15-12.el6.x86_64rrdtool-php-1.3.8-7.el6.x86_64php-pear-1.9.4-4.el6.noarchphp-devel-5.3.3-46.el6_6.x86_64php-mbstring-5.3.3-46.el6_6.x86_64php-mcrypt-5.3.3-3.el6.x86_64php-5.3.3-46.el6_6.x86_64php-tidy-5.3.3-46.el6_6.x86_64php-pecl-memcache-3.0.5-4.el6.x86_64php-xmlrpc-5.3.3-46.el6_6.x86_64php-xmlseclibs-1.3.1-3.el6.noarchphp-common-5.3.3-46.el6_6.x86_64php-pdo-5.3.3-46.el6_6.x86_64php-xml-5.3.3-46.el6_6.x86_64php-fpm-5.3.3-46.el6_6.x86_64php-cli-5.3.3-46.el6_6.x86_64php-mysql-5.3.3-46.el6_6.x86_64php-eaccelerator-0.9.6.1-1.el6.x86_64php-gd-5.3.3-46.el6_6.x86_64  根据nginx报的502错误,可以初步判断是upstream出现了问题,再提到upstream之前,先列一下nginx的配置文件(去掉注释,我已经将nginx记录错误日志的级别从默认级别提升到info)。
user              nginx;  
worker_processes  1;
  
error_log  /var/log/nginx/error.log info;
  
pid        /var/run/nginx.pid;
  
events {
  
    worker_connections  1024;
  
}
  
http {
  
    include       /etc/nginx/mime.types;
  
    default_type  application/octet-stream;
  
    client_max_body_size 10M;
  
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  
                      '$status $body_bytes_sent "$http_referer" '
  
                      '"$http_user_agent" "$http_x_forwarded_for"';
  
    access_log  /var/log/nginx/access.log  main;
  
    sendfile        on;
  
    keepalive_timeout  65;
  
    include /etc/nginx/conf.d/*.conf;
  
}
  由于此配置文件中没有显式写明任何server,因此需要查看一下include /etc/nginx/conf.d/*.conf; 所包含的默认server文件,即/etc/nginx/conf.d/default.conf,去掉注释
cat /etc/nginx/conf.d/default.conf  
server {
  
    listen       80 default_server;
  
    server_name  _;
  
    include /etc/nginx/default.d/*.conf;
  
    location / {
  
        root   /usr/share/nginx/html;
  
        index  index.php index.html index.htm;
  
    }
  
    error_page  404              /404.html;
  
    location = /404.html {
  
        root   /usr/share/nginx/html;
  
    }
  
    error_page   500 502 503 504  /50x.html;
  
    location = /50x.html {
  
        root   /usr/share/nginx/html;
  
    }
  
     location ~ [^/]\.php(/|$) {
  
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  
                if (!-f $document_root$fastcgi_script_name) {
  
                        return 404;
  
                }
  
                fastcgi_pass 127.0.0.1:9000;
  
                fastcgi_index index.php;
  
                include fastcgi_params;
  
     }
  
}
  初步判断,此nginx的配置确实没有问题,应该是php-fpm或者php本身的问题(缩小问题范围)。
  查阅nginx日志文件(/var/log/nginx/error.log),发现如下提示,确定是php-fpm的问题,fastcgi也算是对upstream的一种代理
2015/08/14 17:05:32 [notice] 9645#0: using the "epoll" event method  
2015/08/14 17:05:32 [notice] 9645#0: nginx/1.0.15
  
2015/08/14 17:05:32 [notice] 9645#0: built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
  
2015/08/14 17:05:32 [notice] 9645#0: OS: Linux 2.6.32-504.el6.x86_64
  
2015/08/14 17:05:32 [notice] 9645#0: getrlimit(RLIMIT_NOFILE): 65535:65535
  
2015/08/14 17:05:32 [notice] 9646#0: start worker processes
  
2015/08/14 17:05:32 [notice] 9646#0: start worker process 9648
  
2015/08/14 17:05:36 [error] 9648#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.1.228, server: 192.168.1.101, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.1.101"
  
2015/08/14 17:09:22 [error] 9648#0: *4 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.1.228, server: 192.168.1.101, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.1.101"
  
2015/08/14 17:11:23 [error] 9648#0: *7 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.1.228, server: 192.168.1.101, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.1.101"
  
2015/08/14 17:11:33 [info] 9648#0: *9 client closed prematurely connection while reading client request line, client: 192.168.1.228, server: 192.168.1.101
  创建一个能打开phpinfo的文件,查看php文件能否正确解析(进一步缩小问题范围)
  发现php-fpm能正常解析php文件,里面的各个php组件都显示正常
  查看phpMyAdmin的版本,查阅官方网站的文档看看是否支持php5.3.3,发现当前的phpMyAdmin支持,因此应该不是phpMyAdmin的问题
  开始检查php-fpm的日志(/var/log/php-fpm/error.log),发现如下所示:
[14-Aug-2015 16:34:53] NOTICE: fpm is running, pid 9522  
[14-Aug-2015 16:34:53] NOTICE: ready to handle connections
  
[14-Aug-2015 16:43:54] WARNING: [pool www] child 9527 exited on signal 11 (SIGSEGV) after 541.401349 seconds from start
  
[14-Aug-2015 16:43:55] NOTICE: [pool www] child 9614 started
  
[14-Aug-2015 16:44:00] WARNING: [pool www] child 9526 exited on signal 11 (SIGSEGV) after 547.107407 seconds from start
  
[14-Aug-2015 16:44:00] NOTICE: [pool www] child 9615 started
  
[14-Aug-2015 17:05:36] WARNING: [pool www] child 9523 exited on signal 11 (SIGSEGV) after 1843.098829 seconds from start
  
[14-Aug-2015 17:05:36] NOTICE: [pool www] child 9649 started
  这个日志显然不足以提供足够的信息来解决问题,因此修改php-fpm和php.ini对日志级别的一些参数配置,以提升日志级别,获取详细的错误信息。
  搜索配置文件的中log关键字,或者根据文档或资料修改,一些方法或步骤如下:
  /etc/php-fpm.conf文件,将日志级别从notice改动到debug
log_level = debug  /etc/php-fpm.d/www.conf文件,将php worker的标准输出和错误输出从/dev/null 重定向到主要的错误日志中,即/var/log/php-fpm/error.log
catch_workers_output = yes  /etc/php.ini文件
error_reporting = E_ALL & ~E_DEPRECATED  
display_errors = On
  
display_startup_errors = On
  
log_errors = On
  
track_errors = On
  
html_errors = On
  再次重新启动php-fpm,发现worker中的详细错误:
[14-Aug-2015 17:09:18] NOTICE: fpm is running, pid 9672  
[14-Aug-2015 17:09:18] NOTICE: ready to handle connections
  
[14-Aug-2015 17:09:22] WARNING: [pool www] child 9673 said into stderr: "[Fri Aug 14 17:09:22 2015"
  
[14-Aug-2015 17:09:22] WARNING: [pool www] child 9673 said into stderr: "] [notice] EACCELERATOR(9673): PHP crashed on opline 30 of PMA_URL_getCommon() at /usr/share/nginx/html/libraries/url_generating.lib.php:188"
  
[14-Aug-2015 17:09:22] WARNING: [pool www] child 9673 said into stderr: ""
  
[14-Aug-2015 17:09:22] WARNING: [pool www] child 9673 exited on signal 11 (SIGSEGV) after 4.286828 seconds from start
  
[14-Aug-2015 17:09:22] NOTICE: [pool www] child 9679 started
  
[14-Aug-2015 17:11:23] WARNING: [pool www] child 9675 said into stderr: "[Fri Aug 14 17:11:23 2015"
  
[14-Aug-2015 17:11:23] WARNING: [pool www] child 9675 said into stderr: "] [notice] EACCELERATOR(9675): PHP crashed on opline 30 of PMA_URL_getCommon() at /usr/share/nginx/html/libraries/url_generating.lib.php:188"
  错误信息中提到EACCELERATOR这个php模块,因此先确定一下是不是由于这个模块有问题,因此,先将此模块禁用,方法是将/etc/php.d/eaccelerator.ini文件更改个后缀名称,例如mv /etc/php.d/eaccelerator.ini /etc/php.d/eaccelerator.ini~,然后重启php-fpm,再校验一下结果,发现问题已经解决。
  可能是eaccelerator与phpMyAdmin冲突的原因,因此要想使用phpMyAdmin可以将此模块禁用,或者安装时跳过这个包。
  注释:eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。它还有对脚本起优化作用,以加快其执行效率。使PHP程序代码执效率能提高1-10倍。(来自bdbk)
  问题解决思路总结
  第0条,沟通是诊断故障的关键,详细了解问题始末,例如部署方案,步骤,做了哪些操作等
  第一,根据经验判断,nginx+php-fpm+phpMyAdmin是很牢靠的组合,因此判断这是个例问题,而不是批量问题,因此直接开始动手,登录到系统中查看安装的软件包,nginx、php和phpMyAdmin版本都是要查看的,此步骤有助于根据掌握的知识和经验,初步判断是否相互兼容,是否有未修复bug等。
  第二,执行nginx -t检查nginx的配置文件有无显式错误,检查nginx运行状态
  第三,执行php-fpm -t检查php-fpm的配置文件有无显式错误,检查php-fpm的运行状态
  第四,检查错误日志,先检查nginx的错误日志,因为它是“第一现场”,再检查php-fpm日志,因为它是“第二现场”
  第五,如果日志提示明显,则按照日志提示,修改相应的配置文件,再次验证问题
  第六,如果依然有问题,则本步骤就是解决问题的最关键的步骤,需要提升记录日志的级别,这也就是为什么有debug为什么叫做调试,将nginx的日志级别提升到info(为什么不能提升到debug,nginx编译时有个--debug选项,不确定时可以不用),将php的日志级别提升到debug,打开所有的php调试开关
  第七,重新启动nginx和php-fpm后,配置文件生效,重新打开网页重现问题,再次打开日志,根据日志提示内容再次,修改相应的配置文件,再次验证问题
  第八,如果反复修改无果后,该查阅官方手册就查阅官方手册,该Google 搜索就Google搜索,该反馈bug就反馈bug,如果持续无果,则换种解决问题的方式,寻找正确的解决方案,参照如下:

  •   参考已有的成功的版本组合,更换版本组合或者修改配置文件,消除环境差异性,适用于快速解决问题
  •   将yum安装改为编译安装,或者yum安装更少的包,以最小化的安装方式将问题范围缩减到最小,从而确定问题,提升解决问题的能力,适用于研究和学习
  最后补充一句:只要出现的问题能够重现,而不是随机出现,则就一定能很好的解决,因此不要慌,也不要浮躁,更不要放弃,甚至可以缓一缓后再冷静处理。
  --end--



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-633534-1-1.html 上篇帖子: CentOS下nginx+mono+fastcgi构建asp.net服务器笔记 下篇帖子: 用nginx_php 自动安装LNMP第二版
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表