-
-
Save ant0nioli/ed04c216d854d8758ced to your computer and use it in GitHub Desktop.
Vagrant provision script for LAMP environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# Variables | |
APPENV=local | |
DBHOST=localhost | |
DBNAME=dbname | |
DBUSER=dbuser | |
DBPASSWD=dbpass | |
echo -e "\n--- Mkay, installing now... ---\n" | |
echo -e "\n--- Updating packages list ---\n" | |
apt-get update | |
echo -e "\n--- Install base packages ---\n" | |
apt-get -y install curl git | |
echo -e "\n--- Updating packages list ---\n" | |
apt-get update | |
echo -e "\n--- Install MySQL specific packages and settings ---\n" | |
echo "mysql-server mysql-server/root_password password $DBPASSWD" | debconf-set-selections | |
echo "mysql-server mysql-server/root_password_again password $DBPASSWD" | debconf-set-selections | |
echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections | |
echo "phpmyadmin phpmyadmin/app-password-confirm password $DBPASSWD" | debconf-set-selections | |
echo "phpmyadmin phpmyadmin/mysql/admin-pass password $DBPASSWD" | debconf-set-selections | |
echo "phpmyadmin phpmyadmin/mysql/app-pass password $DBPASSWD" | debconf-set-selections | |
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect none" | debconf-set-selections | |
apt-get -y install mysql-server-5.5 phpmyadmin | |
echo -e "\n--- Setting up our MySQL user and db ---\n" | |
mysql -uroot -p$DBPASSWD -e "CREATE DATABASE $DBNAME" | |
mysql -uroot -p$DBPASSWD -e "grant all privileges on $DBNAME.* to '$DBUSER'@'localhost' identified by '$DBPASSWD'" | |
echo -e "\n--- Installing PHP-specific packages ---\n" | |
apt-get -y install apache2 php5 libapache2-mod-php5 php5-curl php5-gd php5-mcrypt php5-mysql | |
echo -e "\n--- Enabling mod-rewrite ---\n" | |
a2enmod rewrite | |
echo -e "\n--- Allowing Apache override to all ---\n" | |
sed -i "s/AllowOverride None/AllowOverride All/g" /etc/apache2/apache2.conf | |
sed -i "s/var\/www/vagrant/g" /etc/apache2/apache2.conf | |
echo -e "\n--- Replacing document root directory ---\n" | |
sed -i "s/\/var\/www/\/vagrant/g" /etc/apache2/sites-enabled/000-default.conf | |
echo -e "\n--- We definitly need to see the PHP errors, turning them on ---\n" | |
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php5/apache2/php.ini | |
sed -i "s/display_errors = .*/display_errors = On/" /etc/php5/apache2/php.ini | |
echo -e "\n--- Configure Apache to use phpmyadmin ---\n" | |
echo -e "\n\nListen 81\n" >> /etc/apache2/ports.conf | |
cat > /etc/apache2/conf-available/phpmyadmin.conf << "EOF" | |
<VirtualHost *:81> | |
ServerAdmin webmaster@localhost | |
DocumentRoot /usr/share/phpmyadmin | |
DirectoryIndex index.php | |
ErrorLog ${APACHE_LOG_DIR}/phpmyadmin-error.log | |
CustomLog ${APACHE_LOG_DIR}/phpmyadmin-access.log combined | |
</VirtualHost> | |
EOF | |
a2enconf phpmyadmin | |
echo -e "\n--- Add environment variables to Apache ---\n" | |
cat > /etc/apache2/sites-enabled/000-default.conf <<EOF | |
<VirtualHost *:80> | |
DocumentRoot /vagrant | |
ErrorLog \${APACHE_LOG_DIR}/error.log | |
CustomLog \${APACHE_LOG_DIR}/access.log combined | |
SetEnv APP_ENV $APPENV | |
SetEnv DB_HOST $DBHOST | |
SetEnv DB_NAME $DBNAME | |
SetEnv DB_USER $DBUSER | |
SetEnv DB_PASS $DBPASSWD | |
</VirtualHost> | |
EOF | |
echo -e "\n--- Restarting Apache ---\n" | |
service apache2 restart | |
echo -e "\n--- Installing Composer for PHP package management ---\n" | |
curl --silent https://getcomposer.org/installer | php | |
mv composer.phar /usr/local/bin/composer | |
echo -e "\n--- Installing NodeJS and NPM ---\n" | |
#curl --silent --location https://deb.nodesource.com/setup_4.x | sudo bash - | |
apt-get -y install nodejs | |
curl --silent https://npmjs.org/install.sh | sh | |
echo -e "\n--- Installing javascript components ---\n" | |
npm install -g gulp bower > /dev/null 2>&1 | |
echo -e "\n--- Updating project components and pulling latest versions ---\n" | |
cd /vagrant | |
sudo -u vagrant -H sh -c "composer install" | |
cd /vagrant/client | |
sudo -u vagrant -H sh -c "npm install" | |
sudo -u vagrant -H sh -c "bower install -s" | |
sudo -u vagrant -H sh -c "gulp" | |
echo -e "\n--- Creating a symlink for future phpunit use ---\n" | |
ln -fs /vagrant/vendor/bin/phpunit /usr/local/bin/phpunit | |
echo -e "\n--- Add environment variables locally for artisan ---\n" | |
cat >> /home/vagrant/.bashrc <<EOF | |
# Set envvars | |
export APP_ENV=$APPENV | |
export DB_HOST=$DBHOST | |
export DB_NAME=$DBNAME | |
export DB_USER=$DBUSER | |
export DB_PASS=$DBPASSWD | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment