Organized Steps to Deploy a Laravel App on EC2 Instance Ubuntu 22.04 Nginx Server

Organized Steps to Deploy a Laravel App on EC2 Instance Ubuntu 22.04 Nginx Server

Steps to Deploy a Laravel App on EC2 Instance Ubuntu 22.04 Nginx Server.

  1. Create An EC2 Instance on AWS console
  2. Install Nginx Server
  3. Install PHP with required packages
  4. Install MySQL Database
  5. Deploy Laravel app using GitHub Action workflow


1.After AWS EC2 Instance Created

2.Connect with putty with ssh key

3.Install Nginx Server

  • sudo apt update
  • sudo apt install nginx
  • systemctl status nginx (to check status)
  • sudo systemctl restart nginx
  • sudo nginx -t

4.Install php with packages

  • sudo apt update
  • sudo apt install --no-install-recommends php8.1
  • sudo apt-get install php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath php8.1-fpm

# Install Composer (Php package manager)

  • curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
  • HASH=`curl -sS https://composer.github.io/installer.sig`
  • echo $HASH
  • 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;"
  • sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
  • composer

5.Install MySQL Database

  • sudo apt update
  • sudo apt install mysql-server
  • sudo mysql
  • ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your password';
  • sudo systemctl restart nginx
  • sudo systemctl restart php8.1-fpm

8.DIR Permission

  • sudo mkdir -p /var/www/html/
  • sudo chown -R ubuntu:ubuntu /var/www/html/

7. Now Deploy Laravel App on server?

File permissions

  • chmod -R ugo+rw storage/logs
  • mkdir -p framework/{sessions,views,cache}
  • chmod -R ugo+rw storage/framework

Set root

  • cd /etc/nginx/sites-available/
  • sudo nano default

# This file will automatically load configuration files provided by oth
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##


# Default server configuration
#
server {
? ? ? ? listen 80 default_server;
? ? ? ? listen [::]:80 default_server;


? ? ? ? # SSL configuration
? ? ? ? #
? ? ? ? # listen 443 ssl default_server;
? ? ? ? # listen [::]:443 ssl default_server;
? ? ? ? #
? ? ? ? # Note: You should disable gzip for SSL traffic.
? ? ? ? # See: https://bugs.debian.org/773332
? ? ? ? #
? ? ? ? # Read up on ssl_ciphers to ensure a secure configuration.
? ? ? ? # See: https://bugs.debian.org/765782
? ? ? ? #
? ? ? ? # Self signed certs generated by the ssl-cert package
? ? ? ? # Don't use them in a production server!
? ? ? ? #
? ? ? ? # include snippets/snakeoil.conf;


? ? ? ? root /var/www/sivakami-ecommerce-backend/public/;


? ? ? ? # Add index.php to the list if you are using PHP
? ? ? ? index index.php index.html index.htm index.nginx-debian.html;


? ? ? ? server_name _;


? ? ? ? location / {
? ? ? ? ? ? ? ? # First attempt to serve request as file, then
? ? ? ? ? ? ? ? # as directory, then fall back to displaying a 404.
? ? ? ? ? ? ? ? #try_files $uri $uri/ =404;
? ? ? ? ? ? ? ? try_files $uri $uri/ /index.php?$query_string;
? ? ? ? }


? ? ? ? # pass PHP scripts to FastCGI server
? ? ? ? #
? ? ? ? location ~ \.php$ {
? ? ? ? ? ? ? ? include snippets/fastcgi-php.conf;
? ? ? ? #
? ? ? ? #? ? ? ?# With php-fpm (or other unix sockets):
? ? ? ? ? ? ? ? fastcgi_pass unix:/run/php/php8.1-fpm.sock;
? ? ? ? #? ? ? ?# With php-cgi (or other tcp sockets):
? ? ? ? #? ? ? ?fastcgi_pass 127.0.0.1:9000;
? ? ? ? }


? ? ? ? # deny access to .htaccess files, if Apache's document root
? ? ? ? # concurs with nginx's one
? ? ? ? #
? ? ? ? #location ~ /\.ht {
? ? ? ? #? ? ? ?deny all;
? ? ? ? #}
}        


Please?share your thoughts, queries, and suggestions in the comments.

要查看或添加评论,请登录

Kabilraj Selvanantham的更多文章

社区洞察

其他会员也浏览了