Skip to content

Instantly share code, notes, and snippets.

@EmadAdly
Last active December 9, 2020 15:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EmadAdly/75630ddcead565e98b26c73004681564 to your computer and use it in GitHub Desktop.
Save EmadAdly/75630ddcead565e98b26c73004681564 to your computer and use it in GitHub Desktop.
Deploying Laravel app in Amazon Ec2 or Lightsail

1- Creating the Lightsail or EC2 Instance

create a new Lightsail instance or EC2 instance From the AWS Management Console.

2- Connecting to the new instance

Once you create it, download the associated .pem file. you can be downloaded the default SSH key from your account page. we need to move it to the ~/.ssh directory. You can do so by executing

mv ~/Downloads/pemfile.pem ~/.ssh/pemfile.pem

if the directory might not exist. You can create the directory by

mkdir ~/.ssh

now change permissions for our .pem file. We can do so by executing

sudo chmod 600 ~/.ssh/pemfile.pem

to connect remotely to our instance, we can do so by executing

ssh -i ~/.ssh/pemfile.pem ec2-user@00.00.00.00

note: You can find your instance’s IP and username in either your EC2 or Lightsail dashboard.

3- Installing Apache2 in our AWS instance

we are going to install PHP 7.3, We will need to make sure you have the following package installed so you can add repositories

sudo apt-get install software-properties-common

You will need the repository from Ondrej

sudo add-apt-repository ppa:ondrej/apache2

Before installing Apache, you need to update the package list for upgrades and new packages.

sudo apt-get update

install Apache2

sudo apt-get install apache2

if you navigate to the public IP of the instance from a browser, you will see the familiar Apache Welcome Page.

4- Installing PHP in our AWS instance

now install the PHP 7.3 and several other packages

You will need the repository from Ondrej

sudo add-apt-repository ppa:ondrej/php

Before installing PHP, you need to update the package list for upgrades and new packages.

sudo apt-get update

install php 7.3

sudo apt-get install php7.3 php7.3-xml php7.3-gd php7.3-opcache php 7.3-mbstring

You can check your installed PHP version

php -v

1- Install the MySQL v8

To download the latest repositories, enter

wget –c https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.deb

first before we go, need root password to use it in installation steps.

if you don't have you can change root password by this command

sudo passwd

To install the repositories, enter the command:

sudo dpkg –i mysql-apt-config_0.8.13-1_all.deb

Any time you’re installing new software, you should refresh the software cache to ensure you are installing the latest release

sudo apt-get update

install mysql

sudo apt install mysql-server

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