Created
October 19, 2018 01:00
-
-
Save JeffreyHyer/6573f827431d95970a3a6bca70aedb38 to your computer and use it in GitHub Desktop.
Vagrant Setup
This file contains 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 | |
###### VARS ###### | |
HOSTNAME="toweez" | |
MYSQL_ROOT_PASS=$(openssl rand -hex 12) | |
MYSQL_USER=$HOSTNAME | |
MYSQL_PASS=$(openssl rand -hex 12) | |
MYSQL_DB=$HOSTNAME | |
REDIS_PASS=$(openssl rand -hex 12) | |
################## | |
echo "--- Add external PPAs to sources ---" | |
add-apt-repository -y ppa:ondrej/php | |
add-apt-repository -y ppa:ondrej/apache2 | |
add-apt-repository -y ppa:chris-lea/redis-server | |
apt-get -qq update | |
echo "--- Upgrade existing packages ---" | |
apt-get -y upgrade | |
echo "--- Install core/base packages needed later ---" | |
apt-get install -y curl python-software-properties build-essential tcl8.5 git openssl debconf zip unzip | |
echo "--- Install MySQL ---" | |
echo mysql-server mysql-server/root_password password $MYSQL_ROOT_PASS | debconf-set-selections | |
echo mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASS | debconf-set-selections | |
apt-get -y install mysql-server | |
echo "--- Setup MySQL User and Database ---" | |
mysql -uroot -p$MYSQL_ROOT_PASS -e "CREATE DATABASE $MYSQL_DB" | |
mysql -uroot -p$MYSQL_ROOT_PASS -e "GRANT ALL PRIVILEGES ON $MYSQL_DB.* TO '$MYSQL_USER'@'localhost' IDENTIFIED BY '$MYSQL_PASS'" | |
mysql -uroot -p$MYSQL_ROOT_PASS -e "FLUSH PRIVILEGES" | |
echo "--- Install Apache 2.4.x and PHP 7.x ---" | |
apt-get install -y --allow-unauthenticated\ | |
php7.2 apache2 libapache2-mod-php7.2 php7.2-curl php7.2-gd php7.2-mysql php7.2-mbstring php7.2-common php7.2-curl php-pear \ | |
php7.2-xml php7.2-dom php-redis openssl-blacklist openssl-blacklist-extra | |
echo "--- Configure Apache/PHP ---" | |
a2enmod rewrite | |
a2enmod headers | |
a2enmod mime | |
a2enmod deflate | |
a2enmod setenvif | |
a2enmod filter | |
a2enmod expires | |
a2enmod ssl | |
service apache2 restart | |
rm -rf /var/www/html | |
echo "--- Install Redis Server ---" | |
apt-get -y install redis-server | |
echo "--- Install Composer ---" | |
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | |
sed -i "s/DB_DATABASE=.*$/DB_DATABASE=$MYSQL_DB/" /var/www/$HOSTNAME/.env | |
sed -i "s/DB_USERNAME=.*$/DB_USERNAME=$MYSQL_USER/" /var/www/$HOSTNAME/.env | |
sed -i "s/DB_PASSWORD=.*$/DB_PASSWORD=$MYSQL_PASS/" /var/www/$HOSTNAME/.env | |
sed -i "s/REDIS_PASSWORD=.*/REDIS_PASSWORD=$REDIS_PASS/" /var/www/$HOSTNAME/.env | |
echo "MySQL [root] Password: $MYSQL_ROOT_PASS" > /var/www/$HOSTNAME/.server/credentials.txt | |
echo "MySQL New User: $MYSQL_USER" >> /var/www/$HOSTNAME/.server/credentials.txt | |
echo "MySQL New Pass: $MYSQL_PASS" >> /var/www/$HOSTNAME/.server/credentials.txt | |
echo "MySQL New DB: $MYSQL_DB" >> /var/www/$HOSTNAME/.server/credentials.txt | |
echo "Redis AUTH: $REDIS_PASS" >> /var/www/$HOSTNAME/.server/credentials.txt | |
echo "+----------------------------------------------------" | |
echo "| SETUP COMPLETE " | |
echo "+----------------------------------------------------" | |
echo "| MySQL [root] Password: $MYSQL_ROOT_PASS " | |
echo "| MySQL New User: $MYSQL_USER " | |
echo "| MySQL New Pass: $MYSQL_PASS " | |
echo "| MySQL New DB: $MYSQL_DB " | |
echo "| " | |
echo "| Redis AUTH: $REDIS_PASS " | |
echo "+----------------------------------------------------" | |
echo "| Saved to /.server/credentials.txt " | |
echo "+----------------------------------------------------" |
This file contains 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
Vagrant.configure(2) do |config| | |
config.vm.box = "ubuntu/xenial64" | |
config.vm.provision "shell", path: "vagrant-bootstrap.sh" | |
config.vm.network "private_network", { | |
ip: "192.168.11.2", | |
} | |
config.vm.synced_folder ".", "/vagrant", disabled: true | |
config.vm.synced_folder ".", "/var/www/toweez" | |
config.vm.provider "virtualbox" do |v| | |
v.memory = 1024 | |
v.cpus = 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment