Created
July 23, 2018 09:55
-
-
Save aurmil/e346aec64c3f6b6ea17259f41e3b6ab0 to your computer and use it in GitHub Desktop.
Vagrant box based on Ubuntu 18.04 with Apache 2.4 + mod_rewrite ; PHP 7.2 + composer ; MariaDB 10 ; git, node, npm, bower, yarn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# author Aurélien Millet | |
# license MIT | |
# configuration | |
time_zone = "Europe/Paris" | |
Vagrant.configure("2") do |config| | |
config.vm.box = "generic/ubuntu1804" | |
config.vm.network "forwarded_port", guest: 80, host: 8080 | |
config.ssh.forward_agent = true | |
config.vm.synced_folder ".", "/vagrant", type: "virtualbox", | |
owner: "www-data", group: "www-data" | |
config.vm.provider "virtualbox" do |vb| | |
vb.name = "vagrant_ubuntu1804" | |
vb.memory = 1024 | |
vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000] | |
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] | |
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] | |
end | |
config.vm.provision "shell" do |s| | |
s.args = [time_zone] | |
s.inline = <<-SHELL | |
# configuration | |
TIME_ZONE=$1 | |
# disable queries for user manual interactions | |
export DEBIAN_FRONTEND=noninteractive | |
# update time zone | |
timedatectl set-timezone "$TIME_ZONE" | |
# update packages | |
apt-get update -q | |
# install Vim and Git | |
apt-get install -q -y vim git | |
# install Apache, PHP and MySQL | |
apt-get install -q -y apache2 | |
apt-get install -q -y php7.2 libapache2-mod-php7.2 | |
apt-get install -q -y php7.2-curl php7.2-gd php7.2-mbstring php7.2-mysql php7.2-xml php7.2-zip php7.2-bz2 php7.2-intl | |
apt-get install -q -y mariadb-server mariadb-client | |
a2enmod rewrite headers | |
systemctl restart apache2 | |
# set Vagrant folder as Apache root folder and go to it | |
dir='/vagrant/www' | |
if [ ! -d "$dir" ]; then | |
mkdir "$dir" | |
fi | |
if [ ! -L /var/www/html ]; then | |
rm -rf /var/www/html | |
ln -fs "$dir" /var/www/html | |
fi | |
cd "$dir" | |
# vhost | |
file='/etc/apache2/sites-available/dev.conf' | |
if [ ! -f "$file" ]; then | |
SITE_CONF=$(cat <<EOF | |
<Directory /var/www/html> | |
AllowOverride All | |
Options +Indexes -MultiViews +FollowSymLinks | |
AddDefaultCharset utf-8 | |
SetEnv ENVIRONMENT "development" | |
php_flag display_errors On | |
EnableSendfile Off | |
</Directory> | |
EOF | |
) | |
echo "$SITE_CONF" > "$file" | |
fi | |
a2ensite dev | |
systemctl reload apache2 | |
# Composer | |
EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)" | |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" | |
ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")" | |
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]; then | |
>&2 echo 'ERROR: Invalid installer signature (Composer)' | |
rm composer-setup.php | |
else | |
php composer-setup.php --quiet | |
rm composer-setup.php | |
mv composer.phar /usr/local/bin/composer | |
chmod +x /usr/local/bin/composer | |
sudo -H -u vagrant bash -c 'composer global require hirak/prestissimo' | |
fi | |
# phpinfo script | |
file='phpinfo.php' | |
if [ ! -f "$file" ]; then | |
echo '<?php phpinfo();' > "$file" | |
fi | |
# OPcache gui script | |
file='opcache.php' | |
if [ ! -f "$file" ]; then | |
wget -nv -O "$file" https://raw.githubusercontent.com/amnuts/opcache-gui/master/index.php | |
fi | |
# Adminer script | |
file='adminer.php' | |
if [ ! -f "$file" ]; then | |
wget -nv -O "$file" http://www.adminer.org/latest.php | |
wget -nv https://raw.githubusercontent.com/vrana/adminer/master/designs/pepa-linha/adminer.css | |
fi | |
# node, npm, bower, yarn | |
apt-get install curl | |
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - | |
apt-get install -y nodejs | |
npm install -g bower | |
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - | |
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list | |
sudo apt-get update && sudo apt-get install yarn | |
SHELL | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment