5

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!

2
  • 1
    If I recall correctly (I haven't used Apache for a while) - you need an AddHandler directive to have it associate the PHP file with the PHP parser. The AddType directive is more for setting the mime-type sent to the browser. Try adding: AddHandler php5-script .php after your AddType directive. You also seem to have LoadModule php5_module /usr/lib/httpd/modules/libphp5.so twice in your config (as per your error log) - so, it is possible you have conflicting Types/Handlers defined as well.
    – cyberx86
    Feb 6, 2012 at 15:38
  • I added this to httpd.conf, with no success. I should have mentioned it, but I did already have AddHandler php-script .php. Also, I did remove the redundant (and potentially conflicting) LoadModule call as you mentioned, also with no success.
    – geoweaser
    Feb 6, 2012 at 16:20

4 Answers 4

1

It seems that php5_module is already loaded by yourself and loaded later by the default rhel6 configuration or the configuration on rhel6 is loading the module php5_module... which in itself doesn't matter except for the fact that the configuration you are entering is being overridden by the default rhel6 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:

# 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
1
  • Yes - great - thanks! It seems that I had two redundancies in my httpd.conf: two AddHandler calls and an unnecessary LoadModule call . The combination of cyberx86's advice (above) of making sure that AddHandler php5-script .php was included; cyberx86's and your advice to remove the LoadModule php5_module modules/libphp5.so call (as rhel 6 is loading if by default); and your advice be careful to only have 1 line for each directive (i.e. remove AddHandler php-script .php) fixed the problem. Many hearty thanks!
    – geoweaser
    Feb 7, 2012 at 15:20
0

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.

1
  • Would be the right place, so yes, please! :)
    – user00265
    Feb 3, 2012 at 22:39
0

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!

2
  • In the examples from @geoweaser there are no short tags in use. A short tag looks like this <? echo "somehing"; ?> Oct 12, 2012 at 19:34
  • And why on earth do you have ancient code using short open tags? Oct 13, 2012 at 20:04
0

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 :

# a2dismod mpm_event
# a2enmod php7.0
# systemctl restart apache2

did the trick :)

Enjoy

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .