When it comes to developing WordPress sites, having a local server or Virtual Host on your computer/laptop emulates the environment similar to the web host’s server is essential in any sort of development including WordPress. You must be able to test it locally before launching live with real data. There are many development environments that each individual prefers, for me, it is MAMP due to its easy-to-follow configurations files in setting up a Virtual Host. Having used this method in the past I have provided the steps for both on Mac and Windows users.
- Go to the MAMP application folder and find the
Applications > MAMP > conf > apache > httpd.conf
C:/ > MAMP > conf > apache > httpd.conf
- Open the file in your favourite text editor and search for this line:
# Virtual hosts #Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
# Virtual hosts #Include conf/extra/httpd-vhosts.conf
- Uncomment the second line by removing the hash
# Virtual hosts Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
# Virtual hosts Include conf/extra/httpd-vhosts.conf
- In the same file look for:
<Directory /> Options Indexes FollowSymLinks AllowOverride None </Directory>
<Directory /> Options Indexes FollowSymLinks AllowOverride All </Directory>
- In the MAMP application folder find the
Applications > MAMP > conf > apache > extra > httpd-vhosts.conf
C:/ > MAMP > conf > apache > extra > httpd-vhosts.conf
- Place this code at the end of this file:
<VirtualHost *:80> ServerName example.test DocumentRoot "/path/to/project/directory/site" </VirtualHost>
Change the document root to point to wherever your project is located.
Note – Chrome no longer allows
.devdomain ending for local websites so consider using
- Now to set up the network with the hosts file so that you can configure the IP address that you resolved the given domain name to. This allows your computer to recognise your local domain. Open up your terminal window and type:
sudo nano /etc/hosts
After being prompted for your administration password a screen will show up looking something like this:
Add your desired hostname mapping at the bottom by using the keyboard arrow keys to navigate and hitting
ctrl + oto save, enter to confirm and lastly
ctrl + xto exit.
Open Notepad as Administrator and from the Notepad application open the file:
At the bottom of the file, type the name of your virtual host.
- Flush your DNS cache to ensure the mapping works by entering this in the terminal window:
sudo killall -HUP mDNSResponder
- Finally, the last step of setting up Virtual Hosts involves tweaking MAMPs settings:
To remove the :8888 from the end of the URL go back into the
httpd.conffile and find:
Listen 8888 ServerName localhost:8888
Then change it to:
Listen 80 ServerName localhost:80
Restart your servers and try
http://example.testin your browser.