Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laravel deploy script
# Change to the project directory
cd /home/forge/domain.com
# Turn on maintenance mode
php artisan down
# Pull the latest changes from the git repository
git pull origin master
# Install/update composer dependecies
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
# Run database migrations
php artisan migrate --force
# Clear caches
php artisan cache:clear
# Clear expired password reset tokens
php artisan auth:clear-resets
# Clear and cache routes
php artisan route:clear
php artisan route:cache
# Clear and cache config
php artisan config:clear
php artisan config:cache
# Install node modules
# npm install
# Build assets using Laravel Mix
# npm run production
# Turn off maintenance mode
php artisan up
@OlahTamas

This comment has been minimized.

Copy link

OlahTamas commented Jun 13, 2018

Hi, a small suggestion from personal experience: drop in a 'php artisan queue:restart' somewhere, if you use queue workers.

@tvbeek

This comment has been minimized.

Copy link

tvbeek commented Jun 14, 2018

If you add --no-dev it will not install the dev requirements (Like phpunit, faker and other packages that you don't need on production)

The composer command is then:
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev

@reindert-vetter

This comment has been minimized.

Copy link

reindert-vetter commented Jun 14, 2018

You better use this library. Then you do not have any downtime.
https://github.com/deployphp/deployer/blob/master/README.md

@BenSampo

This comment has been minimized.

Copy link
Owner Author

BenSampo commented Jun 14, 2018

@tvbeek, I've added --no-dev as per your suggestion, thanks!

@OlahTamas thanks for your suggestion too. I'm not going to add it because I think it's something you'll do as part of setting up queue workers for your application. It's per-project thing.

@freekmurze

This comment has been minimized.

Copy link

freekmurze commented Jun 15, 2018

That's a cool script! It's clear, it's simple, it's well made, it does the job 👍

The only downside is that there is some downtime involved for the users of the site.

For those interested I've made a more complex deploy script. That complexity buys you a near zero downtime deploy. The application is built in a separate directory and where it's ready a symlink to the public folder is set.

@jannejava

This comment has been minimized.

Copy link

jannejava commented Jun 16, 2018

Good job! Reloading PHP FPM service can also be a good idea if you are using OPCache.

@lorisleiva

This comment has been minimized.

Copy link

lorisleiva commented Jun 18, 2018

🔥 Cool script :) I am using something very similar on my package Laravel Deployer (a wrapper around DeployerPhp for Laravel applications that lets you deploy with zero downtime via a simple php artisan deploy).

@peterjaap

This comment has been minimized.

Copy link

peterjaap commented Jun 20, 2018

Extra tip; require https://github.com/erjanmx/laravel-migrate-check into your project and use php artisan migrate:check to see whether there are migrations to be run. If it returns a zero exit code, there are no migrations and you don't have to pull your site down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.