This is something I found myself Googling every time I needed it. That was until I actually just sat down and thought about what it was I was doing when I needed to set up a new local virtual host. This really isn’t difficult at all, but there are some file paths that need remembering. These are:
- Hosts – /private/etc/hosts
- Httpd.conf – /Applications/MAMP/conf/apache/httpd.conf
Add your chosen domain to your hosts file. Open up Terminal and then type:
sudo nano -w /private/etc/hosts
Then add in the following to the bottom of this file (it doesn’t really matter if it’s at the bottom or not, but I generally add new ones to the bottom):
I like to use the “.dev” extension for any ‘local’ domains I set up.
Navigate over to the following location in Finder:
Now open up Httpd.conf in a text editor. You can do this in nano or vi, but I prefer to just use my favourite text editor (Sublime text!).
This is where tutorials on this can vary. You can either include a separate dedicated vhosts conf file into the main httpd.conf, OR you can just add your vhosts to the bottom of the httpd.conf file. It really doesn’t matter. From an organisational point of view then it’s probably better to have a separate of concerns and go with the vhosts.conf file (/extra/vhosts.conf). If you go this route then make sure you uncomment the vhosts line in your httpd.conf file.
Anyway, here’s what you need to do. Copy a paste this into the bottom of your httpd.conf file (or vhosts.conf file if that’s what you’d like to use):
<VirtualHost *:8888> ServerName mydomain.dev DocumentRoot /sites/mydomain/public_html/ Directory /sites/mydomain/public_html/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all /Directory> /VirtualHost>
Leave a comment
Was this helpful? Did I miss something? Do you have a question? Get in touch, or tell me below.