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

zend framework 3

First view on Zend Framework 3 by Matthew O’Phinney

Interesting stuff: One of the very first video impressions of Zend Framework 3, and it sounds fantastic! This is even

increase-your-pagespeed-score

Increase your PageSpeed score (10min video with Matt Gaunt)

Compact and clever information for dramatic speed increases. Definitly worth watching. This article was written quite a while ago (9

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. This article was written

How major web companies (and banks) handle passwords quite wrong

There’s a very interesting “movement” in password handling going on for a long time, the basic idea is to encourage

set up a local virtual machine for development with vagrant and puphpet / puppet (and ubuntu, linux, php, apache, mysql)

A super-simple pre-configured Vagrant box with HipHop, Hack and Hack code examples

Another game-changing project: Victor Berchet‘s HHVM Vagrant box is a simple Ubuntu 12.04 LTS Vagrant-box that comes with preinstalled HHVM/HipHop

php

PHP 5.7 gets refactored core, is 10%-30% faster than PHP 5.5! Wow!

What an announcement! The awesome PHP core guys have refactored the Zend Engine (which drives PHP) and could successfully speed

cheap cloud server php

DigitalOcean rolls out interesting feature: Transfering server snapshots directly to the client’s account

Today DigitalOcean has rolled out a quite interesting new feature: You are now able to transfer a server snapshot (which

php

How to install/setup latest version of PHP 5.5 on Debian Wheezy 7.0/7.1/7.2 (and how to fix the GPG key error)

Please note: This works fine. But this package will also upgrade your apache to version 2.4 which has different config

vagrant

How to setup a (or multiple) server/LAMP-stack inside a virtual machine for local development with Vagrant and PuPHPet

You know this: You need a new server, something to develop on, something to test on, something to put your

hearthbleed-ssl-bug

A quick guideline on how to fix the Hearthbleed bug (and update OpenSSL) on Ubuntu

If you still haven’t fixed your servers after mainstream discovery of the legendary Hearthbleed bug, then do it now –

1/4

Categories

Search

php
12 tools for better PHP quality
java
Interesting: code of the same application in PHP, Python, Ruby, Closure, node.js, Java and Go
Google I/O 2014 – HTTPS Everywhere (video)
php-phalcon-logo
Which PHP-framework to learn in 2014 ? PHALCON, by far the fastest ever!
Install Laravel 4 on Ubuntu 12.04 LTS (a how-to tutorial)
phpstorm-github-code-color-syntax-theme
Get Github’s code colors in PHPStorm (2014 style)
hack-php
The first micro framework written in Hack is there: hack-mvc !
The New Era of JavaScript (28min conference talk, Jack Franklin, 2013)
phpstorm 7.0 php
A perfect video tutorial to get started with xdebug in PHPStorm
php
How to install latest PHP 5.4.x on Ubuntu 12.04 LTS (Precise Pangolin)
php mvc
Preview-release of (my) “php-mvc” project (a simple php mvc barebone)
hack-php
Wow! Facebook devs have rewritten and fixed PHP, releasing it as new language called “Hack” today
Test GZIP compression of your server easily
PHPMyAdmin not found after installation ? Here’s a fix (Ubuntu 12.04) !
october cms
October CMS, built on top of Laravel, is beautiful, clever and on the way to be the new #1 CMS

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