下面由phpmyadmin使用教程欄目給大家介紹phpMyAdmin在nginx+php-fpm模式下無法使用的解決方法,希望對需要的朋友有所幫助!
昨天接到一個(gè)網(wǎng)友的問題,說yum安裝nginx+php-fpm+mysql+phpMyAdmin后,發(fā)現(xiàn)phpMyAdmin無法打開,一直報(bào)502錯(cuò)誤已經(jīng)抓狂半天了,本著幫助別人快樂自己的原則,遠(yuǎn)程幫他看了一下, 現(xiàn)記錄和總結(jié)如下,問題解決思路的總結(jié)放在文章最后,問題解決思路總結(jié)也是本文的重點(diǎn)。
推薦:《phpmyadmin使用教程》
問題環(huán)境:CentOS6通過yum安裝的nginx+php-fpm+mysql+phpMyAdmin
問題描述:安裝完成后發(fā)現(xiàn)nginx沒有問題,而phpMyAdmin無法打開,提示502錯(cuò)誤
問題解決過程
查看問題環(huán)境的安裝包:
nginx-filesystem-1.0.15-12.el6.noarch |
nginx-1.0.15-12.el6.x86_64 |
rrdtool-php-1.3.8-7.el6.x86_64 |
php-pear-1.9.4-4.el6.noarch |
php-devel-5.3.3-46.el6_6.x86_64 |
php-mbstring-5.3.3-46.el6_6.x86_64 |
php-mcrypt-5.3.3-3.el6.x86_64 |
php-5.3.3-46.el6_6.x86_64 |
php-tidy-5.3.3-46.el6_6.x86_64 |
php-pecl-memcache-3.0.5-4.el6.x86_64 |
php-xmlrpc-5.3.3-46.el6_6.x86_64 |
php-xmlseclibs-1.3.1-3.el6.noarch |
php-common-5.3.3-46.el6_6.x86_64 |
php-pdo-5.3.3-46.el6_6.x86_64 |
php-xml-5.3.3-46.el6_6.x86_64 |
php-fpm-5.3.3-46.el6_6.x86_64 |
php-cli-5.3.3-46.el6_6.x86_64 |
php-mysql-5.3.3-46.el6_6.x86_64 |
php-eaccelerator-0.9.6.1-1.el6.x86_64 |
php-gd-5.3.3-46.el6_6.x86_64 |
根據(jù)nginx報(bào)的502錯(cuò)誤,可以初步判斷是upstream出現(xiàn)了問題,再提到upstream之前,先列一下nginx的配置文件(去掉注釋,我已經(jīng)將nginx記錄錯(cuò)誤日志的級別從默認(rèn)級別提升到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; 所包含的默認(rèn)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的配置確實(shí)沒有問題,應(yīng)該是php-fpm或者php本身的問題(縮小問題范圍)。
查閱nginx日志文件(/var/log/nginx/error.log),發(fā)現(xiàn)如下提示,確定是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
創(chuàng)建一個(gè)能打開phpinfo的文件,查看php文件能否正確解析(進(jìn)一步縮小問題范圍)
發(fā)現(xiàn)php-fpm能正常解析php文件,里面的各個(gè)php組件都顯示正常
查看phpMyAdmin的版本,查閱官方網(wǎng)站的文檔看看是否支持php5.3.3,發(fā)現(xiàn)當(dāng)前的phpMyAdmin支持,因此應(yīng)該不是phpMyAdmin的問題
開始檢查php-fpm的日志(/var/log/php-fpm/error.log),發(fā)現(xiàn)如下所示:
[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
這個(gè)日志顯然不足以提供足夠的信息來解決問題,因此修改php-fpm和php.ini對日志級別的一些參數(shù)配置,以提升日志級別,獲取詳細(xì)的錯(cuò)誤信息。
搜索配置文件的中l(wèi)og關(guān)鍵字,或者根據(jù)文檔或資料修改,一些方法或步驟如下:
/etc/php-fpm.conf文件,將日志級別從notice改動(dòng)到debug
log_level = debug
/etc/php-fpm.d/www.conf文件,將php worker的標(biāo)準(zhǔn)輸出和錯(cuò)誤輸出從/dev/null 重定向到主要的錯(cuò)誤日志中,即/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
再次重新啟動(dòng)php-fpm,發(fā)現(xiàn)worker中的詳細(xì)錯(cuò)誤:
[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"
錯(cuò)誤信息中提到EACCELERATOR這個(gè)php模塊,因此先確定一下是不是由于這個(gè)模塊有問題,因此,先將此模塊禁用,方法是將/etc/php.d/eaccelerator.ini文件更改個(gè)后綴名稱,例如mv /etc/php.d/eaccelerator.ini /etc/php.d/eaccelerator.ini~,然后重啟php-fpm,再校驗(yàn)一下結(jié)果,發(fā)現(xiàn)問題已經(jīng)解決。
可能是eaccelerator與phpMyAdmin沖突的原因,因此要想使用phpMyAdmin可以將此模塊禁用,或者安裝時(shí)跳過這個(gè)包。
注釋:eAccelerator是一個(gè)自由開放源碼php加速器,優(yōu)化和動(dòng)態(tài)內(nèi)容緩存,提高了php腳本的緩存性能,使得PHP腳本在編譯的狀態(tài)下,對服務(wù)器的開銷幾乎完全消除。它還有對腳本起優(yōu)化作用,以加快其執(zhí)行效率。使PHP程序代碼執(zhí)效率能提高1-10倍。(來自bdbk)
問題解決思路總結(jié)
第0條,溝通是診斷故障的關(guān)鍵,詳細(xì)了解問題始末,例如部署方案,步驟,做了哪些操作等
第一,根據(jù)經(jīng)驗(yàn)判斷,nginx+php-fpm+phpMyAdmin是很牢靠的組合,因此判斷這是個(gè)例問題,而不是批量問題,因此直接開始動(dòng)手,登錄到系統(tǒng)中查看安裝的軟件包,nginx、php和phpMyAdmin版本都是要查看的,此步驟有助于根據(jù)掌握的知識和經(jīng)驗(yàn),初步判斷是否相互兼容,是否有未修復(fù)bug等。
第二,執(zhí)行nginx -t檢查nginx的配置文件有無顯式錯(cuò)誤,檢查nginx運(yùn)行狀態(tài)
第三,執(zhí)行php-fpm -t檢查php-fpm的配置文件有無顯式錯(cuò)誤,檢查php-fpm的運(yùn)行狀態(tài)
第四,檢查錯(cuò)誤日志,先檢查nginx的錯(cuò)誤日志,因?yàn)樗恰暗谝滑F(xiàn)場”,再檢查php-fpm日志,因?yàn)樗恰暗诙F(xiàn)場”
第五,如果日志提示明顯,則按照日志提示,修改相應(yīng)的配置文件,再次驗(yàn)證問題
第六,如果依然有問題,則本步驟就是解決問題的最關(guān)鍵的步驟,需要提升記錄日志的級別,這也就是為什么有debug為什么叫做調(diào)試,將nginx的日志級別提升到info(為什么不能提升到debug,nginx編譯時(shí)有個(gè)–debug選項(xiàng),不確定時(shí)可以不用),將php的日志級別提升到debug,打開所有的php調(diào)試開關(guān)
第七,重新啟動(dòng)nginx和php-fpm后,配置文件生效,重新打開網(wǎng)頁重現(xiàn)問題,再次打開日志,根據(jù)日志提示內(nèi)容再次,修改相應(yīng)的配置文件,再次驗(yàn)證問題
第八,如果反復(fù)修改無果后,該查閱官方手冊就查閱官方手冊,該Google 搜索就Google搜索,該反饋bug就反饋bug,如果持續(xù)無果,則換種解決問題的方式,尋找正確的解決方案,參照如下:
-
參考已有的成功的版本組合,更換版本組合或者修改配置文件,消除環(huán)境差異性,適用于快速解決問題
-
將yum安裝改為編譯安裝,或者yum安裝更少的包,以最小化的安裝方式將問題范圍縮減到最小,從而確定問題,提升解決問題的能力,適用于研究和學(xué)習(xí)
最后補(bǔ)充一句:只要出現(xiàn)的問題能夠重現(xiàn),而不是隨機(jī)出現(xiàn),則就一定能很好的解決,因此不要慌,也不要浮躁,更不要放棄,甚至可以緩一緩后再冷靜處理。
–end–