Lately I have been doing a lot of php development, and I am using Ubuntu Linux for it.
One of my biggest pains was/is setting up an alias or virtual host for the new project (yes, I am coming from the lazy windows world).
After a few tries and a lot of help from Robert Basic I put together this post to remind me next time I get a bad case of stupid.
So… First things first, I will assume that you have an Ubuntu setup with Apache web server installed, and that you are using gedit.
Fire up the terminal and type:
If you did not get any error messages and your return looks like below, you are on the right track.
Next thing to do is to go to sites-available directory by typing
OK, now we are in apaches directory where all the definition files for virtual hosts are. We want to copy the default template one, cryptically named default
This will create a copy of the default template named our-test-site (you of course should substitute this with anything you wish). Let’s edit it, type
This will open up the file in the editor, below are the contents of default vhost file (as usual YMMV if you did some customization)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
We need to add one line and edit two lines.
Add ServerName our-test-site.local just above the DocumentRoot directive (in front of line 4).
Edit DocumentRoot /var/www path on line 4 and set it to /path-to-the-test-site-WITHOUT-trailing-slash. It should look something like this
In case you did not notice my subtle hints, there should NOT be a trailing slash at the end of the path.
Edit path on line 9 and set it to /path-to-the-test-site-WITH-trailing-slash/. It should look something like this
In case you did not notice my subtle hints, there SHOULD be a trailing slash at the end of the path.
And there you have it, almost done, the virtual host file is setup. Enable it by typing
The response should look like this
At this point the virtual host setup is done, all that is left is to tell the server that our-test-site.local should be resloved to 127.0.0.1. We do that by typing
and adding 127.0.0.1 our-test-site.local after the localhost (line 1).
The entire hosts file should look like
1 2 3 4 5 6 7 8 9 10 11
Save it, close the editor and finally type
So there you go, your virtual host is setup, open the browser and type http://our-test-site.local and enjoy.
Update: In case you encounter problems accessing the content of the localhost, you should add the ServerName localhost into your default virtual host (as described above for the new virtual host). Then disable and enable site, and restart the apache
1 2 3
Update 2: In your new virtual host file you should change your
for your first two directory nodes (the / one and the one with the path to your site). That will allow all the .htaccess files to work properly and allow redirection.
And of course do not forget to
1 2 3