Configurable LAMP development stack for Vagrant.
-
Install vagrant from vagrantup.com
-
Download and Install VirtualBox from virtualbox.org
-
Clone this repository to a folder of your choice (I have it in my home folder)
-
Add this row to your local machine's "hosts" file (Linux/Mac: "/etc/hosts")
33.33.33.10 vagrant.dev
-
Go to the repository folder and launch the box
$ cd [repo]
$ vagrant up
- Wait for vagrant to download, start and provision your virtual machine (a few minutes)
- When the setup is done you can visit your local development host at http://vagrant.dev/
- Any files you add to the folder sites/vagrant.dev/ will be visible at http://vagrant.dev/
- Now you can configure your own sites, see the onfiguration section below.
Installed software:
- Apache
- MySQL
- php
- phpMyAdmin
- Xdebug with Webgrind
- zsh with oh-my-zsh
- git, subversion
- mc, vim, screen, tmux, curl
- MailCatcher
The vagrant machine is set to use IP 33.33.33.10 by default.
Webgrind and phpMyAdmin are available on every domain. For example:
PHP is configured to send mail via MailCatcher. Web frontend of MailCatcher is running on port 1080 and also available on every domain:
Port 33066 is forwarded to MySql, with a default vagrant/vagrant user so you can use your favorite client to administer databases.
You can add XDEBUG_PROFILE to your GET parameter to generate an xdebug trace, e.g. http://vagrant.dev/?XDEBUG\_PROFILE. You can then investigate at http://local.dev/webgrind/
Site configurations are stored as json files in the folder databags/sites/
. These configs automatically set up apache virtual hosts and databases. They can also import databases and rsync uploaded files from a remote server. See examples below.
Whenever you need to apply new configurations all you need to do is run the provisioning again.
$ vagrant provision
Put your code for the site in the "sites" folder, within a folder named as the "host" in your config.
Also remember to add your new site hosts to your local machine's hosts file.
33.33.33.10 vagrant.dev project.dev project2.dev
Put your web app in the folder sites/local.dev/
for this site configuration to work.
{
"id": "local",
"host": "local.dev",
"aliases": [ "example.dev", "foo.dev" ]
}
Put your web app in the folder sites/database.dev/
for this site configuration to work.
{
"id": "database",
"host": "database.dev",
"database": [{
"db_name": "my_db",
"db_user": "my_db",
"db_pass": "my_db",
}]
}
Put your web app in the folder sites/import.dev/
. You also need a database dump named sites/import.dev/import.sql
for this config to work.
{
"id": "import",
"host": "import.dev",
"database": [{
"db_name": "my_import",
"db_user": "my_import",
"db_pass": "my_import",
"db_import_file": "import.sql"
}]
}
For this config to work you need an SSH account on a remote server and a MySQL account. For the SSH account you must have Public Key Authentication set up and your private key file needs to exist in the root vagrant directory. All settings under "db_copy" are required.
I use a single private key file without a passphrase for all the servers I need to sync databases and files from. This is a separate private key from the one I usually use, since it has no passphrase it is best to use it only for syncing from development and testing servers. Read more about public and private keys at help.ubuntu.com.
In this config I also use the "webroot" to define that apache should use sites/copy.dev/webroot/
as the DocumentRoot. By default sites/copy.dev/
would be used.
The "framework" is also set, this triggers some extra features, see "Supported frameworks" below.
{
"id": "copy",
"host": "copy.dev",
"webroot": "webroot",
"framework": "magento",
"database": [{
"db_name": "my_copy",
"db_user": "my_copy",
"db_pass": "my_copy",
"db_copy": {
"ssh_host": "sync.example.com",
"ssh_user": "vagrant",
"ssh_private_key": "vagrant_id_rsa",
"mysql_user": "root",
"mysql_pass": "password",
"remote_database": "my_copy"
}
}]
}
The provisioning script has support for some automated setup of frameworks and CMS.
- Clears cache on startup/provision (deletes all files in /var/cache).
- Creates a cron file for running Magento cron (/etc/cron.d/magento).
- After a database sync, it sets the base_url to site host.
- Clears cache on startup/provision using drush.
- After a database sync, it sets the home and siteurl to site host.