Skip to content

Instantly share code, notes, and snippets.

@huyb1991
Created September 30, 2016 02:44
Show Gist options
  • Save huyb1991/2cc5b6e94d5db93df0d17f16d5b96876 to your computer and use it in GitHub Desktop.
Save huyb1991/2cc5b6e94d5db93df0d17f16d5b96876 to your computer and use it in GitHub Desktop.
A simple Vagrantfile and provision.sh file to setup a LAMP stack for ubuntu/trusty64 box.
#!/usr/bin/env bash
# Variables
DBPASSWORD='admin123'
PROJECT_PATH='/sample-project'
sudo apt-get update
# 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 $DBPASSWORD"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $DBPASSWORD"
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 $DBPASSWORD"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/admin-pass password $DBPASSWORD"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/app-pass password $DBPASSWORD"
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 "${PROJECT_PATH}"
<Directory "${PROJECT_PATH}">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EOF
)
echo "${VHOST}" > /etc/apache2/sites-available/000-default.conf
# enable mod_rewrite
sudo a2enmod rewrite
sudo php5enmod mcrypt
# restart apache
service apache2 restart
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
config.vm.synced_folder "./", "/var/www/html", id: "vagrant-root",
owner: "vagrant",
group: "www-data",
mount_options: ["dmode=775,fmode=664"]
config.vm.provision "shell", path: "provision.sh"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment