A turn-key LAMP development stack, based on Centos 6, PHP5.6, MySQL 5.6.
You will need to install these local dependencies before you can use Vagrant:
- git https://git-scm.com/downloads
- virtualbox https://www.virtualbox.org/wiki/Downloads
- vagrant https://www.vagrantup.com/downloads.html
- vagrant-vbguest plugin: https://github.com/dotless-de/vagrant-vbguest
-
Create a directory to host your VMs:
mkdir -p ~/code/vagrants/centos6
-
'cd' to that directory:
cd ~/code/vagrants/centos6
-
Clone this repo into that directory.
There are two directories within the checked-out code:
./vagrant
./workspace
./vagrant
contains all the files necessary to run the Vagrant VM../workspace
provides a directory in which to store your working files, which is file-shared to the Vagrant VM - so you can access your working files from both your OS and the Vagrant VM../workspace
is also used by the Vagrant VM to serve projects via http://localhost:8080
-
'cd' to the ./vagrant directory
cd ./vagrant
-
Start the VM:
vagrant up
On first boot, Vagrant may take anywhere up to 10 mins to install required dependencies.
"Patient you must be, young Jedi.".
-
'cd' to the ./vagrant directory
cd ./vagrant
-
Stop the VM:
vagrant suspend
-
'cd' to the ./vagrant directory:
cd ./vagrant
-
Resume the VM:
vagrant resume
-
'cd' to the ./vagrant directory:
cd ./vagrant
-
Check the status:
vagrant status
SSH connections to the VM are pretty simple and straightforward:
-
In the
./vagrant
directory, type:vagrant ssh
SSH key pairs are provisioned for you, by Vagrant, when the VM boots, so you will not have to provide any login credentials when you connect. You will automatically login as the 'vagrant' user, and will be free to sudo
or sudo su -
once inside.
By default, Apache will serve everything inside the ./workspace
(/workspace
inside the VM) directory as one site. This is convenient for anyone with little or no knowledge of configuring Apache, or if time is particularly tight - you could simply have one Vagrant VM per project, and keep things super simple.
However, if your project requires custom configuration, or if you'd prefer to run multiple projects within one VM (recommended if you're having to switch between projects often), you will most likely prefer the 'Advanced' usage (see below).
###Advanced usage (shared/multiple host/s) To set up your own custom virtual hosts, and/or host multiple sites from the same VM, follow this example to get started:
-
SSH to the Vagrant VM (see above).
-
sudo mkdir -p /workspace/hello/_logs
-
echo "<?php print '<h1>Hello world</h1>';" > /workspace/hello/index.php
-
sudo nano /etc/httpd/conf.d/hello.conf
-
Add the following content:
<VirtualHost *:80> ServerName hello.localhost DocumentRoot "/workspace/hello" ErrorLog /workspace/hello/_logs/error.log CustomLog /workspace/hello/_logs/access.log combined <Directory "/workspace/hello"> DirectoryIndex index.php </Directory> </VirtualHost>
-
Press CTRL+x to quit Nano (hit Y when prompted to save changes).
-
Reconfigure Apache to support Name-based Virtual Hosts:
sudo cp /vagrant/modules/apache/confs/shared.conf /etc/httpd/conf/httpd.conf
-
Restart Apache:
sudo service httpd restart
-
Visit the following URL in your browser: http://hello.localhost:8080
For more info on Apache virtual host configuration options, visit: https://httpd.apache.org/docs/current/vhosts/name-based.html
phpMyAdmin comes pre-installed with passwordless entry (only for use in development environments where non-sensitive or mock data is used).
With the VM running, visit: http://localhost:8080/phpMyAdmin
At the login screen, simply login as the root user. Leave the password field blank.