1. 程式人生 > 實用技巧 >PHP出現access denied問題及解決辦法

PHP出現access denied問題及解決辦法

配置好PHP環境後,訪問頁面,頁面上只出現了 Access denied字樣。

問題分析

開啟 /usr/local/php/etc/php.ini 檔案,找到 cgi.fix_pathinfo

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0

這裡註釋裡預設是1,但是用oneinstack 安裝後預設是0。

如果在Nginx裡配置了

fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 

則 cgi.fix_pathinfo=0 必須改為1。

解決

配置修改為cgi.fix_pathinfo=1,重啟 php-fpm 和 Nginx 後解決。