我运行 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
答案1
您实际安装了 PHP 吗?软件包libapache2-mod-php5
?通常,安装此软件包时,您不需要编辑任何配置文件来激活 PHP。
答案2
检查 apache 的错误日志。检查LoadModule php5_module modules/libphp5.so
apache 配置中是否有 或类似内容。检查 libphp5.so 文件是否存在。使用 检查 apache 是否加载了 libphp5.so 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