Categories
Computers

php5 and apache2 and public_html directories

I finally got around to setting up WordPress on my home server for purposes of tinkering. I decided to install the blog in the public_html directory in my home. The apache2 webserver was already installed and I knew that browsing to the public_html folder worked just fine.

But when I tried to access the WordPress install page, all the browser wanted to do was download it as a text file.

Hmmm.

So I stuck a php file with phpinfo() in the public_html folder and tried to access it. Same result.

OK. So I check for a few things using aptitude and checking the enabled modules in the apache2 setup directory and it looks like everything should work. So I decide to stick the phpinfo() code into a file under /var/www since that’s the document root.

VOILA! The PHP info page pops into view. So, for some reason, PHP is disabled for public_html folders on my machine (a debian/testing installation). Some quick googling turned up the culprit. It was 5 lines in the php5.conf file under the apache2/mods-available directory:

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

As can be seen, there’s even a handy little explanation! After commenting them out and running /etc/init.d/apache2 restart I was finally able to install WordPress on my home machine. Kinda blew the whole “5 minute install” thing though.