Setting up a virtual host

Alex Bennett 21 May 2018

This is a selfish tutorial, I keep having to check online every time I come to do this just to remind myself what it is I’m doing. The process is more or less the same depending on using XAMPP or MAMP and due to the vast number of sites I work on a year giving them all a unique virtual hostname is an essential but forgettable part of web development.

Windows

  • Open XAMPP control panel and ensure Apache is not running.
  • Navigate to ‘C:/xampp/apache/config/extra’
  • Open ‘httpd-vhosts.conf’ in a text editor
  • Uncomment ‘# NameVirtualHost *:80’
  • Include the following code for each virtualhost you want to setup (change example to your site)

<VirtualHost example.local:80> ServerAdmin admin@localhost.com DocumentRoot “C:/xampp/htdocs/example” ServerName example.local ServerAlias example.local <Directory “C:/xampp/htdocs/example”> Order allow,deny Allow from all </Directory> </VirtualHost>

  • Navigate to ‘C:/Windows/System32/drivers/etc/hosts` and open your host file with notepad, ensure you are running notepad as administrator
  • Uncomment # 127.0.0.1 localhost
  • Add your virtual hostname on a new line # 127.0.0.1 example.local
  • Restart Apache and navigate to your new virtual host

That should be it, all set up on windows with a new virtual host for your local development needs.

Contact

If you have an interesting opportunity or a project in need of a developer, please get in touch: