How To Set Up Apache Virtual Hosts on Debian

March 29, 2014 1.4k views
2 Answers
You just need to define each virtual host in its own file.

Try this.

Running as root, or using sudo, type:

cd /etc/apache2/sites-available
nano yourdomainname.conf

Then copy into the blank text file that opens:


DirectoryIndex index.php
DocumentRoot /var/www/yourdomainname

You should obviously change "yourdomainname" to whatever your details are.

Also change the /var/www/yourdomainname to wherever you've stored the files for the site.

And finally, swap index.php to whatever your index document is (or leave it as it is if you actually have an index.php).

Then press ctrl+o to save the file.

Press ctrl+x to exit nano.

After this, at the command prompt, type:

a2ensite yourdomainname.conf
service apache2 restart

If you want to disable the virtual host in the future, type:

a2dissite yourdomainname.conf
service apache2 restart

Sorry, the text for the virtualhost file didn't render properly in my answer.

I've uploaded a text file for you to use here:
Have another answer? Share your knowledge.