Skip to content

Repoint global DocumentRoot, still run PHP

An answer to this question on Stack Overflow.

Question

I have a server which is serving up a web page for a project.

The project is stored in a user directory on the server. (/home/user/theproject/webstuff).

Originally, I was using the userdir module to make this accessible via http://theserver/user and a symbolic link from /home/user/public_html to /home/user/theproject/webstuff to indicate the location of the files.

But, ultimately, it would be better to serve the files from http://theserver without having to indicate the user (since there really is only one user).

And then I had a truly brilliant idea.

Instead, I would rewrite my /etc/apache2/sites-enabled/000-default.conf file to read:

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /home/user/theproject/webstuff
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Now everything is lovely and good... except that PHP doesn't run any more.

Instead, the following error is raised:

AH01630: client denied by server configuration: /home/user/theproject/webstuff/script.php

To the client, this appears as a 403 Forbidden error.

So this is something of a dual question:

  1. Is there a better way to achieve my goal?
  2. How can I enable PHP in this situation?

Answer

As it turns out, I had to edit /etc/apache2/apache2.conf.

On Line 164 there is a block which I had to modify as follows:

#<Directory /var/www>
<Directory /home/user/theproject/webstuff>
  Options Indexes FollowSymLinks
  AllowOverride None
  Require all granted
</Directory>