Ubuntu – Apache virtual hosts not working (error 403)

Apache2virtualhost

I have installed apache2, php and mysql server to my ubuntu 14.04 and was tested and everything is working as expected.

I have application created using codeigniter & was past developed on mac osx, so I create the following in order to run it on my ubuntu:

create new site configuration file inside sites-available named payroll-v1.conf like below:

<VirtualHost *:80>
ServerName  payroll.v1
DocumentRoot /home/ahmed-saber/workspace/payroll-v1/

<Directory /home/ahmed-saber/workspace/payroll-v1/>
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory> 

</VirtualHost>

adding the line below to etc/hosts

127.0.0.1   payroll.v1

although my application not working and always output 403 forbidden even if i trying to access any static html page for test

Best Answer

The 403 error means that your pages are inaccessible for Apache.

Setting chmod -R 755 as you did, made it accessible for everybody on your system - every user, program, daemon etc. Furthermore, you have made all files executable this way (see this or this for mor info on permissions and executables on Linux).


More secure, yet simple solution, will be adding yourself to Apache's group (in Ubuntu its www-data) and then changing your Apache workspace to this group:

sudo adduser ahmed-saber www-data
sudo chown .www-data /home/ahmed-saber/workspace/
chmod 750 /home/ahmed-saber/workspace/

For more secure approach you could use Access Control List, which might be a little more complicated.

In situations like this, you can always check Apache's error log (/var/log/apache2/error.log). If you are developing web pages you can keep one terminal window opened with "live view" of logs (error.log or access.log or whatever), like this:

tail -f /var/log/apache2/error.log