Skip to content

Instantly share code, notes, and snippets.

@mdrmike
Last active February 4, 2016 23:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdrmike/3d70d7b56d8ce75786f7 to your computer and use it in GitHub Desktop.
Save mdrmike/3d70d7b56d8ce75786f7 to your computer and use it in GitHub Desktop.
Bash script to Setup Ubuntu 14.04 + Nginx + PHP-FPM + Maria and other optional tools based on for https://gist.github.com/mdrmike/2fb54d72bd9c4075dd5e
#!/bin/bash
# Setup Script to configure Ubuntu 14.04 as an NGINX webserver configured for
# Drupal. This script will install and configure NGINX + PHP5-FPM + MARIADB and
# Optionally instal and configure additional development and desktop software.
#
# THE MIT LICENSE
# Copyright (C) 2014, Michael Stewart www.zaferia.net
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
################################################################################
# SCRIPT VARIABLES
#################################
WWWDevelopment=1 # Flag to install extra development apps (phpmyadmin, etc)
WWWDesktop=1 # Flag to install Desktop GUI apps
WWWRubyRBenv=1 # Flag - Ruby install type, set only RBenv, RVM, or APT to 1
WWWRubyRVM=0
WWWRubyAPT=0
WWWOwner="drupalpro" # user
WWWGroup="www-data" # apache/nginx group
SQLuser="root" # MYSQL root user
SQLpwd="drupalpro" # MYSQL root user password
DIRHome="/home/$WWWOwner" # user home path
DIRPrograms="$DIRHome/Programs" # path for user Programs (Applications)
DIRwww="$DIRHome/websites" # path to website projects directory
DIRd5="drush5" # directory name for drush 5.x
DIRd6="drush6" # directory name for drush 6.x
VER_DRUPAL="drupal-7.x" # Version of Drupal to install for example website
VER_DRUSH5="7.x-5.9" # Version of Drush to install
VER_DRUSH6="8.x-6.0-beta1" # Version of Drush to install
VER_KOALA="v2.0.3" # Version of Koala to install
VER_GEANY_SCHEMES="1.22" # Version of colorschemes for geany
OPT_APTGET="-y" # APT-GET options
################################################################################
# UPDATE UBUNTU 14.04
apt-get update
apt-get $OPT_APTGET upgrade
# CORE INSTALL
# note: you'll need to enter a root password for mysql
apt-get $OPT_APTGET install nginx php5-fpm php5-cli php5-gd mariadb-server-5.5
# Optional: Install Development related apps
[ $WWWDevelopment = 1 ] && apt-get $OPT_APTGET install git phpmyadmin
# Backup orig conf files
cp /etc/php5/fpm/pool.d/www.conf /etc/php5/fpm/pool.d/www.conf.ORIGINAL
# php5-fpm setup
# secure php5-fpm a bit more to only listen.allowed_clients = 127.0.0.1
sed -i 's|;listen.allowed_clients = 127.0.0.1|listen.allowed_clients = 127.0.0.1|g' /etc/php5/fpm/pool.d/www.conf
# Setup PHP for Drupal
# by overriding vanilla PHP.ini (which makes for easy future updates)
mkdir /etc/php5/conf.d
wget -O - https://gist.github.com/mdrmike/75c3707ee867537def03/download | sudo tar xz
mv gist75c3*/* /etc/php5/conf.d/
rm -R gist75c3*
ln -s /etc/php5/conf.d/php_drupalpro.ini /etc/php5/fpm/conf.d/99-php_drupalpro.ini
# Setup nginx
# NGINX DRUPAL VHOST TEMPLATE
wget -O - https://gist.github.com/mdrmike/ec44068eb88a592b8f86/download | sudo tar xz
mv gistec44*/* /etc/nginx/sites-available/
rm -R gistec44*
# Optional: PHPMYADMIN Setup
wget -O - https://gist.github.com/mdrmike/8cd55112af1db7a446f5/download | sudo tar xz
mv gist8cd5*/* /etc/nginx/sites-available/
rm -R gist8cd5*
ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/
echo '127.0.0.1 phpmyadmin #drupalpro' | sudo tee -a /etc/hosts
# Optional: Install Drush
sudo -u $WWWOwner -g $WWWOwner mkdir -p $DIRPrograms
sudo -u $WWWOwner -g $WWWOwner git clone https://github.com/drush-ops/drush.git $DIRPrograms/$DIRd5
sudo -u $WWWOwner -g $WWWOwner cp -R $DIRPrograms/$DIRd5 $DIRPrograms/$DIRd6
cd $DIRPrograms/$DIRd5
sudo -u $WWWOwner -g $WWWOwner git checkout tags/$VER_DRUSH5
cd $DIRPrograms/$DIRd6
sudo -u $WWWOwner -g $WWWOwner git checkout tags/$VER_DRUSH6
ln -s $DIRPrograms/$DIRd5/drush /usr/local/sbin/
ln -s $DIRPrograms/$DIRd5/drush /usr/local/sbin/d5
ln -s $DIRPrograms/$DIRd6/drush /usr/local/sbin/d6
ln -s $DIRPrograms/$DIRd5/drush.complete.sh /etc/bash_completion.d/
# Optional: Quickstart drush addons install
mkdir $DIRPrograms
mkdir $DIRHome/.drush
sudo -u $WWWOwner -g $WWWOwner git clone --branch 7.x-3.x http://git.drupal.org/project/drupalpro.git $DIRPrograms/drupalpro
ln -s cd $DIRPrograms/drupalpro/drush_addons/* $DIRHome/.drush/
# Optional: Setup example Drupal Website: drupal7.dev
sudo -u $WWWOwner -g $WWWGroup mkdir -p $DIRwww
drush -y dl --destination=$DIRwww $VER_DRUPAL
mv $DIRwww/drupal-7*/ $DIRwww/drupal7
mkdir $DIRwww/drupal7/sites/default/files
cp $DIRwww/drupal7/sites/default/default.settings.php $DIRwww/drupal7/sites/default/settings.php
chown -R $WWWOwner:$WWWGroup $DIRwww
find $DIRwww -type d -print0 | xargs -0r chmod a=,u+srwX,g+srX --
chmod a=,ug+rwX $DIRwww/drupal7/sites/default/files
chmod ug+rw $DIRwww/drupal7/sites/default/settings.php
cp /etc/nginx/sites-available/TEMPLATE_drupalpro.conf /etc/nginx/sites-available/drupal7.dev.conf
sed -i 's|##==SERVER_TLD==|drupal7.dev|g' /etc/nginx/sites-available/drupal7.dev.conf
sed -i 's|##==PATH_TO_SITE==|/home/drupalpro/websites/drupal7|g' /etc/nginx/sites-available/drupal7.dev.conf
sed -i 's|##==D7_ONLY==||g' /etc/nginx/sites-available/drupal7.dev.conf
ln -s /etc/nginx/sites-available/drupal7.dev.conf /etc/nginx/sites-enabled/
echo '127.0.0.1 drupal7.dev #drupalpro' | sudo tee -a /etc/hosts
mysql -h localhost -u$SQLuser -p$SQLpwd
create database drupal7;
create user drupal7;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `drupal7`.* TO 'drupal7'@'localhost' IDENTIFIED BY 'drupal7';
exit
# Restart Services
service mysql restart
service nginx restart
service php5-fpm stop #bug in php5-fpm restart: https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1242376
sleep 3 && service php5-fpm start
# Make all logs readable by adm group
chown -R :adm /var/log/*
chmod -R g+r /var/log/*
# Optional: Install Desktop development apps
[ $WWWDesktop = 1 ] && apt-get $OPT_APTGET install gitg meld nautilus-compare guake geany diodon synaptic indicator-multiload hamster-applet hamster-indicator gtg autokey-gtk
# APT-GET Option to Install Ruby
if [ $WWWRubyAPT = 1 ]; then
apt-get $OPT_APTGET install ruby
gem install compass
fi
# RBenv Option to Install Ruby
# Optional: (Don't do this if you install ruby via apt-get) alternate rbenv ruby install - https://gorails.com/setup/ubuntu/14.04 / OR chruby: http://yousefourabi.com/blog/2013/11/the-postmodern-ruby-environment
# hmm ... might need: sudo apt-get install apt-get install autoconf bison libssl-dev
if [ $WWWRubyRBenv = 1 ]; then
# https://gorails.com/setup/ubuntu/14.04 - requirements
#apt-get install git curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties
#https://github.com/sstephenson/ruby-build/wiki ubuntu requirements
apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6 libreadline6-dev zlib1g zlib1g-dev
git clone git://github.com/sstephenson/rbenv.git $DIRHome/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $DIRHome/.bash_aliases
echo 'eval "$(rbenv init -)"' >> $DIRHome/.bash_aliases
git clone git://github.com/sstephenson/ruby-build.git $DIRHome/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> $DIRHome/.bash_aliases
sudo -u $WWWOwner -g $WWWOwner rbenv install 2.1.2
sudo -u $WWWOwner -g $WWWOwner rbenv global 2.1.2
sudo -u $WWWOwner -g $WWWOwner ruby -v && gem install compass
fi
# RVM Option to Install Ruby
# Optional: (Don't do this if you installed ruby via apt-get or rbenv)
# setup requirements for veewee
if [ $WWWRubyRVM = 1 ]; then
# https://gorails.com/setup/ubuntu/14.04 - requirements
#apt-get install git curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties
#apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
apt-get install git curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties
# check for missing requirements for RVM
# for name in {bash,awk,sed,grep,ls,cp,tar,curl,gunzip,bunzip2,git,svn} ; do which $name || echo "** MISSING: $name" ; done
# Install requirements for RVM
sudo -u $WWWOwner -g $WWWOwner curl -sSL https://get.rvm.io | sudo -u $WWWOwner -g $WWWOwner bash -s stable
sudo -u $WWWOwner -g $WWWOwner source $DIRHome/.rvm/scripts/rvm
sudo -u $WWWOwner -g $WWWOwner echo "source ~/.rvm/scripts/rvm" >> $DIRHome/.bash_aliases
sudo -u $WWWOwner -g $WWWOwner rvm install 2.1.2
sudo -u $WWWOwner -g $WWWOwner rvm use 2.1.2 --default
sudo -u $WWWOwner -g $WWWOwner ruby -v
fi
# Optional: Setup editors
# GEANY
[ ! -d $DIRHome/.config/geany ] && sudo -u $WWWOwner -g $WWWOwner mkdir -p $DIRHome/.config/geany
sudo -u $WWWOwner -g $WWWOwner git clone https://github.com/codebrainz/geany-themes.git $DIRHome/.config/geany/codebrainz
cd $DIRHome/.config/geany/codebrainz
git checkout tags/$VER_GEANY_SCHEMES
sudo -u $WWWOwner -g $WWWOwner mkdir -p $DIRHome/.config/geany/colorschemes
sudo -u $WWWOwner -g $WWWOwner ln -s $DIRHome/.config/geany/codebrainz/colorschemes/* $DIRHome/.config/geany/colorschemes/
# Optional: Install Koala GUI for SASS/LESS/COFFESCRIPT Development: https://github.com/oklai/koala # https://github.com/rogerwang/node-webkit
[ ! -d $DIRPrograms ] && mkdir $DIRPrograms
git clone https://github.com/oklai/koala.git $DIRPrograms/koala
cd $DIRPrograms/koala
git checkout tags/$VER_KOALA
cd $DIRPrograms
wget -O - http://dl.node-webkit.org/v0.9.2/node-webkit-v0.9.2-linux-x64.tar.gz | tar xz
cp ~/Programs/node-webkit-v0.9.2-linux-x64/nw* ~/Programs/koala/src/
#fix stupid broken dependency - http://askubuntu.com/questions/288821/how-do-i-resolve-a-cannot-open-shared-object-file-libudev-so-0-error/288822#288822
[ `getconf LONG_BIT` == "64" ] \
&& ln -s /lib/x86_64-linux-gnu/libudev.so.1 /lib/x86_64-linux-gnu/libudev.so.0 \
|| ln -s /lib/i386-linux-gnu/libudev.so.1 /lib/i386-linux-gnu/libudev.so.0
sudo -u $WWWOwner -g $WWWOwner tee -a $DIRHome/.local/share/applications/koala.desktop > /dev/null <<-END_OF_FILE
[Desktop Entry]
Version=2.0.2
Name=Koala
Comment=Preprocessor
Exec=/home/drupalpro/Programs/koala/src/nw
Icon=/home/drupalpro/Programs/koala/src/app/assets/img/koala.png
Terminal=false
Type=Application
Categories=Development;Application;
END_OF_FILE
chmod +x $DIRHome/.local/share/applications/koala.desktop
# Optional: Install live-reload: https://github.com/guard/guard-livereload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment