phpMyAdmin在nginx+php

40次阅读
没有评论

共计 7008 个字符,预计需要花费 18 分钟才能阅读完成。

行业资讯    
数据库    
phpMyAdmin 在 nginx+php-fpm 模式下无法使用的解决方法

自动写代码机器人,免费开通

这篇文章给大家分享的是有关 phpMyAdmin 在 nginx+php-fpm 模式下无法使用的解决方法的内容。丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考。一起跟随丸趣 TV 小编过来看看吧。

昨天接到一个网友的问题,说 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 安装更少的包,以最小化的安装方式将问题范围缩减到最小,从而确定问题,提升解决问题的能力,适用于研究和学习

感谢各位的阅读!关于 phpMyAdmin 在 nginx+php-fpm 模式下无法使用的解决方法就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向 AI 问一下细节

丸趣 TV 网 – 提供最优质的资源集合!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-18发表,共计7008字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)