Skip to content

Instantly share code, notes, and snippets.

@sidben
Last active October 25, 2022 17:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidben/4a0bbb3780b035fd965d2120593d4801 to your computer and use it in GitHub Desktop.
Save sidben/4a0bbb3780b035fd965d2120593d4801 to your computer and use it in GitHub Desktop.
Script to setup NGINX / PHP for Laravel projects on AWS EC2 instances running Ubuntu (20.04)
#!/bin/bash
sudo apt update -y && sudo apt upgrade -y
sudo apt install zip unzip certbot python3-certbot-nginx software-properties-common -y
# AWS
sudo apt install awscli -y
# Remove Apache, Install NGINX
sudo systemctl stop apache2 && sudo systemctl disable apache2
sudo apt remove apache2 -y
sudo apt autoremove -y
sudo apt install nginx -y
# PHP 7.4
sudo apt install php7.4 php7.4-fpm php7.4-cli -y
sudo apt install php-common php-bcmath php-curl php-mbstring php-mysql php-xml -y
# NGINX host config
sudo mkdir /var/www/html/public
sudo curl -o /etc/nginx/sites-available/default https://gist.githubusercontent.com/sidben/b5a1cdf2dd0aa8e66395ec7e0db3cf02/raw
sudo nginx -t && sudo nginx -s reload
# Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
# Supervisor
sudo apt install supervisor -y
#!/bin/bash
sudo apt update -y && sudo apt upgrade -y
sudo apt install zip unzip certbot python3-certbot-nginx software-properties-common -y
# AWS
sudo apt install awscli -y
# PHP 8
sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/nginx
sudo apt update -y && sudo apt upgrade -y
sudo apt install -y php8.1-fpm php8.1-cli
sudo apt install -y php8.1-bcmath php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-xml php8.1-zip
# NGINX host config
sudo mkdir /var/www/html/public
sudo curl -o /etc/nginx/sites-available/default https://gist.githubusercontent.com/sidben/aab921a9ad0297d2affcf6711e5fac40/raw
sudo nginx -t && sudo nginx -s reload
# Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
# Supervisor
sudo apt install supervisor -y
@sidben
Copy link
Author

sidben commented Oct 25, 2022

OBS: EC2 instance created today (t4.small) came with Nginx by default instead of Apache, so the lines were removed from the PHP 8 script.

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