Apache-2.2

PHP 不在 apache2 上執行

  • June 4, 2017

我執行 apache(Apache/2.2.14 Ubuntu)。PHP 未執行。我注意到這條線

AddType application/x-httpd-php .php .html .htm

/etc/apache2/apache.conf 中缺少我嘗試在 .conf 文件的多個位置添加該行。沒有任何效果。

我試過chown www-data /var/www/chmod 777 /var/www(我是 linux 新手)

我讀到你可能需要添加

AddType application/x-httpd-php .php

到 httpd.conf。這也沒有結果

我也嘗試執行這個簡單的程式碼(放在 /var/www/ 中)

<?php
 phpinfo();
?>

Firefox 提示我保存文件而不是執行它。

是的,我每次進行更改時都重新啟動了 apache。

我被困住了。

編輯:

ls - l /var/給,

.....
.....
drwxrwxrwx  3 www-data www-data 4096 2011-12-05 14:39 www

既然apache執行在這個組裡,那麼所有者應該是www-data吧?

訪問日誌給了我:

127.0.0.1 - - [05/Dec/2011:14:39:58 -0500] "GET /info.php HTTP/1.1" 200 327 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110628 Ubuntu/10.04 (lucid) Firefox/3.6.18"
127.0.0.1 - - [05/Dec/2011:14:45:35 -0500] "GET /info.php HTTP/1.1" 304 187 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110628 Ubuntu/10.04 (lucid) Firefox/3.6.18"
127.0.0.1 - - [05/Dec/2011:14:46:44 -0500] "GET /info.php HTTP/1.1" 304 187 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110628 Ubuntu/10.04 (lucid) Firefox/3.6.18"
127.0.0.1 - - [05/Dec/2011:14:53:26 -0500] "GET /info.php HTTP/1.1" 304 187 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110628 Ubuntu/10.04 (lucid) Firefox/3.6.18"

和錯誤日誌:

[Mon Dec 05 14:25:08 2011] [notice] caught SIGTERM, shutting down
[Mon Dec 05 14:25:09 2011] [notice] Apache/2.2.14 (Ubuntu) configured -- resuming normal operations
[Mon Dec 05 14:27:08 2011] [notice] caught SIGTERM, shutting down
[Mon Dec 05 14:27:09 2011] [notice] Apache/2.2.14 (Ubuntu) configured -- resuming normal operations
[Mon Dec 05 14:35:33 2011] [notice] caught SIGTERM, shutting down
[Mon Dec 05 14:35:34 2011] [notice] Apache/2.2.14 (Ubuntu) configured -- resuming normal operations
[Mon Dec 05 14:35:52 2011] [notice] caught SIGTERM, shutting down
[Mon Dec 05 14:35:53 2011] [notice] Apache/2.2.14 (Ubuntu) configured -- resuming normal operations
[Mon Dec 05 14:45:29 2011] [notice] caught SIGTERM, shutting down
[Mon Dec 05 14:45:30 2011] [notice] Apache/2.2.14 (Ubuntu) configured -- resuming normal operations
[Mon Dec 05 14:46:38 2011] [notice] caught SIGTERM, shutting down
[Mon Dec 05 14:46:39 2011] [notice] Apache/2.2.14 (Ubuntu) configured -- resuming normal operations
[Mon Dec 05 14:54:16 2011] [notice] caught SIGTERM, shutting down
[Mon Dec 05 14:54:17 2011] [notice] Apache/2.2.14 (Ubuntu) configured -- resuming normal operations

你真的安裝了PHP嗎?包libapache2-mod-php5?通常,在安裝此軟體包時,您不需要編輯任何配置文件來啟動 PHP。

檢查apache的錯誤日誌。檢查您是否LoadModule php5_module modules/libphp5.so在 apache 配置中有或類似的配置。檢查 libphp5.so 文件是否存在。檢查 libphp5.so 是否由 apache 載入pmap <apache_worker_PID>|grep php。例如執行:

ps -edf |grep apache|grep -v root|head -1|awk '{print $2}'|xargs pmap|grep php

您可以在 Ubuntu 上的 apache 中啟用 php:

sudo a2enmod php5
sudo /etc/init.d/apache2 force-reload

另請參閱:https ://help.ubuntu.com/community/ApacheMySQLPHP#Installing_PHP_5

引用自:https://serverfault.com/questions/337873