Setup LAMP Stack with RHEL/CentOS or Debian/Ubuntu using Ansible as provisioner on Vagrant
- Make sure your machine supports Virtualization
- VirtualBox installed - get it from https://www.virtualbox.org/wiki/Downloads
- Vagrant installed - get it from http://www.vagrantup.com/downloads.html
Vagrant uses ansible local provisioning so it should work fine on Windows and Linux where no ansible is installed on the host machine.
These are a few of the distros that works out of the box. Other versions under the RHEL/Debian family should work with minimal changes to the configurations.
- Ubuntu 14.04 (Trusty)
- Centos 6.8
You can change the type of distribution you want by updating the config.vm.box
part of the Vagrantfile
.
config.vm.box = 'geerlingguy/centos6'
See ansible-role-apache for more info on Apache.
You can update the VirtualHost's servername
and alias
by editing vars/main.yml
apache_vhosts:
- servername: "local.dev"
serveralias: "local.dev"
documentroot: "/var/www/vagrant/html"
See ansible-role-mysql for more info on MySQL.
Below are some of the variables specific to MySQL
# vars/main.yml
mysql_root_password: root
mysql_databases:
- name: sample_db
encoding: latin1
collation: latin1_general_ci
mysql_users:
- name: vagrant
host: "%"
password: vagrant
priv: "sample_db.*:ALL"
mysql_enabled_on_startup: yes
See ansible-role-php for more info on PHP.
Below are some of the variables specific to PHP
# vars/main.yml
php_enablerepo: "epel"
php_opcache_enable: "0"
php_enable_apc: false
# vars/RedHat.yml
php_packages:
- php56w
- php56w-cli
- php56w-common
- php56w-dom
- php56w-gd
- php56w-mysql
# vars/Debian.yml
php_packages:
- libapache2-mod-php5.6
- php5.6
- php5.6-cli
- php5.6-common
- php5.6-dom
- php5.6-gd
- php5.6-mysql
The folder html
is where you should place your PHP project. It is mapped to /var/www/vagrant/html
directory of the VM and is being used by a VirtualHost with a servername local.dev
.
In order for your project to be accessible, you need to edit your hosts file and add the following:
127.0.0.1 local.dev
For Windows host machine, you can edit your hosts file by doing the ff:
- Run cmd as administrator
- Search for cmd in start menu > right click > run as administrator
- Once in cmd, enter the ff:
notepad drivers\etc\hosts
- Add the lines above and save
For Linux host machine, you can edit your hosts file by doing the ff:
- Launch terminal
- Once in terminal, enter the ff:
sudo vi /etc/hosts
- Add the lines above and save
Once you've updated your hosts file, you can now access your project at http://local.dev:8080
- ansible-role-repo-epel - Installs EPEL repo
- ansible-role-mysql - Installs MySQL database server
- ansible-role-apache - Installs Apache server
- ansible-role-php - Installs PHP and some of its common modules
- ansible-role-ppa-ondrej - Installs ondrej/php ppa for Debian/Ubuntu
- ansible-role-repo-webtatic - Installs the Webtatic repository on RHEL/CentOS
- config-repos - Install repos based on distribution
MIT