Durning the last couple of months I’ve played around quite a bit with Vagrant. I’m sure that you’ve heard about Vagrant and understood that it’s some new, cool thing that everybody should use.
You may also have read that MAMP is bad and Vagrant is good, and now you’ve came across a little guide on how to replace MAMP with Vagrant.
I’ll be using the excellent Vaprobash script to the Vagrant server up and running.
- Create a new directory somewhere on your computer. That will correspond to what previously been your
- Download Vaprobash using the terminal.
curl -L http://bit.ly/vaprobash > Vagrantfile
- Open the Vagrantfile and uncomment the lines where Apache and MySQL are getting installed. At the time of this writing, it’s line 125 and 140.
vagrant upand wait for everything to get downloaded and installed. (This might take a while).
Okey, so now you have the virtual machine up and running. Success!
Remember how you used to browse to
http://localhost:8888/project1 when using MAMP? Now when you are using Vagrant, the URL to your projects are
First things first. Working with virtual hosts is very easy with MAMP Pro. It’s not quite as fast and easy to set up vhosts with Vagrant, but it’s not that terrible either.
With that said, here’s how you create a vhost called
- Login to the server:
- Add the name of the vhost and the path:
sudo vhost -s project1.dev -d /vagrant/project1
- Exit out of the server:
- Edit the host file using Vim or your editor of choise:
sudo vim /etc/hosts
- Add the following line:
- Save the file and browse to
Now let’s connect to MySQL using Sequel Pro. At the connection screen, select the SSH tab and use these credentials:
- MySQL Host:
- SSH Host:
- SSH User:
- SSH Key: `~/.vagrant.d/insecure_private_key`` (Click on the key icon and browse to that directory)
Now you should be able to connect to the MySQL database inside the Vagrant server.
This was a very quick and simple guide on how to get started with Vagrant. There’s of course a lot more to learn about the subject, but I leave that research for you to do.
The good thing about Vagrant is that you can fairly easy set up a local environment that is more or less the same as the production, which of course is something good. It can also be used to make sure that you the team you’re a part of have exactly the same environment.
However, I still think that it’s completely fine to continue using MAMP. It will still do the trick in most projects and Vagrant might be overkill. But when the day comes when you have to deal with a production server using Nginx instead of Apache, give Vagrant a shot.