Did you ever wonder if there was a other way to organise your web projects than creating subfolders in your normal htdocs folder and using the with http://localhost/project1, you’ve come to the right place.
In this post I’ll show you how you can create dynamic virtual hosts without restarting Apache or adding anything to the Apache VirtualHost configuration.
So let’s get started:
If you’ve followed the previous tutorial you should already have a working lamp setup. However if you don’t it’s really easy to set it up:
sudo apt-get install lamp-server^
When the installation is finished you should be asked for a password for the root mysql server. After you’ve specified your password you should be able to open http://localhost/ in you browser and see the “It Works!” message. (On Ubuntu 14.04 it’s a quiet longer page with the title “Apache2 Ubuntu Default Page”)
First we have to configure Apache to use our user to run the web server, else we will run into permission problems.
To do this open the file /etc/apache2/env.conf and change the username and group to your username and primary group (This should be the same as your username).
After this it’s quite easy, as I’ve already created a script which does everything for you.
Just download the script from here and run it with root rights ‘sudo vhost.sh example.dev’. This will add my vhost config and add a new host named example.dev