我使用Apache 2.2.15在rhel 6.2上运行php 5.3.3,并且没有得到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执行时,我得到期望的文本输出到terminal(“ Hello php World ”)。
什么时候,我添加一些HTML到index.php中,如下所示:
<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是通过CLIparsing和解释的,而不是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文件被parsing:
chcon -R -h -t httpd_sys_content_t /export1
是正确的。 我不认为selinux是问题,因为我没有得到任何权限的错误,我已经暂时禁用selinux echo 0 >/selinux/enforce没有由Apache解释的PHP的结果成功。
php模块正在被加载其configuration,并且.php扩展名被理解为在httpd.conf中configuration:
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
请帮忙!
似乎php5_module已经被你自己加载了,之后被默认的rhel6configuration加载,或者rhel6configuration加载了模块php5_module …这本身并不重要,除了你正在input的configuration被覆盖由默认的rhel6configuration。
看着Dan的网站上的第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
说明一些明显的东西,你从来没有说过你是如何访问示例文件。 你直接访问index.php (即http://example.com/folder/index.php )吗?
如果没有,请注意,如果有一个index.html ,它将被调用,因为目录索引顺序:
DirectoryIndex index.html index.html.var index.php
最后,这应该在serverfault.com而不是在这里。
我有一个类似的问题,最后通过在/etc/php.ini设置short_open_tag = On来修复它。 升级时要小心默认configuration文件!