susanBuck / e15-spring21

1 stars 0 forks source link

EC2 & Laravel #26

Closed cgiansante closed 3 years ago

cgiansante commented 3 years ago

Below is some information for configuring a Amazon Linux EC2 instance for use with Laravel and github.

I am hoping to use this approach for project three. All thoughts, pointers and advice is welcome.

These details helped me and assume you are familiar with AWS EC2 (SSH & CLI), Security Groups, and costs (everything used is free tier eligible). Please proceed at your own risk.

Create EC2 instance with the following details

Amazon Linux 2 AMI, t2 micro using below user data:

#! /bin/bash
yum update -y
yum -y install httpd
service httpd start
amazon-linux-extras enable php7.4
yum install php-cli php-pdo php-fpm php-json php-mysqlnd php-mbstring php-dom
yum install git
echo "<h1>Welcome Page<h1>" > /var/www/html/index.html

If any commands failed from the user data on instance provisioning,

sudo yum update -y
sudo yum install httpd -y
sudo systemctl restart httpd
sudo amazon-linux-extras enable php7.4
sudo yum install php-cli php-pdo php-fpm php-json php-mysqlnd php-mbstring php-dom -y
sudo yum install git -y

Install composer

sudo curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer
sudo chmod +x /usr/bin/composer
sudo systemctl restart httpd

Connect to github

ssh-keygen -t rsa -C "email@domain.com"
sudo cat /home/ec2-user/.ssh/id_rsa.pub
ssh -T git@github.com

Update mod_rewrite

sudo nano /etc/httpd/conf/httpd.conf
    Update AllowOverride All from AllowOverride None
    Check the inclusion of /etc/httpd/conf.d

Update DNS records

Use the public URL or an elastic IP of this instance

Production Domains

Comfirm git & Clone e15

cd /var/www/html
git clone git@github.com:username/e15.git

Deploy to Digital Ocean

For Each App

cd /var/www/html/e15/app

Install Composer

composer install --no-dev

App storage permissions

sudo chmod -R 775 /var/www/html/e15/app/storage

Create ev file

sudo cp /var/www/html/e15/p3/.env.example /var/www/html/e15/p3/.env

Move to app location and generate key

cd /var/www/html/e15/p2
sudo php artisan key:generate

Edit Env variables

sudo nano /var/www/html/e15/app/.env

Update virtual hosts

sudo nano /etc/httpd/conf.d/vhosts.conf
sudo systemctl restart httpd

Check your ec2 user file permissions for the web root and app folders with the AWS LAMP guide below.

Resources

AWS LAMP AWS Instance creation AWS mod rewrite

susanBuck commented 3 years ago

This is a great resource, thanks for sharing @cgiansante! I'm going to re-open it and leave it open for a week so there's a better chance more students will have the opportunity to see it. 👍

zrashidharvard2020 commented 3 years ago

This is very helpful instructions to set up Laravel on EC2. It helped me a lot.