Logo
  • PHP
    • HipHop / HHVM
    • Modern PHP
    • PHPStorm
    • LAMP
    • Laravel
    • Composer
    • PDO
  • JavaScript
    • node.js
    • AngularJS
  • CSS
    • SASS
    • “CSS4” (CSS level 4)
  • HTML
  • Git
  • LAMP
  • Vagrant
  • UI / UX
  • Architecture of …
  • Off-Topic
With ♥ from Berlin
December 2, 2014
Chris
LAMP, Linux, Local Development, PHP, PHPStorm, Server, Ubuntu, Vagrant, Virtual Machine / VM
Comments Off on A super-simple Vagrant LAMP stack bootstrap (installable with one command)

A super-simple Vagrant LAMP stack bootstrap (installable with one command)

PreviousNext
vagrant

As I have to setup servers inside Vagrant quite often, sometimes 10 times per day, I started to use provisioning: Using a list of commands that will be executed automatically when Vagrant sets up a new box. This saves a shitload of time. To do so, I’m using a reduced-to the max Vagrantfile that

  • sets up a Ubuntu 14.04 LTS “Trustry Thar” 64bit box
  • makes the box accessable by the host at IP 192.168.33.22
  • syncs the current folder with /var/www/html inside the box (permanently, in both directions)
  • automatically perform all the commands in bootstrap.sh directly after setting up the box for the first time

and a bootstrap.sh that holds your chosen password and your chosen project folder name and does this:

  • update, upgrade
  • create the project folder inside /var/www/html
  • install Apache 2.4, PHP 5.5, MySQL, PHPMyAdmin, git and Composer
  • sets the pre-chosen password for MySQL and PHPMyAdmin
  • activates mod_rewrite and add AllowOverride All to the vhost settings

 

The files

The Vagrantfile looks like this:

# -*- 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.33.22"

  # 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

and the bootstrap.sh that looks like this

#!/usr/bin/env bash

# Use single quotes instead of double quotes to make it work with special-character passwords
PASSWORD='12345678'
PROJECTFOLDER='myproject'

# 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

 

Installation

To use this, simply get both files here in the repo, put them inside a folder and do a

vagrant up

Make sure you already have the ubuntu/trusty64 box loaded, if not, do

vagrant box add ubuntu/trusty64

Voila, 5mins later you’ll have a fully installed box, syncing with your local folder.

boxgitUbuntuvagrant
Share this

Bézier Curves – Under the Hood (4min video)

Take a peek under the hood to see how computers draw cubic Bézier curves, as used in design and motion

phpstorm-8

Killer-feature in PHPStorm: Search everywhere

A short but massive productivity improvement: The new “search everywhere” feature in PHPStorm 7.1+! Simply double-tap the SHIFT key and

What’s new in PHPStorm 10 (Official promo video)

PHPStorm 10 is out! New features are mainly full PHP7 support, much better auto-recognation / autocompletion (even within arrays (unsure

O’Reilly’s Programming JavaScript Applications by Eric Elliott for free (Early Access release)

O’Reilly currently offers the entire book Programming JavaScript Applications by Eric Elliott for free (as an online-readable version) while its

php uk conference

PHP Caching Best Practices by Eli White (video from PHP UK Conference 2014)

The title says it all: PHP Caching best practices.

laracon-2014-eu-amsterdam

Laracon 2013 – Jordi Boggiano: In Depth Composer (47min video)

More videos of 2013’s and 2014’s Laracon events from US and EU on their Youtube channel.

Perfect HTML email templates for perfect HTML emails (outlook!) with INK

The people behind FOUNDATION, the excellent responsive frontend framework, have just released a set of highly professional, perfectly compatible HTML

Interesting stats on SONY’s hacked passwords

In 2011 SONY’s Playstation network got hacked, 77 million accounts have been compromised, and more than 1.000.000 passwords – saved

Redesigning Windows 8 – fantastic and clever drafts by Jay Machalani

The interface of Windows 8 has been the topic of heated discussions for a long time now, and everybody who’s

mod-rewrite-ubuntu-14-04-lts

EOL lists of Ubuntu, Debian and CentOS for your server plannings

Chosing the right server operating system will probably save your life and avoid a lot of stress with your clients.

1/4

Categories

Search

composer
How to install Composer on Windows 7 / 8 or Ubuntu
DEF CON 18 – When your computer got stolen and you can still SSH into it: “Pwned by the 0wner” (22min conference talk)
mod-rewrite-ubuntu-14-04-lts
Which server OS version to choose ? Some EOL lists of Debian, Ubuntu and CentOS
php
How the PHP session garbage collector really works
composer
A short & simple Composer tutorial
php
How to install PHP curl extension (in 5 seconds)
Frontend Ops Conf 2014 – Keynote by Alex Sexton: “Front End Operations”
Serious hard-to-fix bug in OAuth and OpenID discovered, lots of major sites affected
php ide
Sitepoint asks for your favourite PHP IDE – take part!
Install MINI in 30 seconds inside Ubuntu 14.04 LTS
Hacked french TV channel exposed passwords in TV interview (video, screenshots, links)
vagrant
A preinstalled Vagrant box with PHP HipHop / HHVM and Ubuntu 13.10 (Saucy Salamander)
js javascript
Push database changes to all clients in real-time (!) with AngularJS and Firebase
-45% (or even 50%) off on DesignWall today
Create a fast, perfect and bootable 1:1 Windows backup (full clone of HDD) for SSD migration

Tags

apache bash centos composer conference coupon CSS debian fonts framework git GitHub hack HHVM HipHop HTML HTML5 IDE JavaScript JS LAMP laravel linux mod_rewrite MVC MySQL Nginx optimization PHP PHP 5.5 PHP 5.6 phpmyadmin PHPStorm security server SSD Ubuntu UI UX vagrant video virtual machine voucher VPS wordpress
Side-Project: Wordle-Solver:
www.wordle-helper.info

Pages

  • Privacy Policy