Thursday, February 3, 2011

Problem with php and apache...

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?

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

    Jacob : 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?
    James Lawrie : stupid question, but have you installed php?
    Jacob : Im trying to set this up on private server host im paying for, so everything is already installed
    James Lawrie : 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
    Jacob : The LoadModule line is in my httpd.conf, I can not find any php.conf file.
    James Lawrie : You shouldn't need a php.conf file if the data is in other configuration files (it's just typically there). Do you include anything else before the LoadModule line? The order of the declarations in httpd.conf can affect things. Also I thought it was apache2.conf on Ubuntu?
    Jacob : I'm not using ubuntu? There is stuff loaded before php...I will try putting php first.
  • 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....

    Jacob : 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.
    Josh : 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.
    From Josh

0 comments:

Post a Comment