Skip to content

Instantly share code, notes, and snippets.

@dickolsson
Last active June 8, 2017 15:55
Show Gist options
  • Save dickolsson/45f06e85f8a8e57eaf23 to your computer and use it in GitHub Desktop.
Save dickolsson/45f06e85f8a8e57eaf23 to your computer and use it in GitHub Desktop.
Provisioning script for a simple PHP/Drupal development environment
#!/bin/bash
#
# Configure your IDE to listen to connections with these settings:
#
# * Max simultaneous connections: 3
# * Xdebug port: 9001
# * DBGp host: <blank>
# * DBGp port: 9001
# * IDE key: MYIDE
#
# Run PHP CLI scripts like this:
#
# $ PHP_IDE_CONFIG="serverName=myServer" php myScript.php
export DOMAIN=${1:-drupal1.dev}
export HOST=${2:-192.168.33.1}
export PHPMEMORY=${3:-512M}
export USR=${4:-vagrant}
export NAME=`echo $DOMAIN | cut -d \. -f 1`
export TLD=`echo $DOMAIN | cut -d \. -f 2`
export UHOME=/home/$USR
export ROOT=/var/www/html
export ENVVARS=/etc/apache2/envvars
export SITECONF=/etc/apache2/sites-available/000-default.conf
export PHPINI=/etc/php5/apache2/php.ini
export XDEBUGINI=/etc/php5/mods-available/xdebug.ini
export PHP="/usr/bin/php -d xdebug.remote_enable=0"
export COMPOSER=/usr/local/bin/composer
export DRUSH=$UHOME/.composer/vendor/bin/drush.php
DEBIAN_FRONTEND=noninteractive apt-get -y update
DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
DEBIAN_FRONTEND=noninteractive apt-get -y -f install apache2 php5 libapache2-mod-php5 mysql-server php5-mysql php5-curl php5-gd php5-cli php5-xdebug git-core
echo 'Configuring PHP...'
grep -q "memory_limit = $PHPMEMORY" $PHPINI || sed -i "s/memory_limit = .*/memory_limit = $PHPMEMORY/g" $PHPINI
grep -q 'xdebug.remote_enable' $XDEBUGINI || cat >> $XDEBUGINI <<EOF
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=$HOST
xdebug.remote_port=9001
xdebug.idekey=MYIDE
xdebug.max_nesting_level=999
EOF
echo 'Configuring Apache...'
grep -q "$DOMAIN" /etc/hosts || sed -i "s/127.0.0.1 localhost/127.0.0.1 localhost $DOMAIN/g" /etc/hosts
grep -q "$USR" $ENVVARS || sed -i "s/www-data/$USR/g" $ENVVARS
grep -q 'AllowOverride All' $SITECONF || cat >> $SITECONF <<EOF
<Directory $ROOT>
AllowOverride All
</Directory>
EOF
a2enmod rewrite
service apache2 restart
echo 'Installing Composer...'
test -f $COMPOSER || (curl -sS https://getcomposer.org/installer | $PHP && mv composer.phar $COMPOSER)
$PHP $COMPOSER self-update
su $USR -c -p -l "$PHP $COMPOSER global update"
if [ ! -f $ROOT/sites/default/settings.php ]; then
echo 'Resetting Drupal installation...'
echo "DROP DATABASE IF EXISTS $NAME; CREATE DATABASE $NAME;" | mysql -uroot
chmod 755 $ROOT/sites/default
rm -rf $ROOT/sites/default/files $ROOT/index.html
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment