403 Error Trying to Access File on Apache Server

apache-2.4http-status-code-403

I have an Ubuntu 14.04 server at http://images.example.com with this in /etc/apache2/sites-enabled/richblockspoorblocks.com.conf:

<VirtualHost *:80>
        ServerAdmin admin@example.com
        ServerName example.com
        ServerAlias images.example.com
        Header set Access-Control-Allow-Origin "*"
        DocumentRoot /home/username/var/www/example.com/public_html
        ErrorLog /home/username/var/www/example.com/logs/error.log
        CustomLog /home/username/var/www/example.com/logs/access.log combined
</VirtualHost>

I have a file /home/username/var/www/example.com/public_html/test.txt.

But when I navigate my browser to http://images.example.com/test.txt, I get a 403 forbidden error.

Forbidden
You don't have permission to access /test.txt on this server.

Apache/2.4.7 (Ubuntu) Server at images.example.com Port 80

Here's what I see when I run ls -la while in ~/:

drwxrwxr-x 3 www-data username 4096 May 20 21:32 var

error.log only has a client denied by server configuration message.

I've already run apache2 restart.

What must I change to see test.txt in my browser?

Best Answer

You seem to be placing your website files and DocumentRoot in a /home/user sub-directory:

    DocumentRoot /home/username/var/www/example.com/public_html

Usually, Apache works in /var/www, you might have a mistake nesting like that in your user's home directory. If you upload and point the DocumentRoot somewhere else than the default location (/var/www/), you might need to fix the owner/group/others and their permissions, so the user or group (www-data) for apache can read them.

Is there any reason to be using your user's home for the webserver DocumentRoot?

If you really want it there, you might try to change the group, to allow apache to read it:

I don't recommend this, unless you know what you are doing

chgrp -R www-data /home/username/var/www/example.com/public_html

That should probably make it work. Although you might also have to change some permissions, depending how you copied/uploaded the files to that directory.

ps. Again, unless there is some really good reason for that directory structure, I would go for the default /var/www.