Skip to content

Instantly share code, notes, and snippets.

@notflip
Last active October 10, 2017 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notflip/d6e49d19da4c65599b64bbffc2b7a06e to your computer and use it in GitHub Desktop.
Save notflip/d6e49d19da4c65599b64bbffc2b7a06e to your computer and use it in GitHub Desktop.
AWS EC2 LEMP Setup
cat ~/.ssh/id_rsa.pub | ssh -i "#DOMAIN#.pem" ubuntu@ec2-#DOMAIN-IP#.eu-central-1.compute.amazonaws.com "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
# SSH into the instance
ssh -i "#DOMAIN#.pem" ubuntu@ec2-#DOMAIN-IP#.eu-central-1.compute.amazonaws.com
# Update Packages and install Nginx
sudo apt-get update
sudo apt-get install -y nginx composer git
# Install and setup MySQL
sudo apt-get install -y mysql-server
mysql_secure_installation
# Get the PHP71 Repository
sudo apt-get install -y python-software-properties
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update -y
# Show all packages available for PHP71
apt-cache pkgnames | grep php7.1
# Install PHP71 and configure
sudo apt-get install -y php7.1 php7.1-fpm php7.1-mysql php7.1-dom php7.1-curl php7.1-mcrypt php7.1-zip
sudo (nano|vi|whatever) /etc/php/7.1/fpm/php.ini
{Search for cgi.fix_pathinfo, uncomment and set the value to 0}
{Exit Vim}
sudo systemctl restart php7.1-fpm
# Create the server blocks
sudo mkdir -p /var/www/#DOMAIN#
sudo chown -R $USER:$USER /var/www/#DOMAIN#
sudo chmod -R 755 /var/www
# Copy the default server block
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/#DOMAIN#
sudo (nano|vi|whatever) /etc/nginx/sites-available/#DOMAIN#
# SSL?
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install -y python-certbot-nginx
{Uncomment the PHP block and the FPM line}
{Uncomment the .ht line and leave to deny all}
{Exit vi|nano}
sudo systemctl reload nginx
sudo ln -s /etc/nginx/sites-available/#DOMAIN#.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
# Set the correct permissions
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment