Skip to content

Instantly share code, notes, and snippets.

@alexelev
Created April 28, 2020 19:31
Show Gist options
  • Save alexelev/d3f2ea706aea5982d988f0958ee617b6 to your computer and use it in GitHub Desktop.
Save alexelev/d3f2ea706aea5982d988f0958ee617b6 to your computer and use it in GitHub Desktop.
Deploy Laravel app on Amazon EC2
# Deploy Laravel app on Amazon EC2
1. Create EC2 instance. Add to EC2 Security Group rules for accessing by SSH and HTTP protocols.
2. Server stuff:
+ Change `/etc/apache2/sites-available/000-default.conf` by adding:
```
DocumentRoot /var/www/html/public
<Directory /var/www/html/public/>
AllowOverride All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
```
+ exec `sudo a2enmod rewrite`
+ exec `sudo systemctl restart apache2`
3. Install php 7.4:
+ `sudo apt-get update`
+ `sudo add-apt-repository ppa:ondrej/php`
+ `sudo apt-get update && sudo apt-get upgrade`
+ `sudo apt -y install php7.4`
+ `sudo apt-get install -y php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip,xml}`
4. Install composer:
+ `sudo apt install wget php-cli php-zip unzip`
+ `php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"`
+ `HASH="$(wget -q -O - https://composer.github.io/installer.sig)"`
+ `php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"`
+ `sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer`
5. Install nodejs
+ `curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -`
+ `sudo apt-get install nodejs`
6. [Add Swap](https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04) to prevent a composer issues
+ `sudo dd if=/dev/zero of=/swapfile count=20148 bs=1MiB`
+ `sudo chmod 600 /swapfile`
+ `sudo mkswap /swapfile`
+ `sudo swapon /swapfile`
+ `swapon -s`
7. Create or clone project into `/var/www/html`, set config
8. Create RDS. Add to EC2 Security Group rules for accessing by specific protocol (for MySQL 3306).
9. In .env-file of your project set up data from RDS.
10. Run migration and seed the data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment