Download and Create Project
After installing, create a directory for project and initialize the directory.
1 2 3
Of course, we can follow the documentation to do
vagrant box add hashicorp/precise32 but let’s conclude it into our
Let’s create new provisioning script-
install.sh in our project root to install apache, PHP, mysql, XDebug, Composer etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Next, let’s edit the magic
1 2 3 4 5 6 7 8 9 10 11
This basically talks to Vagrant like this:
- Hey, install Ubuntu Server 12.04(32 bit) for me, you can find it at the link given
- I want to access my server via
- I want you to install something else. Please look at them at
install.sh(which created at first)
- Sync all the files to the /var/www so I can access them on my host machine(own desktop)
Boot into Virtual Machine
Yes, we can now
1 2 3
Once you’re in, try to play around by checking all the software installed.
1 2 3 4
You should be seeing something like It Works! if you browse
192.168.33.10 via your Chrome or Firefox. We’ll be able to see the index.php inside /var/www/html directory. Also, the directory
/vagrant in virtual machine is synced to
/var/www in host machine.
A more human like address
Next, instead of typing
192.168.33.10 to access our page, we can set it to a url like address. For instance,
dev.local. To do this, we need to configure 2 files. First, inside our virtual machine(after SSHed), let’s open up
1 2 3 4 5 6 7
Here we changed the server name to
dev.local. Also don’t forget to reload apache.
cmd+d to logout to our host machine and customize the
1 2 3 4 5
Try to go to
dev.local/ in your browser. You should see Apache2 default page.
The default document root is
/var/www/html, so to start using our LAMP server, we can delete the default
index.php inside the directory and create our own. Of course if you like you can alter your document root. For instance
So we had successful created our LAMP server on vagrant up. It might be a little bit painful at first but once you get comfortable with it, you can create your next project like a boss.
Shut down the VM
Also don’t forget to shut down your virtual machine when you’re done.
1 2 3
All of these 3 commands work to shut down a virtual machine with differenct speed. Of course the one take shorter time to shut down and boot up consumes more disk space and RAM.