Complete Guide

Deploy any Laravel App in AWS (Amazon Web Services)

Using AWS EC2 + RDS (Ubuntu, MySQL RDS)

Monday, April 19, 2021 (MDT)

Check if your website is working

Table of Contents

Deploying Laravel applications the correct way in 10 Steps using AWS.

In this tutorial we will cover

  1. Domain Registration

  2. Elastic IP Address

  3. Security Groups

  4. Launching RDS instance (For MySQL DB)

  5. Launching EC2 Linux Ubuntu Instance

  6. Requirements Gathering & Preparations

  7. Importing Laravel Project & Setting up folder permissions

  8. Installing & configuring Apache2, Installing Composer & Dependencies

  9. SSL Certification using Certbot

  10. [Optional] CloudWatch & Automated Notifications

Commands

#ssh to instance using .pem file 
ssh -i {pem file} {user}@{ip address}

#connect to mysql, show database and create database
mysql -h production-database.c0wmvggcg6ht.us-east-2.rds.amazonaws.com -P 3306 -u admin -p
SHOW DATABASES;
CREATE DATABASE {db-name};

#git configure remote & force push
git init
git config --global user.email "support@ahtcloud.com" 
git config --global user.name "Emad Zaamout"
git remote add origin {bitbucket-repositry-url}
git push -u -f origin master

#git pull repository 
git pull {bitbucket repository}


# ==== SERVER SET UP ==== 
sudo apt-get update 
sudo apt-get dist-upgrade  
sudo apt-get install apache2 
sudo apt-get install software-properties-commo
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt-get install php7.4
sudo apt install php-curl php-cli php-mbstring git unzip  php7.4-mysql php7.4-dom php7.4-xml php7.4-xmlwriter phpunit php-mbstring php-xml
sudo apt install python3-certbot-apache

# ==== Composer & PHP Extensions
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'c31c1e292ad7be5f49291169c0ac8f683499edddcfd4e42232982d0fd193004208a58ff6f353fde0012d35fdd72bc394') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

sudo mv composer.phar /usr/local/bin/
#[OR] alias composer='/usr/local/bin/composer.phar'

# ==== laravel set up ====
php artisan migrate
php artisan key:generate 

# ==== Laravel Permissions ====
sudo chown -R www-data storage
sudo chown -R www-data storage/framework
sudo chmod g+w -R storage
sudo chmod g+w -R storage/framework
sudo chmod g+w -R storage/framework/sessions/
sudo chmod g+w -R storage/logs/

#virtual host configuration file
<VirtualHost *:80>
    ServerAdmin support@ahtcloud.com
    ServerName greencleaningservices.ca
	ServerAlias www.greencleaningservices.ca
    DocumentRoot /var/www/greencleaningservices/public
    
	ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
   
    <Directory /var/www/greencleaningservices>
        Require all granted
        AllowOverride All
        Options Indexes Multiviews FollowSymLinks
        </Directory>
    </VirtualHost>

Check if your website is correctly configured by using our free tool.

Check if your website is working