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 (7 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

php

Somebody is writing a compiler for PHP, compiles down to machine code, outperforms HHVM

Yes, that’s right. Recki-CT compiles PHP down to machine code. It’s unbelievable what’s going on in the PHP world in

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

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

ubuntu-14-04-lts lamp

How to install/setup a basic LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 12.04 or Debian 7.0/7.1

This little tutorial shows how to setup Apache, MySQL and PHP on a Linux server, in this case Ubuntu 12.04

Support FLARUM, the future of PHP forum scripts (with some dollars on Kickstarter)

PHP forum scripts are horrible, let’s face it. Nearly everything that’s available is hard to install, hard to handle, hard

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. This article was written quite a while ago (8 years), please

composer

Composer problems ? Try full reset !

Some small Composer commands that might solve your problems: I’ve taken them directly from Jordi Boggiano‘s (Composer co-creator) “In Depth

Create a fast, perfect and bootable 1:1 Windows backup (full clone of HDD) for SSD migration

In this article I want to share a super-simple, extremely fast and totally free workflow with you that will create

PHPMyAdmin not found after installation ? Here’s a fix (Ubuntu 12.04) !

You just installed PHPMyAdmin but http://www.yourdomain.com/phpmyadmin just says “phpmyadmin not found” ? Try to create a link in /var/www like

hiphop php

HipHop VM reaches 100% green Unit Tests in Laravel, Drupal, Slim, CodeIgniter etc.

In September 2013 the PHP HipHop VM dev team wrote a very interesting article [1] about failing Unit Tests of

1/4

Categories

Search

frontend-workflow
[german] Modernes Frontend-Development mit Bower, Grunt, Yeoman (45min Video, Thorsten Rinne auf der IPC2013)
forbes 30 under 30
Need motivation ? Check out these 2 awesome “FORBES 30 under 30” lists (web, UI, games)
php
How to install latest PHP 5.4.x on Ubuntu 12.04 LTS (Precise Pangolin)
DEF CON 18 – When your computer got stolen and you can still SSH into it: “Pwned by the 0wner” (22min conference talk)
[Link] Interesting: Designing a Nuclear Waste Warning Symbol That Will Still Make Sense in 10,000 Years
shadow dom
A quick video introduction into Shadow-DOM, the game-changing DOM-subtree-technology
Test GZIP compression of your server easily
Hacked french TV channel exposed passwords in TV interview (video, screenshots, links)
gamescom 2014 trailers
GAMESCOM 2014: Awesome Next-Gen ingame graphics
mod-rewrite-ubuntu-14-04-lts
EOL lists of Ubuntu, Debian and CentOS for your server plannings
angular js
Learn AngularJS in 20 (or 90) minutes with Dan Wahlin
JavaScript ECMAScript6 – A short video introduction (5min)
php
PHP 5.6 announced, statically typed (!) “new” PHP announced by Facebook devs
Beautiful, minimal WordPress theme ZUKI by Elmastudio (with 30% discount)
php
Postmodern PHP: appserver.io, a multithreaded application server for PHP, written in PHP

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 All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
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