SlideShare a Scribd company logo
How to
Deploy
Laravel
Application
on AWS EC2?


www.bacancytechnology.com
Introduction
Are you struggling to find an easy
tutorial on how to deploy Laravel
application on AWS EC2? Then here
is a blog for you to lessen your
hustle! Follow this step-by-step
guide to deploy your application on
Amazon EC2.
Tutorial
Takeaway
Working with Nginx
MySQL: Installation and
Configuration
Laravel: Basic Set-Up and
Project Creation
Deploy Laravel Application on
AWS EC2
You’d be learning about the
following topics for this tutorial.
Prerequisite
RDS
VPC
EC2 Instance: Visit create EC2
instance if have not yet created.
Make sure you have the following
resources to use.
Technical
Stack:
Deploy
Laravel
Application
on AWS EC2
Ubuntu
Nginx
PHP7.2-FPM
To host our Laravel app on Amazon
EC2 we will be using the following
technical stack.
Login to EC2
Instance
Use the following command for
logging in to your EC2 instance.


$ ssh -i “pemfilename”
username@ipaddress


Provide us with your
requirements; We will hustle to
lessen your hustles!


Bacancy provides the Best AWS
Architects to Manage AWS Cloud
Services for your project! Get in
touch with us today to hire AWS
experts without wasting your
time!
Install Nginx
First of all, run the command to
update the libraries with the latest
packages.


$ sudo apt-get update
Get superuser permissions.


$ sudo su


Using the previous variable, add the
repository. Then, press enter to
confirm.
$ add-apt-repository
ppa:nginx/$nginx
$ sudo apt install nginx
Once done with the installation,
check NGINX version.
$ nginx -V
Install and
Configure
MySQL
Using AWS EC2 as Localhost
Using AWS RDS DB Instance
There are two ways to install a MySQL
database.




Using AWS EC2 as
Localhost


Install MySQL in Ubuntu by
running the below command.
sudo apt-get update
sudo apt install mysql-server
sudo mysql_secure_installation
Now, open the MySQL prompt.
sudo mysql


Once we are done with the
installation process use the below
command to configure the root
account with an authentication
password.
ALTER USER 'root'@'localhost'
IDENTIFIED WITH
mysql_native_password BY
'very_your_password';
Flush the privileges (changes)
FLUSH PRIVILEGES;




Using AWS RDS DB
Instance


For creating a MySQL database
instance, go to the link below,
there is a step-by-step guide:
Create a MySQL DB instance
and connect to a database
Since we are done with
configuring our database let’s
move towards
the Laravel project setup. If you
are familiar with the initial
setup of laravel then feel free to
skip the next section and jump
to the deployment section
Develop and Deploy with
Bacancy!
Looking for top-notch
developers with extraordinary
problem-solving skills to
accomplish your requirements?
Contact us now and
hire DevOps developer.
Laravel
Project
Set-Up
Install PHP with CLI


sudo apt update
sudo apt install php-cli unzip
cd ~
Download the
composer globally
using the command


curl -sS
https://getcomposer.org/installer
-o /tmp/composer-setup.php
HASH=`curl -sS
https://composer.github.io/install
er.sig`
Verify the hash and
installation script


echo $HASH
Verify the installation script for
the composer.
php -r "if (hash_file('SHA384',
'/tmp/composer-setup.php')
=== '$HASH')
{
echo 'Installer verified';
}
else
{
echo 'Installer corrupt';
unlink('composer-setup.php');
}
echo PHP_EOL;"
Install the composer in
/usr/local/bin directory


sudo php /tmp/composer-
setup.php
--install-dir=/usr/local/bin --
filename=composer


Check composer
version


composer -v
Create the
Laravel App
and Deploy
your
Application
Create the Laravel project
composer create-project
laravel/laravel demo
cd demo
Install composer in
the preferable
directory


composer install
Copy .env file from
.env.example and add the
following changes. In case
you’re using RDS then you
need to configure it with RDS
creds.


cp .env.example .env
DB_DATABASE=dabasename
DB_USERNAME=root
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=3306
Migrate the database
php artisan migrate


Run the server


php artisan serve
Now move your Laravel demo
code to /var/www/html.






cd /demo /var/www/html


Configure Virtual Host
on Nginx


Moving towards the final step-
change the Nginx configuration file
as per your requirements to deploy
the application.
sudo nano /etc/nginx/sites-
available/default
After changing the default virtual host
file, your file would look like something
like this.
server {
listen 80;
server_name localhost;
root
/var/www/html/demo/public;
add_header X-Frame-Options
"SAMEORIGIN";
add_header X-Content-Type-
Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/
/index.php?$query_string;
}
location = /favicon.ico {
access_log off; log_not_found off; }
location = /robots.txt { access_log
off; log_not_found off; }
error_page 404 /index.php;
location ~ .php$ {
fastcgi_pass
unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param
SCRIPT_FILENAME
$realpath_root$fastcgi_script_name
;
include fastcgi_params;
}
location ~ /.(?!well-known).* {
deny all;
}
}


Save the file and run the following
commands to verify the Nginx
syntax and restart Nginx for
loading your changes.
sudo nginx -t
sudo service nginx restart
Conclusion
So, this was about how to deploy
laravel application on AWS EC2.
What are you waiting for? Go try
these steps and host your
application as well! For more such
cloud tutorials, feel free to visit the
Cloud tutorials page and start
learning! Write us back your
suggestions and feedback; we’d love
to hear from you!
Thank You!
www.bacancytechnology.com

More Related Content

PDF
AWS IoTにおけるデバイスへの認証情報のプロビジョニング
PDF
Introducción a la programación en Tryton
ODP
An introduction to SQLAlchemy
PDF
Red Hat Openshift Container Platform
PDF
AWS の IoT 向けサービス
PDF
AWS Fargate와 Amazon ECS를 활용한 CI/CD 모범사례 - 유재석, AWS 솔루션즈 아키텍트 :: AWS Game Mast...
PPTX
Spring Framework Petclinic sample application
PDF
Microservices Design Patterns | Edureka
AWS IoTにおけるデバイスへの認証情報のプロビジョニング
Introducción a la programación en Tryton
An introduction to SQLAlchemy
Red Hat Openshift Container Platform
AWS の IoT 向けサービス
AWS Fargate와 Amazon ECS를 활용한 CI/CD 모범사례 - 유재석, AWS 솔루션즈 아키텍트 :: AWS Game Mast...
Spring Framework Petclinic sample application
Microservices Design Patterns | Edureka

What's hot (13)

PDF
AWS glue technical enablement training
PPTX
비즈니스 차별화, 민첩성 확보, 리스크 회피를 위한 클라우드 마이그레이션::김효정 (AWS솔루션즈 아키텍트)
PDF
コンテンツ配信: CloudFront & 名前解決サービス: Route 53 詳細 -ほぼ週刊AWSマイスターシリーズ第3回-
PDF
Rest api 테스트 수행가이드
PDF
A First Look at the DB2 10 DSNZPARM Changes
PDF
Amazon Simple Workflow Service (SWF)
PDF
Amazon EKS로 간단한 웹 애플리케이션 구축하기 - 김주영 (AWS) :: AWS Community Day Online 2021
PDF
Domain-Driven-Design 정복기 1탄
PPTX
ASP.MVC Training
PPTX
마이크로서비스 아키텍처로 개발하기
PPTX
Casos de uso de negocios y sistemas
PDF
롯데닷컴의 AWS 클라우드 활용 사례 - AWS Summit Seoul 2017
PDF
AWS初心者向けWebinar RDBのAWSへの移行方法(Oracleを例に)
AWS glue technical enablement training
비즈니스 차별화, 민첩성 확보, 리스크 회피를 위한 클라우드 마이그레이션::김효정 (AWS솔루션즈 아키텍트)
コンテンツ配信: CloudFront & 名前解決サービス: Route 53 詳細 -ほぼ週刊AWSマイスターシリーズ第3回-
Rest api 테스트 수행가이드
A First Look at the DB2 10 DSNZPARM Changes
Amazon Simple Workflow Service (SWF)
Amazon EKS로 간단한 웹 애플리케이션 구축하기 - 김주영 (AWS) :: AWS Community Day Online 2021
Domain-Driven-Design 정복기 1탄
ASP.MVC Training
마이크로서비스 아키텍처로 개발하기
Casos de uso de negocios y sistemas
롯데닷컴의 AWS 클라우드 활용 사례 - AWS Summit Seoul 2017
AWS初心者向けWebinar RDBのAWSへの移行方法(Oracleを例に)
Ad

Similar to How to deploy laravel application on aws ec2 (20)

PPTX
PDF
Deploying your rails application to a clean ubuntu 10
PDF
Ansible Tutorial.pdf
PDF
Ansible - Hands on Training
PDF
Continuous Deployment @ AWS Re:Invent
PDF
Create rails project
PPTX
Just Another Word Press Weblog But More Cloudy
PPTX
TechnoramaNL Azure Key Vault, Azure Dev Ops and Azure Data Factor
PPT
Scaling drupal horizontally and in cloud
PPTX
Breaking Up With Your Data Center Presentation
PDF
Auto scaling applications in 10 minutes (CakeFest 2013)
DOCX
Connect sql-using-perl-from-linux
PDF
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
PPTX
Laravel Tutorial PPT
PDF
From Docker Straight to AWS
PDF
How to Install WordPress on AWS.pdf
PDF
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
PDF
Scaling on EC2 in a fast-paced environment (LISA'11 - Full Paper)
PDF
Dockerize Laravel Application
Deploying your rails application to a clean ubuntu 10
Ansible Tutorial.pdf
Ansible - Hands on Training
Continuous Deployment @ AWS Re:Invent
Create rails project
Just Another Word Press Weblog But More Cloudy
TechnoramaNL Azure Key Vault, Azure Dev Ops and Azure Data Factor
Scaling drupal horizontally and in cloud
Breaking Up With Your Data Center Presentation
Auto scaling applications in 10 minutes (CakeFest 2013)
Connect sql-using-perl-from-linux
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Laravel Tutorial PPT
From Docker Straight to AWS
How to Install WordPress on AWS.pdf
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
Scaling on EC2 in a fast-paced environment (LISA'11 - Full Paper)
Dockerize Laravel Application
Ad

More from Katy Slemon (20)

PDF
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
PDF
Data Science Use Cases in Retail & Healthcare Industries.pdf
PDF
How Much Does It Cost To Hire Golang Developer.pdf
PDF
What’s New in Flutter 3.pdf
PDF
Why Use Ruby On Rails.pdf
PDF
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
PDF
How to Implement Middleware Pipeline in VueJS.pdf
PDF
How to Build Laravel Package Using Composer.pdf
PDF
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
PDF
How to Develop Slack Bot Using Golang.pdf
PDF
IoT Based Battery Management System in Electric Vehicles.pdf
PDF
Understanding Flexbox Layout in React Native.pdf
PDF
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
PDF
New Features in iOS 15 and Swift 5.5.pdf
PDF
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
PDF
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
PDF
Flutter Performance Tuning Best Practices From the Pros.pdf
PDF
Angular Universal How to Build Angular SEO Friendly App.pdf
PDF
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
PDF
Ruby On Rails Performance Tuning Guide.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
How Much Does It Cost To Hire Golang Developer.pdf
What’s New in Flutter 3.pdf
Why Use Ruby On Rails.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How to Implement Middleware Pipeline in VueJS.pdf
How to Build Laravel Package Using Composer.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
How to Develop Slack Bot Using Golang.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
Understanding Flexbox Layout in React Native.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
New Features in iOS 15 and Swift 5.5.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
Ruby On Rails Performance Tuning Guide.pdf

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
Teaching material agriculture food technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Spectroscopy.pptx food analysis technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
20250228 LYD VKU AI Blended-Learning.pptx
Teaching material agriculture food technology
MIND Revenue Release Quarter 2 2025 Press Release
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Digital-Transformation-Roadmap-for-Companies.pptx
Chapter 3 Spatial Domain Image Processing.pdf
sap open course for s4hana steps from ECC to s4
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
Spectral efficient network and resource selection model in 5G networks
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

How to deploy laravel application on aws ec2

  • 1. How to Deploy Laravel Application on AWS EC2? www.bacancytechnology.com
  • 3. Are you struggling to find an easy tutorial on how to deploy Laravel application on AWS EC2? Then here is a blog for you to lessen your hustle! Follow this step-by-step guide to deploy your application on Amazon EC2.
  • 5. Working with Nginx MySQL: Installation and Configuration Laravel: Basic Set-Up and Project Creation Deploy Laravel Application on AWS EC2 You’d be learning about the following topics for this tutorial.
  • 7. RDS VPC EC2 Instance: Visit create EC2 instance if have not yet created. Make sure you have the following resources to use.
  • 9. Ubuntu Nginx PHP7.2-FPM To host our Laravel app on Amazon EC2 we will be using the following technical stack.
  • 11. Use the following command for logging in to your EC2 instance. $ ssh -i “pemfilename” username@ipaddress Provide us with your requirements; We will hustle to lessen your hustles! Bacancy provides the Best AWS Architects to Manage AWS Cloud Services for your project! Get in touch with us today to hire AWS experts without wasting your time!
  • 13. First of all, run the command to update the libraries with the latest packages. $ sudo apt-get update Get superuser permissions. $ sudo su Using the previous variable, add the repository. Then, press enter to confirm. $ add-apt-repository ppa:nginx/$nginx $ sudo apt install nginx
  • 14. Once done with the installation, check NGINX version. $ nginx -V
  • 16. Using AWS EC2 as Localhost Using AWS RDS DB Instance There are two ways to install a MySQL database. Using AWS EC2 as Localhost Install MySQL in Ubuntu by running the below command. sudo apt-get update sudo apt install mysql-server sudo mysql_secure_installation
  • 17. Now, open the MySQL prompt. sudo mysql Once we are done with the installation process use the below command to configure the root account with an authentication password. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_your_password';
  • 18. Flush the privileges (changes) FLUSH PRIVILEGES; Using AWS RDS DB Instance For creating a MySQL database instance, go to the link below, there is a step-by-step guide: Create a MySQL DB instance and connect to a database Since we are done with configuring our database let’s move towards
  • 19. the Laravel project setup. If you are familiar with the initial setup of laravel then feel free to skip the next section and jump to the deployment section Develop and Deploy with Bacancy! Looking for top-notch developers with extraordinary problem-solving skills to accomplish your requirements? Contact us now and hire DevOps developer.
  • 21. Install PHP with CLI sudo apt update sudo apt install php-cli unzip cd ~
  • 22. Download the composer globally using the command curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php HASH=`curl -sS https://composer.github.io/install er.sig`
  • 23. Verify the hash and installation script echo $HASH Verify the installation script for the composer. php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
  • 24. Install the composer in /usr/local/bin directory sudo php /tmp/composer- setup.php --install-dir=/usr/local/bin -- filename=composer Check composer version composer -v
  • 25. Create the Laravel App and Deploy your Application
  • 26. Create the Laravel project composer create-project laravel/laravel demo cd demo Install composer in the preferable directory composer install
  • 27. Copy .env file from .env.example and add the following changes. In case you’re using RDS then you need to configure it with RDS creds. cp .env.example .env DB_DATABASE=dabasename DB_USERNAME=root DB_PASSWORD=your_password DB_HOST=localhost DB_PORT=3306
  • 28. Migrate the database php artisan migrate Run the server php artisan serve
  • 29. Now move your Laravel demo code to /var/www/html. cd /demo /var/www/html Configure Virtual Host on Nginx Moving towards the final step- change the Nginx configuration file as per your requirements to deploy the application. sudo nano /etc/nginx/sites- available/default
  • 30. After changing the default virtual host file, your file would look like something like this. server { listen 80; server_name localhost; root /var/www/html/demo/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type- Options "nosniff"; index index.php; charset utf-8;
  • 31. location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ .php$ { fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name ; include fastcgi_params; }
  • 32. location ~ /.(?!well-known).* { deny all; } } Save the file and run the following commands to verify the Nginx syntax and restart Nginx for loading your changes. sudo nginx -t sudo service nginx restart
  • 34. So, this was about how to deploy laravel application on AWS EC2. What are you waiting for? Go try these steps and host your application as well! For more such cloud tutorials, feel free to visit the Cloud tutorials page and start learning! Write us back your suggestions and feedback; we’d love to hear from you!