Last active
September 17, 2015 13:43
-
-
Save devster31/30e58cc73e10f6df2d9c to your computer and use it in GitHub Desktop.
Varying Vagrant Vagrants base provisioning
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
#!/bin/bash | |
export DEBIAN_FRONTEND=noninteractive | |
# Force Locale | |
echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale | |
locale-gen en_US.UTF-8 | |
# Install Some PPAs | |
echo '>>> Add Nginx development ppa' | |
apt-add-repository -y ppa:nginx/development 2>/dev/null | |
echo '>>> Add redis stable ppa' | |
apt-add-repository -y ppa:rwky/redis 2>/dev/null | |
echo '>>> Add ondrej/php stable ppa' | |
apt-add-repository -y ppa:ondrej/php5-5.6 2>/dev/null | |
# curl --silent --location https://deb.nodesource.com/setup_4.x | sudo bash - | |
echo '>>> Adding the NodeSource signing key to your keyring...' | |
if [ -x /usr/bin/curl ]; then | |
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - | |
else | |
wget -qO- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - | |
fi | |
echo '>>> Creating apt sources list file for the NodeSource Node.js 4.x repo...' | |
echo 'deb https://deb.nodesource.com/node_4.x trusty main' > /etc/apt/sources.list.d/nodesource.list | |
echo 'deb-src https://deb.nodesource.com/node_4.x trusty main' >> /etc/apt/sources.list.d/nodesource.list | |
echo 'OK' | |
apt-get update | |
# Update System Packages | |
apt-get -q -y upgrade | |
# PACKAGE INSTALLATION | |
# Build a bash array to pass all of the packages we want to install to a single | |
# apt-get command. This avoids doing all the leg work each time a package is | |
# set to install. It also allows us to easily comment out or add single | |
# packages. We set the array as empty to begin with so that we can append | |
# individual packages to it as required. | |
apt_package_install_list=() | |
# Start with a bash array containing all packages we want to install in the | |
# virtual machine. We'll then loop through each of these and check individual | |
# status before adding them to the apt_package_install_list array. | |
apt_package_check_list=( | |
# PHP5 | |
# | |
# Our base packages for php5. As long as php5-fpm and php5-cli are | |
# installed, there is no need to install the general php5 package, which | |
# can sometimes install apache as a requirement. | |
php5-fpm | |
php5-cli | |
# Common and dev packages for php | |
php5-common | |
php5-dev | |
# Extra PHP modules that we find useful | |
php5-memcached | |
php5-imagick | |
php5-xdebug | |
php5-mcrypt | |
php5-mysql | |
php5-intl | |
php5-imap | |
php5-curl | |
php5-gmp | |
php-pear | |
php5-gd | |
# nginx is installed as the default web server | |
nginx | |
# memcached is made available for object caching | |
memcached | |
# mysql is the default database | |
mysql-server-5.6 | |
# other packages that come in handy | |
imagemagick | |
subversion | |
git | |
zip | |
unzip | |
ngrep | |
curl | |
make | |
vim | |
colordiff | |
whois | |
re2c | |
supervisor | |
unattended-upgrades | |
software-properties-common | |
curl | |
postfix | |
# ntp service to keep clock current | |
ntp | |
# Req'd for i18n tools | |
gettext | |
# Req'd for Webgrind | |
graphviz | |
# Allows conversion of DOS style line endings to something we'll have less | |
# trouble with in Linux. | |
dos2unix | |
# nodejs for use by grunt | |
g++ | |
nodejs | |
# Mailcatcher requirement | |
libsqlite3-dev | |
) | |
echo ">>> Check for apt packages to install..." | |
# Loop through each of our packages that should be installed on the system. If | |
# not yet installed, it should be added to the array of packages to install. | |
for pkg in "${apt_package_check_list[@]}"; do | |
package_version="$(dpkg -s $pkg 2>&1 | grep 'Version:' | cut -d " " -f 2)" | |
if [[ -n "${package_version}" ]]; then | |
space_count="$(expr 20 - "${#pkg}")" #11 | |
pack_space_count="$(expr 30 - "${#package_version}")" | |
real_space="$(expr ${space_count} + ${pack_space_count} + ${#package_version})" | |
printf " * $pkg %${real_space}.${#package_version}s ${package_version}\n" | |
else | |
echo " *" $pkg [not installed] | |
apt_package_install_list+=($pkg) | |
fi | |
done | |
# MySQL | |
# Use debconf-set-selections to specify the default password for the root MySQL | |
# account. This runs on every provision, even if MySQL has been installed. If | |
# MySQL is already installed, it will not affect anything. | |
debconf-set-selections <<< "mysql-server mysql-server/root_password password root" | |
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password root" | |
# Postfix | |
# Note that if your current Internet connection does not allow communication | |
# over port 25, you will not be able to send mail, even with postfix installed. | |
debconf-set-selections <<< "postfix postfix/main_mailer_type select Internet Site" | |
debconf-set-selections <<< "postfix postfix/mailname string vvv" | |
# Disable ipv6 as some ISPs/mail servers have problems with it | |
debconf-set-selections <<< "postfix postfix/protocols select ipv4" | |
if [[ ${#apt_package_install_list[@]} = 0 ]]; then | |
echo '>>> No apt packages to install.' | |
else | |
echo '>>> Installing apt-get packages...' | |
apt-get install -q -y ${apt_package_install_list[@]} | |
fi | |
# npm and npm-check-updates | |
npm install -g npm | |
npm install -g npm-check-updates | |
# ack-grep | |
# Install ack-rep directory from the version hosted at beyondgrep.com as the | |
# PPAs for Ubuntu Precise are not available yet. | |
if [[ -f /usr/bin/ack ]]; then | |
echo '>>> ack-grep already installed' | |
else | |
echo '>>> Installing ack-grep as ack' | |
curl -s http://beyondgrep.com/ack-2.04-single-file > /usr/bin/ack && chmod +x /usr/bin/ack | |
fi | |
# Composer | |
if [[ -z $COMPOSER_HOME ]]; then | |
echo 'COMPOSER_HOME=/usr/local/src/composer' >> /etc/profile | |
fi | |
# source /etc/profile | |
export COMPOSER_HOME=/usr/local/src/composer | |
if [[ -z "$(composer --version --no-ansi)" ]]; then | |
echo ">>> Installing Composer..." | |
curl -sS https://getcomposer.org/installer | php | |
chmod +x composer.phar | |
mv composer.phar /usr/local/bin/composer | |
fi | |
echo '>>> Updating Composer...' | |
composer self-update | |
if [[ -f /vagrant/provision/github.token ]]; then | |
ghtoken=`cat /vagrant/provision/github.token` | |
composer config --global github-oauth.github.com $ghtoken | |
echo '>>> Your personal GitHub token is set for Composer.' | |
fi | |
composer global require --no-progress phpunit/phpunit mockery/mockery d11wtq/boris psy/psysh | |
composer global config bin-dir /usr/local/bin | |
composer global update | |
# Grunt | |
npm config set spin false --global | |
if [[ "$(grunt --version)" ]]; then | |
echo '>>> Updating Grunt CLI...' | |
npm update -g -s grunt-cli | |
npm update -g -s grunt-sass | |
npm update -g -s grunt-cssjanus | |
npm update -g -s grunt-rtlcss | |
else | |
echo '>>> Installing Grunt CLI...' | |
npm install -g -s grunt-cli | |
npm install -g -s grunt-sass | |
npm install -g -s grunt-cssjanus | |
npm install -g -s grunt-rtlcss | |
fi | |
# Graphviz | |
# Set up a symlink between the Graphviz path defined in the default Webgrind | |
# config and actual path. | |
echo '>>> Adding graphviz symlink for Webgrind...' | |
ln -sf /usr/bin/dot /usr/local/bin/dot | |
# Mailcatcher | |
# Installs mailcatcher using RVM. RVM allows us to install the | |
# current version of ruby and all mailcatcher dependencies reliably. | |
echo '>>> Installing Ruby Version Manager and installing latest stable Ruby version...' | |
gpg -q --no-tty --batch --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 2>/dev/null | |
curl -sSL https://get.rvm.io | sudo bash -s stable --ruby --quiet-curl 2>/dev/null | |
source /etc/profile.d/rvm.sh | |
echo '>>> Installing Mailcatcher with RVM...' | |
$(which rvm) default@mailcatcher --create do gem install --no-rdoc --no-ri mailcatcher | |
$(which rvm) wrapper default@mailcatcher --no-prefix mailcatcher catchmail | |
# Add the vagrant user to the www-data group so that it has better access | |
# to PHP and Nginx related files. | |
echo '>>> Adding www-data and rvm group to vagrant user...' | |
usermod -a -G www-data vagrant | |
usermod -a -G rvm vagrant |
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
#!/bin/bash | |
# Create an SSL key and certificate for HTTPS support. | |
if [[ ! -e /etc/nginx/server.key ]]; then | |
echo '>>> Generate Nginx server private key...' | |
vvvgenrsa="$(openssl genrsa -out /etc/nginx/server.key 2048 2>&1)" | |
echo "$vvvgenrsa" | |
fi | |
if [[ ! -e /etc/nginx/server.crt ]]; then | |
echo '>>> Sign the certificate using the above private key...' | |
vvvsigncert="$(openssl req -new -x509 \ | |
-key /etc/nginx/server.key \ | |
-out /etc/nginx/server.crt \ | |
-days 3650 \ | |
-subj /CN=*.wordpress-develop.dev/CN=*.wordpress.dev/CN=*.vvv.dev/CN=*.wordpress-trunk.dev 2>&1)" | |
echo "$vvvsigncert" | |
fi | |
echo '>>> Setup configuration files...' | |
# Nginx Config | |
echo " * Copying /srv/config/nginx-config/nginx.conf to /etc/nginx/nginx.conf" | |
cp /srv/config/nginx-config/nginx.conf /etc/nginx/nginx.conf | |
echo " * Copying /srv/config/nginx-config/nginx-wp-common.conf to /etc/nginx/nginx-wp-common.conf" | |
cp /srv/config/nginx-config/nginx-wp-common.conf /etc/nginx/nginx-wp-common.conf | |
chmod 644 /etc/nginx/nginx-wp-common.conf | |
if [[ ! -d /etc/nginx/custom-sites ]]; then | |
mkdir /etc/nginx/custom-sites/ | |
fi | |
# PHP5 Config | |
sed -i 's|;listen.mode = 0660|listen.mode = 0666|' /etc/php5/fpm/pool.d/www.conf | |
sed -i 's|;pm.max_requests = 500|pm.max_requests = 100|' /etc/php5/fpm/pool.d/www.conf | |
sed -i 's|;catch_workers_output = yes|catch_workers_output = yes|' /etc/php5/fpm/pool.d/www.conf | |
sed -i 's|;env\[PATH\] = /usr/local/bin:/usr/bin:/bin|env[PATH] = /srv/www/phpcs/scripts/:/usr/local/bin:/usr/bin:/bin|' /etc/php5/fpm/pool.d/www.conf | |
sed -i "s/error_reporting = .*/error_reporting = E_ALL | E_STRICT/" /etc/php5/cli/php.ini | |
sed -i 's|display_errors = .*|display_errors = On|' /etc/php5/cli/php.ini | |
sed -i 's|memory_limit = .*|memory_limit = 512M|' /etc/php5/cli/php.ini | |
sed -i 's|;date.timezone.*|date.timezone = UTC|' /etc/php5/cli/php.ini | |
sed -i "s/error_reporting = .*/error_reporting = E_ALL | E_STRICT/" /etc/php5/fpm/php.ini | |
sed -i 's|;error_log = php_errors.log|error_log = /srv/log/php_errors.log|' /etc/php5/fpm/php.ini | |
sed -i 's|display_errors = .*|display_errors = On|' /etc/php5/fpm/php.ini | |
sed -i 's|;date.timezone.*|date.timezone = UTC|' /etc/php5/fpm/php.ini | |
sed -i 's|upload_max_filesize = .*|upload_max_filesize = 1024M|' /etc/php5/fpm/php.ini | |
sed -i 's|post_max_size = .*|post_max_size = 1024M|' /etc/php5/fpm/php.ini | |
sed -i 's|;opcache.enable=0|opcache.enable=1|' /etc/php5/fpm/php.ini | |
sed -i 's|;opcache.memory_consumption=64|opcache.memory_consumption=128|' /etc/php5/fpm/php.ini | |
cat >> /etc/php5/mods-available/xdebug.ini << EOF | |
xdebug.collect_params = 1 | |
xdebug.idekey = "VVVDEBUG" | |
xdebug.profiler_enable_trigger = 1 | |
xdebug.profiler_output_name = "cachegrind.out.%t-%s" | |
xdebug.remote_autostart = 1 | |
xdebug.remote_enable = 1 | |
xdebug.remote_connect_back = 1 | |
xdebug.remote_host = "192.168.50.1" | |
xdebug.remote_log = /srv/log/xdebug-remote.log | |
xdebug.remote_port = 9000 | |
xdebug.cli_color=1 | |
xdebug.var_display_max_children = -1 | |
xdebug.var_display_max_data = -1 | |
xdebug.var_display_max_depth = -1 | |
EOF | |
# Mailcatcher Config | |
if [[ -f /etc/init/mailcatcher.conf ]]; then | |
echo ' * Mailcatcher upstart already configured.' | |
else | |
cp /srv/config/init/mailcatcher.conf /etc/init/mailcatcher.conf | |
chmod 644 /etc/init/mailcatcher.conf | |
echo " * Copied /srv/config/init/mailcatcher.conf to /etc/init/mailcatcher.conf" | |
fi | |
if [[ -f /etc/php5/mods-available/mailcatcher.ini ]]; then | |
echo ' * Mailcatcher php5 fpm already configured.' | |
else | |
cp /srv/config/php5-fpm-config/mailcatcher.ini /etc/php5/mods-available/mailcatcher.ini | |
chmod 644 /etc/php5/mods-available/mailcatcher.ini | |
echo " * Copied /srv/config/php5-fpm-config/mailcatcher.ini to /etc/php5/mods-available/mailcatcher.ini" | |
fi | |
# Disable PHP Xdebug module by default | |
php5dismod xdebug | |
# Enable PHP mcrypt and opcache module by default | |
php5enmod mcrypt | |
php5enmod opcache | |
# Enable PHP mailcatcher sendmail settings by default | |
php5enmod mailcatcher | |
service php5-fpm restart | |
# Memcached Config | |
echo '>>> Customize Memcached Config...' | |
sed -i "s|logfile /var/log/memcached.log|logfile /srv/log/memcached.log|" /etc/memcached.conf | |
sed -i "s|-m 64|-m 128|" /etc/memcached.conf | |
# MySQL Config | |
echo '>>> Customize MySQL Config...' | |
sed -i '/skip-external-locking/a innodb_file_per_table = 1' /etc/mysql/my.cnf | |
sed -i 's|127.0.0.1|0.0.0.0|' /etc/mysql/my.cnf | |
sed -i 's|key_buffer|key_buffer_size|' /etc/mysql/my.cnf | |
sed -i 's|max_allowed_packet\(.*\)= 16M|max_allowed_packet\1= 128M|' /etc/mysql/my.cnf | |
sed -i 's|log_error = /var/log/mysql/error.log|log_error = /srv/log/mysql/error.log|' /etc/mysql/my.cnf | |
sed -i 's|#log_slow_queries\(.*\)= /var/log/mysql/mysql-slow.log|log_slow_queries\1= /srv/log/mysql/mysql-slow.log|' /etc/mysql/my.cnf | |
sed -i 's|#long_query_time = 2|long_query_time = 2|' /etc/mysql/my.cnf | |
sed -i 's|#log-queries-not-using-indexes|log-queries-not-using-indexes|' /etc/mysql/my.cnf | |
echo " * Copying /srv/config/mysql-config/root-my.cnf => /home/vagrant/.my.cnf" | |
cp /srv/config/mysql-config/root-my.cnf /home/vagrant/.my.cnf | |
chmod 644 /home/vagrant/.my.cnf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment