Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am having trouble using the php module with apache2. At the moment, testing with a phpinfo script, only php code is displayed as though it were text, no output at all.

I have the line LoadModule php5_module libphp5.so, with an absolute path.

Yet, when I do apache2 -t -D DUMP_MODULES |grep php, nothing is reported

I have my error level set to warn, and the last entry in my logfile after apache starts is

[notice] Apache/2.2.15 (Unix) PHP/5.2.12 mod_ssl/2.2.15 OpenSSL/0.9.8g configured -- resuming normal operations

Which implies there is php support?

share|improve this question

3 Answers 3

up vote 0 down vote accepted

Try grep -i php. Also do you have AddHandler php5-script .php anywhere in /etc/apache2/*.conf or in the vhost configurations?

share|improve this answer
    
I should have said I tried with grep -i....php does not show up as a loaded module even without grep. And yes, I have the Addhandler section(s) - although I just noticed I don't have any ini or conf file specified for php, do I need this for the module? –  user47587 Sep 4 '10 at 22:00
    
stupid question, but have you installed php? –  James Lawrie Sep 4 '10 at 22:02
    
Im trying to set this up on private server host im paying for, so everything is already installed –  user47587 Sep 4 '10 at 22:06
    
Do you have an /etc/apache2/conf.d/php.conf? It might be elsewhere in Ubuntu. There should be something similar to LoadModule php5_module modules/libphp5.so somewhere –  James Lawrie Sep 4 '10 at 22:13
    
The LoadModule line is in my httpd.conf, I can not find any php.conf file. –  user47587 Sep 4 '10 at 22:23

I had the same problem but it was because CentOS (and I assume RHEL), by default, doesn't recognize the short short tag...

<?

but requires the long tag...

<?php

at the beginning of a block of PHP code.

In php.ini (probably /etc/php.ini) look for "short_open_tag = off". Change this to "short_open_tag = on" and restart Apache to allow the short tag.

share|improve this answer

Make sure your handler looks like in the first reply and make sure it comes after mod_mime - this is most likely a handler issue:

LoadModule mime_module modules/mod_mime.so

Mod_mime is required to actually use the handlers. You should get a warning if it can't find mime.types (a dependency of the above module), but you might do a find / -name mime.types and copy this file into your /etc/httpd/conf/ directory.

http://httpd.apache.org/docs/2.0/mod/mod_mime.html You can make sure it's looking in the right place for the mime types by setting this TypesConfig directory: http://httpd.apache.org/docs/2.0/mod/mod_mime.html#typesconfig

You can also see if you have any luck adding these lines:

AddType application/x-httpd-php .php
AddHandler application/x-httpd-php .php

(The Type is more important for client requests.)


A simple test to see if you have PHP with mostly defaulted settings, is to go to a nonexistant page on your server thus generating a 404 error. It should tell you at the bottom something along the lines of

Not Found

The requested URL /test was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8e-fips-rhel5 PHP/5.2.11

Notice the PHP/5.2.11 in this listing....

share|improve this answer
    
When I go to a non existant file, I get an error message, but not the server info. Probably something to do with mod-security. I have added all the handlers as suggested, and php is loaded after mod_mime. Adding the handlers causes the browser to try and download the file rather than display it....but it still doesn't show the output. –  user47587 Sep 5 '10 at 0:37
    
Yea, mod-security usually does make some changes to that. You might try commenting out the loading of the mod_security module and of the .d directories (Include modsecurity.d/* and Include conf.d/*). The downloading of the file is probably due to the AddType. I might have made a mistake, the type might need text/html instead of application.x-httpd-php, but it's a mute point since apache should be passing it to PHP for processing. –  Joshua Enfield Sep 5 '10 at 1:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.