Create Scotch Box 3.5 with Ubuntu 16.04 and PHP 7 (free version)

Scotch Box

Here are the commands to create a new Scotch Box 3.5 with Ubuntu 16.04 and PHP 7, which is the free version.

git clone https://github.com/scotch-io/scotch-box NEW-scotchbox;
cd NEW-scotchbox;
# activate NFS, increase CPU and RAM
# add SSH forwarding, to allow using host SSH keys, start vagrant
sed -i.tmp 's/ config.vm.synced_folder/##config.vm.synced_folder/' Vagrantfile;
sed -i.tmp 's/#config/config/' Vagrantfile;
sed -i.tmp 's/end/    config.ssh.forward_agent = true\n    config.vm.provider "virtualbox" do |v|\n        v.memory = 8192\n        v.cpus = 4\n    end\n\nend/' Vagrantfile;
vagrant up --debug;
vagrant ssh;

# set the timezone
sudo timedatectl set-timezone Europe/Copenhagen

# update .bashrc with better history and longer history, insert in ~/.bashrc:
echo "
# Bind up/down arrow to history search
bind '\"\e[A\":history-search-backward'
bind '\"\e[B\":history-search-forward'
# Settings for history function
export HISTFILESIZE=50000
export HISTSIZE=50000
export HISTCONTROL=ignoreboth:erasedups
export HISTIGNORE='&:e:c:l:ca:cd:cd -'
# ls aliases
alias la='ls -hal'
alias l='ls -hl'
" >> ~/.bashrc
source ~/.bashrc;

# install Drush 8 for use with Drupal 7 (Drupal 8 includes Drush 9)
# see latest release from https://github.com/drush-ops/drush/releases
wget https://github.com/drush-ops/drush/releases/download/8.1.17/drush.phar;
php drush.phar core-status;
chmod +x drush.phar;
sudo mv drush.phar /usr/local/bin/drush;
drush init -y;
drush st;

# test Drush 8 with Drupal 7 (Drupal 8 includes Drush 9)
drush dl drupal-7 --destination=/var/www/public --drupal-project-rename=d7.local -y;
cd /var/www/public/d7.local;
drush site-install --db-url=mysql://root:root@localhost/d7 --account-name=admin --account-pass=content -y;
drush pm-disable overlay toolbar update -y; # d7
drush pmu overlay toolbar update -y;
drush dl admin_toolbar -y && drush en admin_toolbar_tools -y; #d8
drush dl admin_menu -y && drush en admin_menu admin_menu_toolbar -y; #d7
drush dl devel && drush en devel devel_generate -y && drush generate-content 20;

# add base_url to settings.php, make it writable first, and create one-time log link
sudo chmod 775 sites/default/settings.php
echo "\$base_url = 'http://d7.local';  // NO trailing slash!" >> sites/default/settings.php
drush uli
# Drupal 8 has no base_url
drush uli --uri=http://d8.local

# URL: http://192.168.33.10/d7.local
# add "192.168.33.10 d7.local" (without quotation) to /etc/hosts file on host machine (not vagrant)

# add d7.local to virtualhost
sudo -i
echo "
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/public/d7.local
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ServerName d7.local
          <Directory "/var/www/public/d7.local">
              Options Indexes FollowSymLinks
              AllowOverride all
              Require all granted
          </Directory>
</VirtualHost>
" >> /etc/apache2/sites-available/000-default.conf
systemctl restart apache2.service
exit

# test SSH forwarding works
# ignore or Pass 'Yes' when The authenticity of host can't be established in Expect Shell script during Automation
# add: "-o StrictHostKeyChecking=no"
# https://stackoverflow.com/questions/28461713/
ssh -T git@github.com -o StrictHostKeyChecking=no; # test if it works with Github
ssh -T git@gitlab.com -o StrictHostKeyChecking=no; # test if it works with Gitlab
# success message is "Hi your_username! You've successfully authenticated.