I am running php 5.3.3 on rhel 6.2 with Apache 2.2.15 and am failing to get PHP code interpreted by Apache.
There are no errors (in the system log, httpd/error_log, or php_errors.log) - I have enabled error reporting in php.ini:
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = On
log_errors = On
error_log = /var/log/php_errors.log
Yet, when i view my index.php, which contains the following code, directly from my browser (e.g. myserver.com/index.php), nothing appears but a white-screen:
<?php echo 'Hello php World'; ?>
When executed by php on the command line, I get the expected text output to the terminal ("Hello php World
").
When, I add some HTML to index.php as in:
<html>
<p>Hello from within html</p>
<?php echo 'Hello php World'; ?>
</html>
and view it with my browser, it returns just "Hello from within html
." However, when executed from the command line, I get:
<html>
<p>Hello from within html</p>
Hello php World</html>
So, the PHP is parsed and interpreted via the CLI, but not by Apache.
I have confirmed that index.php and its parent file structure are owned by apache:apache and that the selinux context of the apache modules :
chcon -t httpd_sys_script_exec_t /usr/lib/httpd/modules/*
chcon -t httpd_sys_script_exec_t /usr/lib/php/modules/*
and of the .php files to be parsed:
chcon -R -h -t httpd_sys_content_t /export1
are correct. I don't think selinux is the problem because I don't get any permission errors, and I've temporarily disabled selinux echo 0 >/selinux/enforce
with no resultant success of the php being interpreted by apache.
The php module is being loaded with its configuration and the .php extension is being understood as configured in httpd.conf:
LoadModule php5_module /usr/lib/httpd/modules/libphp5.so
AddType application/x-httpd-php .php .phtml
PHPIniDir /etc/
And, apache knows to look for index.php from:
DirectoryIndex index.html index.html.var index.php
as set in httpd.conf.
I have exhausted my ideas of where my problem is - even tried reinstalling PHP - and sure would appreciate any ideas. In case it's of use, here are the contents of /var/log/httpd/error_log when I start up apache:
[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
Please help!
It seems that
php5_module
is already loaded by yourself and loaded later by the defaultrhel6
configuration or the configuration onrhel6
is loading the modulephp5_module
... which in itself doesn't matter except for the fact that the configuration you are entering is being overridden by the defaultrhel6
configuration.Looking at step 11 from Dan's site, which has worked for me in the past whenever I forgot and needed a quick reminder:
Stating something obvious to my eyes, you never stated how you are trying to access the example file. Are you accessing
index.php
directly (ie. http://example.com/folder/index.php)?If not, do note that if there is an
index.html
it will be called instead because of the directory index order:Lastly, this should be asked in serverfault.com instead of here.
I had a similar problem and finally fixed it by setting
short_open_tag = On
in/etc/php.ini
. Beware of default config files when upgrading!For me, the problem was that the mod was not enabled in apache2.
Clean Debian install, apache2 and php7
I had first to disable mpm_event mod that was enabled by default, i don't know why. By the way, mpm is a very clean way to use PHP, you should consider it instead of the apache2 mod ;) But well, to work quick :
did the trick :)
Enjoy