Skip to content

Instantly share code, notes, and snippets.

@robinwl
Last active July 3, 2017 13:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinwl/c4be47632f3a8776ac24 to your computer and use it in GitHub Desktop.
Save robinwl/c4be47632f3a8776ac24 to your computer and use it in GitHub Desktop.
Vagrant shell provisioner for creating a LAMP-stack
##
# Shell provisioner for LAMP
# Tested on Ubuntu 12.04
##
# Detect environment
source /etc/os-release
# Set non-interactive mode
export DEBIAN_FRONTEND=noninteractive
# Update package mirrors and update base system
apt-get update
apt-get -y dist-upgrade
# Install packages
apt-get -y install mysql-server mysql-client
apt-get -y install apache2
apt-get -y install php5 php5-mysql libapache2-mod-php5 php5-cli php5-curl php-soap php5-imagick php5-gd php5-mcrypt php5-mysql php5-xmlrpc php5-xsl php5-xdebug
apt-get -y install git tree curl htop
# Install composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
# Create database
if [ -z `mysql -uroot --skip-column-names --batch -e "SHOW DATABASES LIKE 'project'"` ]
then
mysql -uroot -e "create database project"
EMPTY_DB=true
fi
# Set up vhost
cat > /etc/apache2/sites-available/vagrant <<'EOF'
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /vagrant/public
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /vagrant/public/>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF
# Clean other vhosts
rm /etc/apache2/sites-enabled/*
# Activate vagrant vhost
ln -s /etc/apache2/sites-available/vagrant /etc/apache2/sites-enabled/000-vagrant
# Change user and group for apache
sed -i '/APACHE_RUN_USER/d' /etc/apache2/envvars
sed -i '/APACHE_RUN_GROUP/d' /etc/apache2/envvars
cat >> /etc/apache2/envvars <<'EOF'
# Apache user and group
export APACHE_RUN_USER=vagrant
export APACHE_RUN_GROUP=vagrant
EOF
# Fix premissions
if [ -d /var/lock/apache2 ]
then
chown -R vagrant:vagrant /var/lock/apache2
fi
# Enable rewrites
a2enmod rewrite
# Some changes to php.ini
sed -i 's/display_errors = Off/display_errors = On/g' /etc/php5/apache2/php.ini
sed -i 's/display_startup_errors = Off/display_startup_errors = On/g' /etc/php5/apache2/php.ini
sed -i 's/error_reporting = E_ALL & ~E_DEPRECATED/error_reporting = E_ALL/g' /etc/php5/apache2/php.ini
sed -i 's/track_errors = Off/track_errors = On/g' /etc/php5/apache2/php.ini
sed -i 's/html_errors = Off/html_errors = On/g' /etc/php5/apache2/php.ini
# Clean up
apt-get clean
# Restart services
service apache2 restart
printf "\n\n"
echo "Provision complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment