The whole process was described in this article, but there are few quirks to fix in newer Ubuntu (namely 13.10 / Apache 2.4).
- Every config file in sites-available has to have a .config extension now, so instead of
sudo nano /etc/apache2/sites-available/project
use
sudo nano /etc/apache2/sites-available/project.config
if upgrading fist add the extension to the /etc/apache2/sites-available/project config file, then delete /etc/apache2/sites-enabled/project and re-run “sudo a2ensite project” / restart apache. - If your project root is located in your home directory you might get a persistent 403 / Forbidden error, that (weird as it is) has nothing to do with Linux permissions. To fix it add “Require all granted” directory directive. Here is how the new config file might look:
<VirtualHost *:80>
DocumentRoot /home/user/project
ServerName project.localhost
<Directory /home/user/project>
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
So here are updated instructions for Ubuntu 13.10+ (and maybe some older versions). Make sure to replace “project” below with the actual name of your project.
- Edit your /etc/hosts file with superuser privileges:
sudo nano /etc/hosts
We catch local requests to the new subdomain here, add following line (make sure your apache actually uses 127.0.0.1 and not say 127.0.1.1):
127.0.0.1 project.localhost
- Now configure the new website so that the server knows where to look for it, to do that create a new config file named after our project:
sudo nano /etc/apache2/sites-available/project.config
Here we set up the path to the project directory and few other options:<VirtualHost *:80>
DocumentRoot /home/user/project
ServerName project.localhost
<Directory /home/user/project>
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
See Apache Docs to get the idea what these directives mean. - Next use terminal to run the following:
sudo a2ensite project
a2ensite is a small utility that creates correct symlinks in sites-enabled to allow your newly configured subdomain to be served. - Last thing to do is to reload Apache so that it “picks up” the new config data:
sudo service apache2 reload
That’s it, now you can access your project under http://project.localhost/.
Hi bcat, Thanks for quick reference. This is what I was looking for.
From Japan
Hi Aadabu,
thanks for the feedback, regards from Germany to Japan!
Yuriy
What a great guide! Worked right away.. But I am having one problem. It works fine without www but as soon as I add http://www.subdomain.mydomain.com it no longer works. How do I make it function with www?
www would be another deeper subdomain, normally you can ignore it if it’s about a local project. If you want it, repeating the same process for the same folder should work
Hi, I done all the steps of your tutorial but when I type sudo a2ensite there is an error: ERROR: Site does not exist!
It seems to be unable to find the config in sites-available, try to add a .conf extension or change it to .conf