我正在使用Apache2.2.15运行php5.3.3在heil6.2上,并且无法得到Apache解释的php代码。
没有错误(系统日志、httpd/ error _log或php_errors.log) --我已经启用了php.ini中的错误报告:
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = On
log_errors = On
error_log = /var/log/php_errors.log然而,当我直接从浏览器(例如myserver.com/ index.php )查看包含以下代码的index.php时,只会出现一个白屏幕:
<?php echo 'Hello php World'; ?>在命令行上由php执行时,我将获得终端("Hello php World")的预期文本输出。
当我向index.php添加一些HTML时,如下所示:
<html>
<p>Hello from within html</p>
<?php echo 'Hello php World'; ?>
</html>然后用我的浏览器查看它,它只返回“Hello from within html”。但是,当从命令行执行时,我得到:
<html>
<p>Hello from within html</p>
Hello php World</html>因此,PHP是通过CLI解析和解释的,而不是由Apache解析和解释的。
我已经确认index.php及其父文件结构属于apache:apache,并且apache模块的selinux上下文:
chcon -t httpd_sys_script_exec_t /usr/lib/httpd/modules/*
chcon -t httpd_sys_script_exec_t /usr/lib/php/modules/*以及要解析的.php文件:
chcon -R -h -t httpd_sys_content_t /export1是正确的。我不认为selinux是问题所在,因为我没有得到任何权限错误,而且我暂时禁用了selinux echo 0 >/selinux/enforce,但是apache解释的php没有成功。
php模块与其配置一起加载,.php扩展被理解为在httpd.conf中配置:
LoadModule php5_module /usr/lib/httpd/modules/libphp5.so
AddType application/x-httpd-php .php .phtml
PHPIniDir /etc/而且,apache知道从以下位置查找index.php:
DirectoryIndex index.html index.html.var index.php设置在httpd.conf中。
我已经用尽我的想法,我的问题在哪里-甚至尝试重新安装PHP -肯定会感激任何想法。如果它有用,下面是启动apache时/var/log/httpd/error_log的内容:
[Fri Feb 03 13:44:53 2012] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
[Fri Feb 03 13:44:53 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Fri Feb 03 13:44:53 2012] [warn] module php5_module is already loaded, skipping
[Fri Feb 03 13:44:53 2012] [notice] Digest: generating secret for digest authentication ...
[Fri Feb 03 13:44:53 2012] [notice] Digest: done
[Fri Feb 03 13:44:54 2012] [warn] mod_wsgi: Compiled for Python/2.6.2.
[Fri Feb 03 13:44:54 2012] [warn] mod_wsgi: Runtime using Python/2.6.6.
[Fri Feb 03 13:44:54 2012] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.0-fips mod_wsgi/3.2 Python/2.6.6 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations请帮帮我!
发布于 2012-02-06 23:37:23
似乎php5_module已经由您自己加载,稍后由默认的rhel6配置加载,或者rhel6上的配置正在加载模块php5_module……这本身并不重要,只是您正在输入的配置被默认的rhel6配置覆盖。
看看丹氏遗址的第11步,它曾经在我忘记和需要快速提醒的时候对我起过作用:
# Make sure there's only **1** line for each of these 2 directives:
# Use for PHP 4.x:
#LoadModule php4_module modules/libphp4.so
#AddHandler php-script .php
# Use for PHP 5.x:
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
AddType text/html .php
# PHP Syntax Coloring
# (optional but useful for reading PHP source for debugging):
AddType application/x-httpd-php-source phps发布于 2012-02-03 22:08:14
在我看来,你从来没有说过你是如何尝试访问这个示例文件的。您是否直接访问index.php (即。http://example.com/folder/index.php)?
如果没有,请注意,如果存在index.html,则将根据目录索引顺序调用它:
DirectoryIndex index.html index.html.var index.php最后,应该在serverfault.com中而不是在这里来问这个问题。
发布于 2012-10-12 19:10:17
我也遇到了类似的问题,最后通过在short_open_tag = On中设置/etc/php.ini来解决这个问题。升级时要小心默认配置文件!
https://serverfault.com/questions/357245
复制相似问题