Link demo: Fashion Shop
-
Create EC2 Instance
https://www.howtoforge.com/how-to-create-an-ec2-instance-on-aws/ -
To host our Laravel app on Amazon EC2 we will be using the following technical stack:
- PHP 8.0
- Composer
- Mysql
- Nginx
--------------------------------------------------Setup project--------------------------------------------------
- Permission Folder:
sudo chown -R www-data:www-data /var/www
- Clone project:
cd /var/www
git clone https://github.com/Vo-Huy-Khoa/fashion-shop-laravel.git
--------------------------------------------------Install PHP--------------------------------------------------
- updating your package list by running the following command:
sudo apt-get update
- Add the ondrej/php PPA using the following commands:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
- Once the PPA is added and your package list is updated, try installing the packages again:
sudo apt-get install php8.0-common php8.0-mysql php8.0-cgi php8.0-mbstring php8.0-curl php8.0-gd php8.0-xml php8.0-xmlrpc php-pear php8.0-fpm
--------------------------------------------------Install Composer---------------------------------------------
- Download the installer:
curl -sS https://getcomposer.org/installer -o composer-setup.php
- Verify the installer:
HASH="$(curl -sS https://composer.github.io/installer.sig)"
echo "$HASH composer-setup.php" | sha384sum -c -
- Install Composer:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- Verify the installation:
composer --version
--------------------------------------------------Install Mysql------------------------------------------------
- Install MySql
sudo apt update
sudo apt install mysql-server
sudo systemctl start mysql.service
- Set Password For Root
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
exit
- Create Database
sudo mysql -u root -p
CREATE DATABASE fashion;
exit
- Import File Sql To Database
mysql -u root -p fashion < shopfashion.sql
- When error password root:
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mật_khẩu_mới';
--------------------------------------------------Install Nginx------------------------------------------------
- Install Nginx
sudo apt install nginx
- Start Nginx
sudo systemctl start nginx
- Enable Nginx
sudo systemctl enable nginx
- Check status Nginx
sudo systemctl status nginx
- Check File Config Nginx
sudo nginx -t
- Restart Nginx
sudo systemctl restart nginx
--------------------------------------------------Config Nginx-------------------------------------------------
- To The File Config Nginx:
cd /etc/nginx/sites-available/
- To the file default:
sudo vim default
- Create Value In File Default:
server {
listen 80;
listen [::]:80;
root /var/www/fashion-shop-laravel/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/php8.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
- Check File Config Nginx
sudo nginx -t
--------------------------------------------------Config Laravel--------------------------------------------------
- Update Composer
composer update
- Generate Key
php artisan key:generate