Skip to content

Instantly share code, notes, and snippets.

@HakamRaza
Last active October 18, 2022 05:04
Show Gist options
  • Save HakamRaza/ca6fa79f6883f335f4963bdf3049017f to your computer and use it in GitHub Desktop.
Save HakamRaza/ca6fa79f6883f335f4963bdf3049017f to your computer and use it in GitHub Desktop.
LEMP Re-Deployment (LEMP, AutoScale)
### GitHub ###
- Create new release for master branch after merging
- run production instance
- ssh to prod server
$ ssh -i "your_pem.pem" ubuntu@<your public dns>.compute.amazonaws.com
### Ubuntu Console ###
$ sudo supervisorctl stop all
$ cd /var/www/<laravel app directory>
$ sudo git fetch
$ sudo git checkout <tag branch/ master>
- optional command depend on needs
- migrate table
$ sudo php artisan migrate
- seed class
$ php artisan db:seed —class=<seeder file>
- edit env file
$ sudo nano .env
- edit scheduler
$ sudo crontab -e
- edit queue worker
$ sudo nano /etc/supervisor/conf.d/laravel-worker.conf
- has changes in route (clear cache & re-caching)
$ php artisan route:cache
- has package change
$ composer install –no-dev
- purge revoked and expired tokens and auth codes...
$ php artisan passport:purge
$ chmod 775 storage/framework/cache
$ chmod 775 storage/framework/cache/data
$ sudo chgrp www-data storage/framework/cache
$ sudo chgrp www-data storage/framework/cache/data
$ php artisan queue:restart
$ php artisan config:clear
$ php artisan cache:clear
- update BUGSNAG_APP_VERSION inside env to latest release version.
- exit and stop server
### Create Branch AMI ###
ec2 > <deployment instance> > action > image and templates > create image
- image name : PROJECT_NAME-VERSION
- tag 'project': PROJECT_NAME,
- wait created and then copy created AMI id
### Launch Configuration ###
ec2 > Auto Scaling > Launch Configuration
- create new launch config
- paste AMI id
- name same as AMI
- use same security group as previous LC
- existing key pair: deployment server key
- instance type: same as previous
### Auto Scaling Group ###
ec2 > Auto Scaling > Auto Scaling Groups
- edit ASG by choose latest LC created
- replace previous auto scaling instance by:
- increase temporary the group min to 2, which will created 2 auto scaling instance inside instance list
- wait status running/ complete
- after complete, change back to 1, it will terminate previous (older) auto scaling instance
### Clean Up ###
- ssh into auto scaling instance
$ chmod 775 storage/framework/cache
$ chmod 775 storage/framework/cache/data
$ sudo chgrp www-data storage/framework/cache
$ sudo chgrp www-data storage/framework/cache/data
$ php artisan queue:restart
$ php artisan config:clear
$ php artisan cache:clear
$ supervisorctl restart all
- ssh back into deployment instance
$ php artisan queue:restart
$ php artisan config:clear
$ php artisan cache:clear
$ supervisorctl restart all
- STOP deployment instance
- optional
- remove all snapshot except latest 2 as backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment