Configure Apache to Serve PHP Pages from a User Directory.

The following is adapted from Adil Mukarram's Blog.


Step 1: Edit the PHP configuration file

sudo gedit /etc/apache2/mods-enabled/php5.conf

Find this section of the config file:

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

Comment out all lines of code in the above section, so that it looks like this.

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

Step 2: Save changes, and exit emacs

control-x, control-s

Step 3: Restart Apache, and you are done

sudo /etc/init.d/apache2 restart