Skip to content

Instantly share code, notes, and snippets.

@fideloper
Created June 27, 2016 16:24
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save fideloper/6095f6a8b0a8ea960d8446a6539c582c to your computer and use it in GitHub Desktop.
Save fideloper/6095f6a8b0a8ea960d8446a6539c582c to your computer and use it in GitHub Desktop.
Provision ubuntu 16.04 vagrant machine
#!/usr/bin/env bash
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get -y upgrade
# Get "add-apt-repository" Command
sudo apt-get install -y software-properties-common
# Repositories for latest PHP, Nginx, Redis
sudo add-apt-repository -y ppa:ondrej/php
sudo add-apt-repository -y ppa:nginx/stable
sudo apt-add-repository -y ppa:chris-lea/redis-server
# Repository for latest MySQL
# http://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/#repo-qg-apt-repo-manual-setup
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5
echo "deb http://repo.mysql.com/apt/ubuntu/ xenial mysql-5.7" | sudo tee /etc/apt/sources.list.d/mysql.list
# Update after adding repositories
sudo apt-get update
# Install Basics: Utilities and some Python dev tools
sudo apt-get install -y build-essential git vim tmux curl wget unzip pigz \
python-pip python-dev supervisor
# Install Nginx & PHP
sudo apt-get install -y nginx \
php7.0-fpm php7.0-cli php-mcrypt php-curl php-gd \
php-sqlite3 php-mysql php-pgsql php-imap php-memcached \
php-mbstring php-xml php7.0-intl
# Install Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
printf "\nPATH=\"$(sudo su - vagrant -c 'composer config -g home 2>/dev/null')/vendor/bin:\$PATH\"\n" | tee -a /home/vagrant/.profile
# Some dev PHP settings
# php cli
sudo sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/7.0/cli/php.ini
sudo sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.0/cli/php.ini
sudo sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.0/cli/php.ini
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.0/cli/php.ini
# php fpm
sudo sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 100M/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/post_max_size = .*/post_max_size = 100M/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.0/fpm/php.ini
# Add user "vagrant" to group www-data
sudo usermod -a -G www-data vagrant
# Install MySQL non-interactively
debconf-set-selections <<< "mysql-community-server mysql-community-server/data-dir select ''"
debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass password root"
debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass password root"
sudo apt-get install -y mysql-server
# Set Timezone (Server/MySQL)
sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime
sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql --user=root --password=root mysql
# Install cache software
sudo apt-get install -y redis-server memcached beanstalkd
# Add 1GB swap for memory overflow
sudo fallocate -l 1024M /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
printf "vm.swappiness=10\nvm.vfs_cache_pressure=50" | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
# Allow caching of NFS file share
sudo apt-get install -y cachefilesd
echo "RUN=yes" | sudo tee /etc/default/cachefilesd
@peterrehm
Copy link

Why are you prefering the mysql repo over the ubuntu repo? More recent releases?

@fideloper
Copy link
Author

Yep! Exactly for that reason. In particular, before the .13 release, there was a memory "bug" that caused high RAM usage on lower RAM servers (1-2 gb size VPSes, popular on DO/Linode)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment