diff --git a/project-08-V2/Shell-Scripts/deploy-app.sh b/project-08-V2/Shell-Scripts/deploy-app.sh new file mode 100644 index 0000000..a3c6675 --- /dev/null +++ b/project-08-V2/Shell-Scripts/deploy-app.sh @@ -0,0 +1,62 @@ +#!/bin/bash -xe + + +# System Updates +sudo yum -y update + + +# STEP 1 - Install system software - including Web and DB +sudo yum install -y mariadb-server httpd +sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2 + + +# STEP 2 - Web and DB Servers Online - and set to startup +sudo systemctl start httpd +sudo systemctl enable httpd +sudo systemctl start mariadb +sudo systemctl enable mariadb + + +# STEP 3 - Setpassword & DB Variables +DBName='HR_RDS_DB' +DBUser='admin' +DBPassword='Project8' +DBRootPassword='Admin123root' +DBEndpoint='copy_here_rds_endpoint' + + +# STEP 4 - Set Mariadb Root Password +mysqladmin -u root password $DBRootPassword + + +# STEP 5 - Install Wordpress +sudo wget http://wordpress.org/latest.tar.gz -P /var/www/html +cd /var/www/html +sudo tar -zxvf latest.tar.gz +sudo cp -rvf wordpress/* . +sudo rm -R wordpress +sudo rm latest.tar.gz + + +# STEP 6 - Configure Wordpress +sudo cp ./wp-config-sample.php ./wp-config.php +sudo sed -i "s/'database_name_here'/'$DBName'/g" wp-config.php +sudo sed -i "s/'username_here'/'$DBUser'/g" wp-config.php +sudo sed -i "s/'password_here'/'$DBPassword'/g" wp-config.php +sudo sed -i "s/'localhost'/'$DBEndpoint'/g" wp-config.php + +# Step 6a - permissions +sudo usermod -a -G apache ec2-user #Add your user (in this case, ec2-user) to the apache group. +sudo chown -R ec2-user:apache /var/www #Change the group ownership of /var/www and its contents to the apache group. +sudo chmod 2775 /var/www + +sudo find /var/www -type d -exec chmod 2775 {} \; +sudo find /var/www -type f -exec chmod 0664 {} \; + +# STEP 7 Create Wordpress DB +echo "CREATE DATABASE $DBName;" >> /tmp/db.setup +echo "CREATE USER '$DBUser'@'localhost' IDENTIFIED BY '$DBPassword';" >> /tmp/db.setup +echo "GRANT ALL ON $DBName.* TO '$DBUser'@'localhost';" >> /tmp/db.setup +echo "FLUSH PRIVILEGES;" >> /tmp/db.setup +mysql -u root --password=$DBRootPassword < /tmp/db.setup +sudo rm /tmp/db.setup