Project: Create a LAMP stack bootstrap and Provision a VM using Vagrant
1) Make Directory
$ mkdir ubuntu-trusty-lamp
$ cd ubuntu-trusty-lamp/
2) Create Vagrant file
Do it when you're in ubuntu-trusty-lamp folder. Name the file as Vagrantfile.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ubuntu/trusty64"
# Create a private network, which allows host-only access to the machine using a specific IP.
config.vm.network "private_network", ip: "192.168.56.10"
# Share an additional folder to the guest VM. The first argument is the path on the host to the actual folder.
# The second argument is the path on the guest to mount the folder.
config.vm.synced_folder ".", "/var/www/html"
# Define the bootstrap file: A (shell) script that runs after first setup of your box (= provisioning)
config.vm.provision :shell, path: "bootstrap.sh"
end
3) Create bootstrap.sh like
# Use single quotes instead of double quotes to make it work with special-character passwords
PASSWORD='lamp1234'
PROJECTFOLDER='myvagrantproject'
# create project folder
sudo mkdir "/var/www/html/${PROJECTFOLDER}"
# update / upgrade
sudo apt-get update
sudo apt-get -y upgrade
# install apache 2.5 and php 5.5
sudo apt-get install -y apache2
sudo apt-get install -y php5
# install mysql and give password to installer
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $PASSWORD"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $PASSWORD"
sudo apt-get -y install mysql-server
sudo apt-get install php5-mysql
# install phpmyadmin and give password(s) to installer
# for simplicity I'm using the same password for mysql and phpmyadmin
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean true"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/app-password-confirm password $PASSWORD"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/admin-pass password $PASSWORD"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/app-pass password $PASSWORD"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2"
sudo apt-get -y install phpmyadmin
# setup hosts file
VHOST=$(cat <<EOF
<VirtualHost *:80>
DocumentRoot "/var/www/html/${PROJECTFOLDER}"
<Directory "/var/www/html/${PROJECTFOLDER}">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EOF
)
echo "${VHOST}" > /etc/apache2/sites-available/000-default.conf
# enable mod_rewrite
sudo a2enmod rewrite
# restart apache
service apache2 restart
# install git
sudo apt-get -y install git
# install Composer
curl -s https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
4) Installation
cd ubuntu-trusty-lamp/
vagrant up
Make sure you already have the ubuntu/trusty64 box loaded, if not, do
vagrant box add ubuntu/trusty64
Post a Comment
Post a Comment