Skip to content

Instantly share code, notes, and snippets.

@jaircuevajunior
Last active April 17, 2024 15:08
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 jaircuevajunior/93638cc77f60417edebdbceb1cdf2b3c to your computer and use it in GitHub Desktop.
Save jaircuevajunior/93638cc77f60417edebdbceb1cdf2b3c to your computer and use it in GitHub Desktop.
A simple guide to help myself setup a common LAmP environment on a AWS Ubuntu 18.04 instance with things that I should not forget

AWS EC2 Setup Guide

Enable Swap File (2GB)

fallocate -l 2G /swapfile &&\
chmod 600 /swapfile &&\
mkswap /swapfile &&\
swapon /swapfile &&\
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab &&\
free -h

Setup Timezone + System Update + Reboot

ln -fs /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime \
&& dpkg-reconfigure -f noninteractive tzdata \
&& apt-get update && apt-get dist-upgrade -y && reboot

Apache + PHP + Common tweaks

add-apt-repository ppa:ondrej/php -y &&\
add-apt-repository ppa:ondrej/apache2 -y &&\
apt-get update &&\
apt-get install apache2 php8.1-fpm php8.1-mysql php8.1-xml php8.1-mbstring php8.1-gd php8.1-curl php8.1-zip -y &&\
a2enmod proxy proxy_fcgi headers expires rewrite ssl &&\
sed -i 's/post_max_size.*/post_max_size = 500M/' /etc/php/*/fpm/php.ini &&\
sed -i 's/upload_max_filesize.*/upload_max_filesize = 500M/' /etc/php/*/fpm/php.ini &&\
apt-get install -y mysql-client &&\
echo "Done! =)"

Sample Apache Vhost

<VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com
        ServerAdmin junior@dinhost.com.br
        DocumentRoot "/var/www/site/public"

        ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
        CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined

        RewriteEngine On
        RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
        RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
        ServerName example.com
        ServerAlias www.example.com
        ServerAdmin junior@dinhost.com.br
        DocumentRoot "/var/www/site/public"

        ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
        CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined

        <Directory /var/www/site/public>
                Require all granted
                Options +FollowSymLinks
                AllowOverride All
        </Directory>

        <IfModule setenvif_module>
            SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
        </IfModule>
        <FilesMatch ".+\.ph(ar|p|tml)$">
            SetHandler "proxy:unix:/run/php/php8.1-fpm-site.sock|fcgi://localhost"
        </FilesMatch>
        <FilesMatch ".+\.phps$">
            Require all denied
        </FilesMatch>
        <FilesMatch "^\.ph(ar|p|ps|tml)$">
            Require all denied
        </FilesMatch>

        SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
        SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>

MySQL 5.7 on Ubuntu 20.04

wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb \
&& dpkg -i mysql-apt-config_0.8.12-1_all.deb \
&& sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29 \
&& apt-get update \
&& apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment