Skip to content

Instantly share code, notes, and snippets.

@miftahafina
Created November 4, 2019 00:28
Show Gist options
  • Save miftahafina/762f7edf10b858b8a8df1ca863f83b99 to your computer and use it in GitHub Desktop.
Save miftahafina/762f7edf10b858b8a8df1ca863f83b99 to your computer and use it in GitHub Desktop.

AWS EC2, Ubuntu 16.04, PHP 7.1, NGINX, Laravel 5.5, MariaDB 10.2, Composer

DISCLAIMER: I will avoid using generic keywords so that you're forced to name things yourself:

test, example, default, key, 10.174.75.99

latvija, pupper, elvisoctp, ilunimati-top-security, 10.10.10.1000000000

AWS EC2 Ubuntu 16.04 Setup

Services -> EC2 -> Launch Instance -> Select "Ubuntu Server 16.04 LTS (HVM), SSD Volume Type"

Step 6: Configure Security Group

ilunimati-top-security | created 2017-11-27T11:03:41.775-06:00

HTTP TCP 80 0.0.0.0/0
HTTP TCP 80 ::/0
SSH TCP 22 0.0.0.0/0
SSH TCP 22 ::/0
HTTPS TCP 443 0.0.0.0/0
HTTPS TCP 443 ::/0

Create a new key pair, name the key (pupper), download the key

chmod 400 ~/pupper.pem

Click on View Instances, select your instance and in "Description" tab you will find your IPv4:

IPv4 Public IP 10.10.10.1000000000

When instance's status: 2/2 checks passed, let's SSH into it

ssh -i pupper.pem ubuntu@10.10.10.1000000000

...
Are you sure you want to continue connecting (yes/no)? yes

Setup

Remove Apache

sudo apt-get remove apache2*
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /etc/apache2 /var/lib/apache2 /var/lib/apache2

PHP 7.1

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm php7.1-curl
php --ini |grep Loaded
sudo vi /etc/php/7.1/cli/php.ini

/cgi.fix_pathinfo
Enter
n
h
x
Shift+4
r
0
:wq

sudo systemctl restart php7.1-fpm.service

Nginx

sudo apt-get install nginx

sudo vi /etc/nginx/sites-available/memes

Paste this snippet, adjust server_name (10.10.10.1000000000 lel...):

server {
        listen 80;
        
        server_name 10.10.10.1000000000 lelmao-xd-Kappa123.com www.lelmao-xd-Kappa123.com;
        
        root /var/www/laravel/public;
        
        index index.php;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        location ~ /\.ht {
                deny all;
        }
}

Make symbolic link, remove garbage:

sudo ln -s /etc/nginx/sites-available/memes /etc/nginx/sites-enabled/memes

sudo nginx -t

sudo systemctl restart nginx.service
sudo systemctl enable nginx.service
sudo systemctl enable php7.1-fpm.service

sudo rm -rf /var/www/html

(Optional) Test

sudo mkdir -p /var/www/laravel/public
sudo bash -c 'echo "STEAM (A for ARTS)" > /var/www/laravel/public/index.php'

Visit your page (IPv4 address), you should be presented w/ STEAM (A for ARTS)

sudo rm -rf /var/www/laravel

Composer

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Type composer, last returned thing might be:

why-not Shows which packages prevent the given package from being installed.

Database (MariaDB 10.2)

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirrors.accretive-networks.net/mariadb/repo/10.2/ubuntu xenial main'

sudo apt update
sudo apt install mariadb-server

Type "mysql -V", you should see:

mysql Ver 15.1 Distrib 10.2.12-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Official source

Database setup

mysql -u root -p

CREATE DATABASE memecentral DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON memecentral.* TO 'elvisoctp'@'localhost' IDENTIFIED BY 'latvija';
FLUSH PRIVILEGES;
exit;

PHPUnit & Laravel

sudo apt install phpunit
cd /var/www
sudo composer create-project --prefer-dist laravel/laravel laravel
cd laravel
sudo vi .env

Update these environment variables:

APP_ENV=production
APP_DEBUG=false
APP_URL=http://10.10.10.100000000

DB_DATABASE=memecentral
DB_USERNAME=elvisoctp
DB_PASSWORD=latvija

Save and exit (:wq), then:

php artisan migrate

Finally:

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

Visit your page: http://10.10.10.100000000

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