Skip to content

Instantly share code, notes, and snippets.

@chrowe
Last active March 25, 2016 04:28
Show Gist options
  • Save chrowe/a405f9a6d17076c721b1 to your computer and use it in GitHub Desktop.
Save chrowe/a405f9a6d17076c721b1 to your computer and use it in GitHub Desktop.
Scripts to set up a site on our dev server

Use the site.sh script to create create a directory, download a git repo, create a log directory, set up settings.local.php, create a database, chreate a vhost file, and import a db backup

The other scripts are called by site.sh

Usage: site.sh [subdomain] [git url] [New MySQL password for site] [Database backup path] [http/https]

Script asks for the MySQL Root password

cat > /var/www/$1.isoveradev.com/docroot/sites/default/settings.local.php << EOF
<?php
/*
* Change the name of this file to 'settings.local.php' and use it to override settings that should only apply locally
* (most obviously, the database). Note that settings.local.php will be excluded from version control.
*/
\$databases = array (
'default' =>
array (
'default' =>
array (
'database' => '$1',
'username' => '$1',
'password' => '$2',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
\$base_url = '$3://$1.isoveradev.com';
\$conf['stage_file_proxy_origin'] = '';
EOF
#!/bin/bash
# Usage: site.sh [subdomain] [git url] [MySQL password] [Database backup path] [http/https]
EXPECTED_ARGS=5
E_BADARGS=65
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: $0 subdomain giturl mysqlpass dbimportpath http/https"
echo "Run as isovera user. mysqlpass should be alphanumeric"
exit $E_BADARGS
fi
#Create project directory
echo "Create /var/www/$1.isoveradev.com"
sudo mkdir /var/www/$1.isoveradev.com
sudo chown isovera:www-data /var/www/$1.isoveradev.com
#Download code
echo "Clone $2 to /var/www/$1.isoveradev.com"
git clone $2 /var/www/$1.isoveradev.com
sudo chown -R isovera:www-data /var/www/$1.isoveradev.com
sudo chmod -R 755 /var/www/$1.isoveradev.com/docroot
mkdir /var/www/$1.isoveradev.com/docroot/sites/default/files
sudo chmod -R 775 /var/www/$1.isoveradev.com/docroot/sites/default/files
#Create log directory
mkdir /var/www/$1.isoveradev.com/log
#Create settings.local.php
echo "Create settings.local.php"
./settings.local.sh $1 $3 $5
#Create database
echo "Create $1 database"
MYSQL=`which mysql`
Q1="CREATE DATABASE IF NOT EXISTS $1;"
Q2="GRANT USAGE ON *.* TO $1@localhost IDENTIFIED BY '$3';"
Q3="GRANT ALL PRIVILEGES ON $1.* TO $1@localhost;"
Q4="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}${Q4}"
$MYSQL -uroot -p -e "$SQL"
#Create vhost file
echo "Create vhost file /etc/apache2/sites-available/$1.isoveradev.com.conf"
# sudo touch /etc/apache2/sites-available/$1.isoveradev.com.conf
sudo ./vhost.sh $1
sudo a2ensite $1.isoveradev.com.conf
sudo service apache2 restart
#import database
echo "Import database"
cd /var/www/$1.isoveradev.com/docroot
drush sql-cli < $4
drush cc all
drush updb
echo "All Done :)"
echo "Visit your site at $5://$1.isoveradev.com"
cat > /etc/apache2/sites-available/$1.isoveradev.com.conf << EOF
# domain: $1.isoveradev.com
# public: /var/www/$1.isoveradev.com/docroot
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin webmaster@localhost
ServerName $1.isoveradev.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.php
DocumentRoot /var/www/$1.isoveradev.com/docroot
<Directory /var/www/$1.isoveradev.com/docroot>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# Log file locations
LogLevel warn
ErrorLog /var/www/$1.isoveradev.com/log/error.log
CustomLog /var/www/$1.isoveradev.com/log/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName $1.isoveradev.com
DirectoryIndex index.php
DocumentRoot /var/www/$1.isoveradev.com/docroot/
<Directory /var/www/$1.isoveradev.com/docroot>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/www/$1.isoveradev.com/log/error.log
CustomLog /var/www/$1.isoveradev.com/log/access.log combined
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
SSLCertificateFile /etc/ssl/certs/isoveradev.crt
SSLCertificateKeyFile /etc/ssl/private/isoveradev.key
SSLCertificateChainFile /etc/ssl/certs/gd_bundle-g2-g1.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
</IfModule>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment