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, from my browser, 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:

<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 success.

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
link|improve this question
feedback

migrated from stackoverflow.com Feb 7 at 9:42

This question came from our site for professional and enthusiast programmers.

2 Answers

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:

DirectoryIndex index.html index.html.var index.php

Lastly, this should be asked in serverfault.com instead of here.

link|improve this answer
Would be the right place, so yes, please! :) – user00265 Feb 3 at 22:39
feedback
up vote 0 down vote accepted

This question should be closed (not sure how to do so) as it was already posted on serverfault.com: Apache executes HTML, but not PHP; PHP CLI works See that post for the resolution.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.