Skip to content

Instantly share code, notes, and snippets.

@shoaibali
Last active May 1, 2016 23:31
Show Gist options
  • Save shoaibali/897687f48970b57ebad3 to your computer and use it in GitHub Desktop.
Save shoaibali/897687f48970b57ebad3 to your computer and use it in GitHub Desktop.
# Disclaimer - Please don't just execute it blindly, this was ran on Ubuntu 14.04.2 LTS
# I am not responsible for whatever harm this shell script may cause.
# Look at the wget requests in the shell script to make sure you are putting in configuration
# files as they should be.
# Many commands are run as sudo and permissions are changed to www-data etc
# The existing user whose running this shell script also becomes part of www-data user group
# Files downlaoded for this shell script to work - example configuration files
# 1. nginx default sites-available config
# 2. php5-fpm to listen on 9000
# 3. SilverStripe deploynaut specific _ss_environment.php file
# Assumptions -
# 1. You don't have a root password on MariaDB
# 2. Running Ubuntu 14.04.2 LTS
# 3. Want to run deploynaut silverstripe using nginx
# 4. Want to run php5-fpm
# 5. /sites/deploynaut/ is where deploynaut is installed
# 6. www-data group and user exists
# Packages installed by this shell script
# 1. Ruby
# 2. Ruby gems + capistrano / capistrano-multi
# 3. Build-essential
# 4. MariaDB (client/server)
# 5. PHP5-FPM and other php libraries
# 6. Nginx
# 7. Redis-server
# 8. SSPAK (SilverStripe tool)
# 9. Sake (SilverStripe tool)
# 10. Composer
# 11. GIT
# Add Ruby 2 PPA otherwise some gems like net-ssh dont install
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get update
# setup depdencies
sudo apt-get -y install build-essential ntp
# setup database
sudo apt-get -y install mariadb-client mariadb-server
# setup php
sudo apt-get -y install php5-fpm php5-cli php5-mysql php5-common php5-curl php5-gd php5-mcrypt
# Might need to enable mcrypt as well
sudo php5enmod mcrypt
# setup webserver
sudo apt-get -y install nginx-full ssl-cert
# -- below this line --
# deplonaut specific
# install redis server
sudo apt-get -y install redis-server git
# install ruby
sudo apt-get -y install ruby2.2 ruby-switch
sudo ruby-switch --set ruby2.2
# install gems required for deploynaut i.e capistrano
sudo gem install capistrano --no-ri --no-rdoc --verbose -v 2.15.5
sudo gem install capistrano-multiconfig --no-ri --no-rdoc --verbose -v 0.0.4
# install composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
# sspak
curl -sS https://silverstripe.github.io/sspak/install | php -- /usr/local/bin
# copy nginx config
wget -O default https://gist.githubusercontent.com/shoaibali/c8b687615d0bf00ba589/raw/0da54ce4e0cef54cc4a1337aafab76924566ebf7/silverstripe-nginx-default-config-deploynaut
sudo cp default /etc/nginx/sites-available/default
sudo service nginx configtest
sudo service nginx restart
# fix permissions
sudo usermod -a -G www-data `whoami`
#sudo usermod -a -G `whoami` www-data
groups `whoami`
newgrp
# copy php-fpm config
wget -O www.conf https://gist.githubusercontent.com/shoaibali/4b25beff35071da70ec8/raw/7f45a6f084fdb4972c3bcfc6ac746be81d5371c6/nginx-www-conf-tcp
sudo cp www.conf /etc/php5/fpm/pool.d/www.conf
sudo service php5-fpm restart
# setup deploynaut directories
sudo mkdir -p /sites/deploynaut/www
sudo mkdir -p /sites/deploynaut/deploynaut-resources/envs
sudo mkdir -p /var/www/.ssh
sudo chown -R www-data:www-data /sites/deploynaut
sudo chmod -R g+w /sites/deploynaut
sudo chmod g+w /var/www
# use compoesr to setup deploynaut
cd /sites/deploynaut/www
# if this is not run as sudo then i get error saying [RuntimeException] Could not delete ./: from composer
sudo composer create-project silverstripe/installer . 3.1.x-dev
sudo composer remove silverstripe/cms
sudo composer require "silverstripe/deploynaut:dev-master#ba0fa083d9eda434e56588210fe3c6f2120d1485"
# Go back to home
cd ~
# copy over silverstripe configuration file with database details etc
wget -O _ss_environment.php https://gist.githubusercontent.com/shoaibali/309ee4fa934b21944fca/raw/3f9a06f06262286c49afef7db643fbf6e502a4e9/deploynaut_ss_environment.php
#cp "`dirname \"$0\"`"/_ss_environment.php /sites/deploynaut/_ss_environment.php
sudo cp _ss_environment.php /sites/deploynaut/_ss_environment.php
# Fix the permissions because above commands were ran as sudo!
sudo chown -R www-data:www-data /sites/deploynaut
# run /dev/build using sake
cd /sites/deploynaut/www
sudo ./framework/sake installsake
sake dev/build "?flush=all"
# setup keys for www-data user
sudo chown -R www-data:www-data /var/www
sudo -u www-data ssh-keygen -t rsa -N '' -f /var/www/.ssh/id_rsa
echo "==== PLEASE PUT THIS PUBLIC KEY TO YOUR GITHUB or BITBUCKET or whatever VERSION CONTROL deployment keys account ==="
echo "\n"
echo "\n"
echo "\n"
echo "\n"
cat /var/www/.ssh/id_rsa.pub
echo "\n"
echo "\n"
echo "\n"
echo "\n"
# to get around problem of "The authenticity of host" git clone getting stuck on that prompt for first time
printf '%s\n\t%s\n' 'Host *' 'StrictHostKeyChecking no' | sudo tee --append /var/www/.ssh/config
sudo chown www-data: /var/www/.ssh/config
sudo chown www-data: /var/tmp/
#silverstripe/secureassets suggests installing silverstripe/cms (Allows you to easily edit file permissions in the CMS)
#chrisboulton/php-resque suggests installing ext-proctitle (Allows php-resque to rename the title of UNIX processes to show the status of a worker.)
#chrisboulton/php-resque suggests installing ext-redis (Native PHP extension for Redis connectivity. Credis will automatically utilize when available.)
#silverstripe/deploynaut suggests installing silverstripe/deploynaut-graphite (Graphite intergration)
# setup resque
sudo mkdir /sites/deploynaut/www/assets/_deploynaut_logs
#sudo mkdir /var/log/deploynaut-php-resque
sudo chown www-data: /sites/deploynaut/www/assets/_deploynaut_logs
sudo cp /sites/deploynaut/www/deploynaut/.scripts/deploynaut-php-resque /etc/init.d/deploynaut-php-resque
sudo chown root:root /etc/init.d/deploynaut-php-resque
sudo chmod +x /etc/init.d/deploynaut-php-resque
sudo update-rc.d deploynaut-php-resque defaults
sudo touch /var/log/deploynaut-php-resque
sudo chown www-data: /var/log/deploynaut-php-resque
sudo service nginx restart
sudo service php5-fpm restart
# start php5 resque
sudo /etc/init.d/deploynaut-php-resque start
echo "You should be good to go! Login to deploynaut and create project and environments etc"
echo "USERNAME: admin and PASSWORD: pass"
echo "************ PLEASE SECURE YOUR _ss_environment.php ***************"
echo "Please remember to login to those environments and check the following"
echo "- Permissions on environment server for /var/www/silverstripe/ should be group writeable and owned by www-data"
echo "- www-data ssh keys are added in authorized_keys of environment server"
echo "- _ss_envornment.php exists in /var/www/silverstripe/"
echo "- shared directory with assets inside it exists"
echo "- sake is installed on the environment server"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment