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
nginx php 5.5

[Link] Set up Nginx with PHP 5.5 easily

As there are surprisingly no good tutorials on how to set up NGINX with PHP 5.5 properly, here’s an excellent

java vs php

Switching from Java to PHP. Seriously. A very interesting and pre-judice-free talk with Ph.D. Aris Zakinthinos

Ph.D. Aris Zakinthinos, CTO of achievers.com, a well-scalability-experienced guy and former IT employee of the military, has just delivered one

phpstorm-github-code-color-syntax-theme

Get Github’s code colors in PHPStorm (2014 style)

I really love the colors on GitHub’s code previews but couldn’t find any themes that copy that in a beautiful

hiphop php

Vote for “Hack” for HipHop/HHMV support (future style PHP) in PHPStorm 8

“Hack” will come. And “Hack” will change PHP, definitly. In case you never heard of it, have a look into

php

PHP 5.6 announced, statically typed (!) “new” PHP announced by Facebook devs

PHP 5.6 goes alpha PHP 5.6 has been announced for a while now, and these days things get serious (code-freeze,

New project: Building a naked PHP skeleton / boilerplate application from scratch

[This post is from November 2013. In the meantime (I’m writing this in November 2014) the project has changed its

GitHub finally introduces repo traffic stats

It has been a veeeery long time, but finally GitHub has introduced private traffic stats for all projects. To open

Stressed and unrelaxed while coding ? Try some ultra-deeply-relaxing ASMR audio clips. It will change your life. Seriously.

Do you remember your first professional massage – and that weird, extremely soft and relaxing feeling you had, this strange

js javascript

[video] Netflix JavaScript Talks about ECMAScript 7: The Evolution of JavaScript

phpstorm-8

A PHPStorm shortcuts cheat sheet (for Windows, Mac OS and Linux)

Shortcuts that will make you life so much easier! Please note: Frontend Devs might be irritated by the weird CTRL-Y-shortcut,

1/4

Categories

Search

How to install/setup latest version of PHPMyAdmin on Ubuntu 12.04 LTS (Precise Pangolin)
Bézier Curves – Under the Hood (4min video)
css4
Angelina Fabbro talks about “CSS4” in this excellent conference video
atomic-design
An introduction into Atomic Design, a super-clean way to style web applications
Disappointed by Watch Dogs’s graphics ? See how it looks with unlocked, hidden settings. Awesome!
php
How to prevent PHP sessions being shared between different apache vhosts / different applications
How to show the available version of a package (before doing apt-get install)
composer
A short & simple Composer tutorial
ilovepreloaders – A tumblr collection of preloader animations
nginx php 5.5
[Link] Set up Nginx with PHP 5.5 easily
php
How to install PHP curl extension (in 5 seconds)
hiphop php
HipHop VM reaches 100% green Unit Tests in Laravel, Drupal, Slim, CodeIgniter etc.
[Link] Making a website vertically responsive
phpstorm-github-code-color-syntax-theme
Get Github’s code colors in PHPStorm (2014 style)
vagrant
A super-simple Vagrant LAMP stack bootstrap (installable with one command)

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