
我有一台裝有 suPHP、Apache2 和 PHP5.4 的伺服器。
我注意到文檔index.html會執行PHP程式碼,而test.html不會執行PHP程式碼。當然,我不希望 PHP 程式碼在 index.html 檔案中執行。
我不知道該去哪裡找問題。我在配置中沒有找到將 php 處理程序指派給某些非 *.php 檔案的位置。
這是我的 mods-available/suphp.conf
<IfModule mod_suphp.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-suphp
</FilesMatch>
suPHP_AddHandler application/x-httpd-suphp
# suPHP_PHPPath /usr/bin/php
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
# Order allow,deny
# Allow from all
</FilesMatch>
AddType application/x-httpd-php-source .phps
suPHP_AddHandler application/x-httpd-php-source
# AddHandler application/x-httpd-php-source
<Directory />
suPHP_Engine on
</Directory>
# By default, disable suPHP for debian packaged web applications as files
# are owned by root and cannot be executed by suPHP because of min_uid.
# Benötigen wir für Nagios3
# <Directory /usr/share>
# suPHP_Engine off
# </Directory>
# # Use a specific php config file (a dir which contains a php.ini file)
# suPHP_ConfigPath /etc/php5/cgi/suphp/
# # Tells mod_suphp NOT to handle requests with the type <mime-type>.
# suPHP_RemoveHandler <mime-type>
</IfModule>
這是我的 mods-available/php5.conf
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
# <IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_value engine Off
# </Directory>
# </IfModule>
</IfModule>
答案1
檢查您的 .htaccess 檔案中的以下內容,因為您可以在那裡打開 php 解釋:
AddType application/x-httpd-php .html .htm
如果這不起作用,請進行字串搜尋。它很可能在某個地方被打開。
grep -rnw 'web_directory_here' -e "x-httpd-php"
如果您在任何地方找到 AddType,請將其刪除。
==
更新:另一個需要檢查的地方是你的 apache MIME 類型,以確保 html 沒有設定為 php。確保 html 不在下面的任何一行。
check in httpd/conf
application/x-httpd-php phtml php php3 php4 php5 php6
application/x-httpd-php-source phps
答案2
您引用您的 mods-available/php5.conf。你的mod_php5啟用了嗎,也就是說你有/etc/apache2/mods-enabled/php5.load嗎?如果是這樣,請嘗試a2dismod php5
,因為不建議同時啟用 suphp 和 mod_php,至少不是全域啟用。也可以嘗試在 index.html 中使用 phpinfo() 來確定哪個模組正在處理請求。