Skip to content

Instantly share code, notes, and snippets.

@ErxrilOwl
Last active May 4, 2024 11:17
Show Gist options
  • Save ErxrilOwl/0287df71d994ba3b3ebcec3a6e4e27bc to your computer and use it in GitHub Desktop.
Save ErxrilOwl/0287df71d994ba3b3ebcec3a6e4e27bc to your computer and use it in GitHub Desktop.
Deploy Laravel Project on AWS EC2 AMI

Deploying Laravel Application on AWS EC2

Reference

Launch the instance

Select Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type

Configure Security Group

Add rule of HTTP and HTTPS

Launch Amazon RDS Database

Create new RDS database. Fill up the form and save.

After that navigate to Security Groups under Network & Security on the EC2 dashboard and click the Create Security Group button.

Create security group with a MYSQL/Aurora rule that opens port 3306 access. Select Anywhere as source, then click Create.

Connect to EC2 Instance via SSH

 ssh -i <filename.pem> ec2-user@<public_ip>

Install Apache

sudo su
yum update -y

yum install httpd24 -y
yum install php72 php72-mysqlnd php72-imap php72-pecl-memcache php72-pecl-apcu php72-gd php72-mbstring -y
yum install mod24_ssl -y

service httpd start

Check by visiting to your public ip in the browser

chkconfig —add httpd
chkconfig httpd on

Install Git

yum install git -y

Install Composer && Laravel

Composer

yum install wget -y
wget https://getcomposer.org/composer.phar

Verify Composer

php composer.phar

Install Laravel (Optional)

php composer.phar global require laravel/installer

If has error PHP Composer update “cannot allocate memory” error

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

cd to apache folder

cd /var/www/html

Create or Clone Project

Clone

git clone <git_url>

Edit .htaccess

vim /var/www/html/laravel/public/.htaccess

Add RewriteBase / just below RewriteEngine On

Configure .env. Supply the database host, name, username and password base on the created rds database

mv .env.example .env
vim .env

Edit config /etc/httpd/conf/httpd.conf and add the following at the bottom of the file

Alias / /var/www/html/<project_folder_name>/public/
<Directory "/var/www/html/<project_folder_name>/public">
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

Give write access to storage folder

sudo chmod -R 777 /var/www/html/laravel/storage
sudo chmod -R 777 /var/www/html/laravel/storage/logs

Restart Apache

service httpd restart
cd /var/www/html/laravel

Migrate

php artisan migrate
@nizzam
Copy link

nizzam commented Oct 5, 2023

Hi @ErxrilOwl ,

Can you do a tutorial for deployment of laravel using NGINX ?

Thank you.

@ErxrilOwl
Copy link
Author

Hi @ErxrilOwl ,

Can you do a tutorial for deployment of laravel using NGINX ?

Thank you.

Hello, this might be helpful, Deployment Guide to Laravel - Ubuntu

@nizzam
Copy link

nizzam commented Oct 6, 2023

Thank you for your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment