How To Set Up Apache Virtual Hosts on Debian

  • Posted March 29, 2014

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Sorry, the text for the virtualhost file didn’t render properly in my answer. <br> <br>I’ve uploaded a text file for you to use here: <br> <br>

You just need to define each virtual host in its own file.
<br> <br>Try this. <br> <br>Running as root, or using sudo, type: <br> <br>cd /etc/apache2/sites-available <br>nano yourdomainname.conf <br> <br>Then copy into the blank text file that opens: <br> <br><VirtualHost *:80> <br> ServerName <br> ServerAlias <br> <br> <br> DirectoryIndex index.php <br> DocumentRoot /var/www/yourdomainname <br></VirtualHost> <br> <br>You should obviously change “yourdomainname” to whatever your details are. <br> <br>Also change the /var/www/yourdomainname to wherever you’ve stored the files for the site.
<br> <br>And finally, swap index.php to whatever your index document is (or leave it as it is if you actually have an index.php). <br> <br>Then press ctrl+o to save the file. <br> <br>Press ctrl+x to exit nano. <br> <br>After this, at the command prompt, type: <br> <br>a2ensite yourdomainname.conf <br>service apache2 restart <br> <br>If you want to disable the virtual host in the future, type: <br> <br>a2dissite yourdomainname.conf <br>service apache2 restart <br> <br>Peter