14

Recently upgraded my system from Karmic to Lucid. This involved Apache and PHP being updated I believe.

Now my server is unable to handle PHP files, any navigation to them is triggering downloading rather than parsing.

The PHP module is still loaded in Apache mods-enabled and I have AddType application/x-httpd-php .php in my httpd.conf.

There are no meaningful messages in Apache access or error logs so I am stumped.

Any help would be appreciated. Thanks.

3 Answers 3

17

/var/log/apache2/error.log should show a line like the below if PHP was succesfully loaded:

[Tue Aug 30 12:53:36 2011] [notice] Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.9 with Suhosin-Patch configured -- resuming normal operations

Pay attention to the date, if it's something from 2009, you've misconfigured something.

AddType is useless, you need to use:

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>

See also the installation instructions on php.net for Apache 2.x.

You should not have a need to add that manually, the package libapache2-mod-php5 installs /etc/apache2/mods-available/php5.conf containing:

<IfModule mod_php5.c>
    <FilesMatch "\.ph(p3?|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    # To re-enable php in user directories comment the following lines
    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
    <IfModule mod_userdir.c>
        <Directory /home/*/public_html>
            php_admin_value engine Off
        </Directory>
    </IfModule>
</IfModule>

Since it's a conffile, it's possible that it's not installed with the upgrade. To fix that purge it and then install it again:

sudo apt-get purge libapache2-mod-php5
sudo apt-get install libapache2-mod-php5

To enable PHP, you have to run:

sudo a2enmod php5

Restart the webserver after:

sudo /etc/init.d/apache2 restart

Other things to do:

  • check for conflicting settings in /etc/apache2.
  • have you built Apache from source?
  • Run sudo apache2ctl configtest to check your configuration for syntax errors
  • Open http://localhost/server-info to check the loaded configuration and modules. The status module must be loaded for that. If you're running a remote server, you need to add yourself to the Allow from list in /etc/apache2/mods-enabled/status.conf and restart the server afterwards
8
  • Brilliant. AFK right now, but will test this out tonight. Thanks.
    – Jivings
    Aug 30, 2011 at 12:23
  • Purged and reinstalled, the module is loaded in mods-enabled, but I am still having the same issue...I can't find anything that would be conflicted and the include for the conf files is definitely present in apache.conf. Do you have any other ideas? Thanks.
    – Jivings
    Aug 30, 2011 at 16:16
  • @Jivings: some debugging ideas added
    – Lekensteyn
    Aug 30, 2011 at 20:06
  • Still unable to figure it out. However I have discovered something even more curious. It seems that PHP is working fine for one of the Virtual Hosts that is set up, though all it does is define a documentRoot at /var/www. How is this possible?!
    – Jivings
    Aug 30, 2011 at 23:21
  • 1
    You will still need to flush your browser's cache and restart apache.
    – Francesco
    Feb 19, 2012 at 23:36
3

Well after nothing else worked and Apache was getting very confusing I finally just purged all of the Apache packages and reinstalled them.

Seems to be working fine now, who knows what was wrong with it....

EDIT

I found out what was wrong when I was setting up my Apache configuration settings again. [This blog entry][1] explains it.

Turns out that although the userdir module is not actively in use, the rest of the sites files reside in my ~/public_html folder, and php was being disabled for everything in there.

I guess this must have been a recent addition to the php module which wasn't present in my Karmic settings.

4
  • 1
    That should be related to a configuration issue. On upgrades, no files in /etc are copied afaik (at least, someone had an issue with /etc/init.d/apache2 not being created on reinstall, only on purge+install)
    – Lekensteyn
    Aug 31, 2011 at 9:21
  • Strange that it worked before my system upgrade then...
    – Jivings
    Aug 31, 2011 at 9:30
  • likely a feature change then. You can't expect every upgrade to respect old configuration settings. Some modifications would make sense for the majority but not for some others.
    – Lekensteyn
    Aug 31, 2011 at 9:34
  • Indeed. Thanks for helping me get to the bottom of it anyway, much appreciated :)
    – Jivings
    Aug 31, 2011 at 10:34
1

the php5.conf file in /etc/apache2/mods-enabled has a few lines at the bottom that keep php from executing inside of a user directory, so depending on your configuration, this could be your issue also. You can just comment these lines out and apache2 reload

You must log in to answer this question.

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