OJ系統部署問題排查記錄;PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045]

前言

自己搭建的OJ系統移植到了另外一個服務器上,進行了重新部署配置,然後發現打不開了,頁面首先提示404,打開nginx的error的日誌文件,發現是文件權限不對,於是改了一通權限,重啓nginx,頁面又提示502,再次打開nginx日誌文件排查問題所在。

nginx的日誌文件的目錄如下

/var/log/nginx/error.log

正文

在linux中一般的文件都可以用vim打開查看,於是看到如下記錄

2020/04/09 08:00:11 [crit] 11025#11025: *2 connect() to unix:/run/php/php7.2-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.100, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "192.168.1.113"

看這個日誌應該是nginx的配置好像有點問題,意思大概就是無法找到php7.2-fpm.sock,然後突然意識到php版本問題,應該是7.0版本,於是打開nginx目錄下的默認配置文件,具體目錄如下

/etc/nginx/sites-enabled/default

使用vim打開上面這個路徑的這個文件即可打開配置文件,找到以下語句

fastcgi_pass unix:/run/php/php7.2-fpm.sock;

把7.2改成了7.0,原以爲這樣就可以,重啓nginx,然後頁面出現該網頁無法正常工作http error 500.。。。。。

再次打開error.log,出現以下錯誤

2020/04/09 08:06:05 [error] 11086#11086: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'debian-sys-maint'@'localhost' (using password: YES) in /home/judge/src/web/include/pdo.php:16
Stack trace:
#0 /home/judge/src/web/include/pdo.php(16): PDO->__construct('mysql:host=loca...', 'debian-sys-main...', '1HBDniSjkCEvrUA...', Array)
#1 /home/judge/src/web/include/memcache.php(43): pdo_query('select * FROM `...')
#2 /home/judge/src/web/index.php(23): mysql_query_cache('select * FROM `...')
#3 {main}
  thrown in /home/judge/src/web/include/pdo.php on line 16" while reading response header from upstream, client: 192.168.1.100, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "192.168.1.113"
PHP message: PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'debian-sys-maint'@'localhost' (using password: YES) 

看到這句應該是連接數據庫的時候出錯了,具體原因應該是用戶名密碼錯誤,於是改找到幾個配置文件修改了與數據庫一致的密碼,然後重啓nginx,又又又是http 500,查看error.log文件發現以下問題

2020/04/09 09:53:17 [error] 12278#12278: *2 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined offset: 0 in /home/judge/src/web/index.php on line 60
PHP message: PHP Warning:  require(template/bs3/index.php): failed to open stream: Permission denied in /home/judge/src/web/index.php on line 68
PHP message: PHP Fatal error:  require(): Failed opening required 'template/bs3/index.php' (include_path='.:/usr/share/php') in /home/judge/src/web/index.php on line 68" while reading response header from upstream, client: 192.168.1.100, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "192.168.1.113"

主要看這句

PHP message: PHP Fatal error:  require(): Failed opening required 'template/bs3/index.php' (include_path='.:/usr/share/php') in /home/judge/src/web/index.php on line 68" while reading response header from upstream, client: 192.168.1.100, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "192.168.1.113"

意思就是打開該路徑下的index.php文件失敗,應該又是文件權限問題,於是從文件夾template開始逐層檢查文件和文件夾權限,發現路徑中的bs3文件夾權限不對,後修改了權限,終於成功打開了首頁,至此OJ系統部署問題排查完成。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章