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
17

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.

This article was written quite a while ago (8 years), please keep this in mind when using the information written here. Links, code and commands might be outdated or broken.

Random articles

  • [Link] How to set up HipHop, Nginx and Laravel in Ubuntu 12.04 LTS (in a Vagrant box)[Link] How to set up HipHop, Nginx and Laravel in Ubuntu 12.04 LTS (in a Vagrant box)
  • Generate Vagrant boxes with Laravel, HipHop, Nginx, WordPress, MySQL, MariaDB, MongoDB, RabbitMQ etc. with one clickGenerate Vagrant boxes with Laravel, HipHop, Nginx, WordPress, MySQL, MariaDB, MongoDB, RabbitMQ etc. with one click
  • A list of downloadable Vagrant boxes (CentOS 5.9 / 6.4, Ubuntu 12 / 13, Debian 6 / 7 / 7.1 / 7.2)A list of downloadable Vagrant boxes (CentOS 5.9 / 6.4, Ubuntu 12 / 13, Debian 6 / 7 / 7.1 / 7.2)
  • How to setup a local server (in a virtual machine) with Vagrant in PHPStormHow to setup a local server (in a virtual machine) with Vagrant in PHPStorm
  • How to setup a (or multiple) server/LAMP-stack inside a virtual machine for local development with Vagrant and PuPHPetHow to setup a (or multiple) server/LAMP-stack inside a virtual machine for local development with Vagrant and PuPHPet
  • EOL lists of Ubuntu, Debian and CentOS for your server planningsEOL lists of Ubuntu, Debian and CentOS for your server plannings
  • You made a mess with Git ? Here’s a flowchart guideline on how to fixYou made a mess with Git ? Here’s a flowchart guideline on how to fix
  • GitHub introduces revert button / rollback for merged pull requestsGitHub introduces revert button / rollback for merged pull requests
  • GitHub rolls out .PSD diff and viewingGitHub rolls out .PSD diff and viewing
boxgitUbuntuvagrant
Share this

17 Comments

  • Luís Felipe de Andrade
    June 19, 2016 9:11 pm

    Thank you! I was looking for this to create a simple (and old) environment! Work it at first

    Reply
  • Carlos Bravo
    April 2, 2016 7:46 pm

    Thank you! This is everything a lamp developer needs. It’s almost sexy to have everything up with just “vagrant up”

    Reply
  • Martin Pultz
    December 31, 2015 3:22 am

    This is great and quite a bit simpler than what I’ve been looking at and trying to understand. If we wanted to use PHP 5.4 would it take much more than

    $ sudo apt-get install python-software-properties
    $ sudo add-apt-repository ppa:ondrej/php5-oldstable
    $ sudo apt-get update
    $ sudo apt-get install -y php5

    Not sure what to do for Apache, but I’m trying to mimic our production server that is a LAMP with Apache 2.2, MySQL, MyPhpAdmin, and PHP 5.4.

    Reply
    • Martin
      June 20, 2016 4:40 pm

      Did you ever figure this one out?

      Reply
  • hereNT
    November 19, 2015 9:33 pm

    This is awesome. Thank you so much. I went through a whole lot of different ‘systems’ for creating vagrant boxes, and none of them were simple enough to really understand what was going on.

    I kind of took it and ran, making a bit more robust version that uses a simple yaml file. It will also automatically check out a sub repo to the web root. That way someone can use the same exact repo for the vagrant machine while keeping the actual working files unique to that one website.

    Question – do you have a license for this? Thinking of releasing mine on github under the MIT license, not sure if you would mind that… I put a link to this site and your repo in a ‘credits’ section of the readme.

    Reply
    • Chris
      November 21, 2015 2:49 pm

      Hey, thanks too! I’ve gone the exact same way, everything was too complicated and totally messy, so I’ve built this one. Feel free to do whatever you want with the code, it’s totally free! As it’s so simply I think it doesn’t even need a licence, you know…

      Reply
    • Martin Pultz
      December 31, 2015 3:10 am

      Can you drop a link to your Git repo to see your example?

      Reply
      • hereNT
        December 31, 2015 3:25 am

        It’s still not totally done, I have some local changes like adding a shared “databases” folder, trying to figure out how I (at one point) was able to get it to pause partway through and give you the github ssh key so the repo can check out private repos during the first provision.

        Windows kind of borked my local machine with a recent update, though, so I haven’t been able to do much with fresh / blank boxes. I can use ssh user@existing.box.ip, but not vagrant ssh boxnumber. Which means I can’t reprovision.

        Anyway, here’s what I have up online so far. I’d really appreciate help cleaning it up and extending it.

        https://github.com/herent/vagrant-bootstraps-php

        Reply
  • Ajeet Varm
    November 4, 2015 9:22 am

    Great job and Thanks a lot ..

    Reply
  • Federico González Brizzio
    July 17, 2015 8:46 pm

    Great! Thank you it’s simple & perfect

    Reply
  • Kresimir Pendic
    June 17, 2015 8:56 am

    Thanks @devmetal:disqus great script!

    Reply
  • Nicole L
    June 4, 2015 5:47 am

    Do you have one with php5.6?

    Reply
  • Omid Hezaveh
    April 19, 2015 5:08 pm

    It works like a charm!
    Thanks for the well written instructions.

    Reply
  • empyrvm
    December 2, 2014 11:33 am

    Does it work with any php applications like prestashop or symfony ?
    Can I use docker instead of virtualbox in my netbook ?

    Thanks for this very easy tutorial.

    Reply
    • Chris
      December 2, 2014 12:11 pm

      He, this just install the tools described and prepares mod_rewrite, so it has nothing to do with the scripts you want to use. It depends, so follow the install tutorials of the script you want to use. Regarding Docker, hmm, i cannot say this, no idea to be honest.

      Reply

Leave A Comment Cancel reply

git-php-deployment

Extremely simple deployment with PHPloy

Let me ask you a question: How mad do you get when you have to remember which files you edited

Install MINI in 30 seconds inside Ubuntu 14.04 LTS

This is a guideline on how to install MINI – an extremely simple naked PHP application – more or less

MINI2, an extremely simple barebone PHP application on top of Slim

For my daily work I often needed to setup super-simple PHP applications, just some more or less static pages plus

php

How to setup / install PHP 5.6 on Ubuntu 14.04 LTS

Ubuntu 14.04 LTS ships with PHP 5.5 by default, but if you want to use PHP 5.6, then it’s just

php

How to use the PHP 5.5 password hashing functions

PHP 5.5 introduced some very interesting password hashing functions that will make your life much much easier, the web much

Serious hard-to-fix bug in OAuth and OpenID discovered, lots of major sites affected

Just a short notice rather than a real article, full story later (I need to check the facts): Several sources

Adobe releases Firebug-like developer tools to edit and extract PSDs

A big step in frontend-development: According to this presentation on Adobe Max 2014 Adobe has just released a very interesting

hack-php

Wow! Facebook devs have rewritten and fixed PHP, releasing it as new language called “Hack” today

Exciting stuff is happening: Some years ago Facebook has released an early preview of HipHop, a virtual machine that precompiles

logo-internet-explorer

How to professionally test on old Internet Explorer versions

If you have (or want) to test your websites and applications on older versions of Internet Explorer, then there’s a

Frontend Ops Conf 2014 – Paul Irish: Delivering The Goods In Under 1000ms (40min video)

This article was written quite a while ago (9 years), please keep this in mind when using the information written

1/4

Categories

Search

ubuntu-14.04-lts
First view: Ubuntu 14.04 LTS brings PHP 5.5 and Apache 2.4
php uk conference
Profiling PHP Applications by Bastian Hofmann (video from PHP UK Conference 2014)
digitalocean coupon
Free $10 coupon for DigitalOcean SSD cloud VPS hosting
bitdeli git github stats
Get visitor stats for your GitHub repo with BitDeli
Berlin, prepare for TOA conference (15th – 17th of July)
js javascript
[video] Netflix JavaScript Talks about ECMAScript 7: The Evolution of JavaScript
MINI2, an extremely simple barebone PHP application on top of Slim
symfony-framework-logo
SensioLabs, creator of Symfony and Silex PHP frameworks, gets $7 million capital
js javascript
Push database changes to all clients in real-time (!) with AngularJS and Firebase
sass laravel
SASSmeister is a real-time JSfiddle for SASS / CSS. Awesome!
hiphop php
Vote for “Hack” for HipHop/HHMV support (future style PHP) in PHPStorm 8
Quick fix for 404 error in WordPress category / tag page
php
“Belt” adds very clever everyday functions to PHP, comes with JavaScript naming styles and eventually solves the needle/haystack problem
atomic-design
An introduction into Atomic Design, a super-clean way to style web applications
O’Reilly’s Learning JavaScript Design Patterns by Addy Osmani for free

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
 
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT