Create a virtual host in mamp

Running virtual host on your desktop will be a great help to boost up your development alot.
I have been doing almost all of my projects now days, I am using MAMP on mac (sorry for window users), if you do not have MAMP go ahead, download and install.

Why virtual Host?

Virtual host give you ability to host its own domain such as “myproject.dev”, by entering this on your browser will project out your project.

Install MAMP

Download MAMP
Once installed, start MAMP application and start servers which will turn 2 red buttons on the left to green

mamp server

When you start the application, you will notice that it automatic opens up the browser which is using :8888 port, something like this: localhost:8888/MAMP…
first change the port to default port by clicking preference->Ports-> click on the “Set to default Apache and MySQL ports”. This will turn your Apache port to 80.
Click ok

Setup up virtual Host?

Now is time to setup your virtual host, asume that you have a project you want to call “myproject”, by the way all project files are to be inside the MAMP http folder, which is in /Applications/MAMP/htdocs or you can change to somewhere using MAMP, prefereces->Apache->Change the Document Root.

Open up [cc lang=”php”] /Applications/MAMP/conf/apache/httpd.conf

in your favorite text-editor. Scroll down to last line. Copy and paste my code below.

*Before doing that, make a backup of the httpd.conf file.

[cc lang=”php”]
NameVirtualHost *


DocumentRoot “/Applications/MAMP/htdocs/myproject”
ServerName myproject.dev

AllowOverride All

Save and close it.

Open up terminal from /Applications/Utilities or click Command+space type in “terminal”.
Enter this command to bring out the host file.
[cc lang=”php”]sudo nano /etc/hosts

 

go to last line and enter the ip address and domain name you wish to use for development which I am using myproject.dev
[cc lang=”php”] 127.0.0.1 myproject.dev

Once done, press Control+o and click enter then press control+x to exit.
Switch to your MAMP application and click Stop Server and Start server again, thats all!