Setting Up A Local Development URL with Apache
Running a local development environment can be confusing at the best of times. Multiple projects all competing for attention can make the process of organising your projects quickly bog down your productivity. In this post, I show you how to streamline your productivity by creating local domain addresses for your projects.
We are going to be creating a URL that is mapped to your projects public folder and will allow you to make calls to http://mysite.dev.
Modify Your Local Host Mapping
Much like you have to setup the correct DNS routing for your production website, mapping your server to your domain name, we need to do the same thing on our local machine.
Open terminal and type the following:sudo vim /etc/hosts
In the text file that opens add the following:127.0.0.1 mysite.dev
This line is telling your local system that the domain name mysite.com should be routed to 127.0.0.1, which is your local host address.
Configure Apache
We have our routing all sorted now, but we now need to ensure the correct files are served. We need to modify our apache server configuration.
I’m currently using MAMP as my apache server, but the basic principles are the same no matter how you are running apache.
Open up terminal and type the following:sudo vim /Applications/MAMP/conf/apache/httpd.conf
Scroll to the bottom of the text file that will have now opened in terminal and add the following:<VirtualHost *:80>
DocumentRoot "/your/project/public"
ServerName mysite.dev
</VirtualHost>
That’s it! Restart your apache server and vist mysite.dev. You should now see your projects home page being served from /your/project/public
.