This tutorial demonstrates how anyone can implement zero-downtime deployments when using https://forge.laravel.com/ without using https://envoyer.io. To do that we will use https://laravel.com/docs/master/envoy, a tool that helps setup tasks during deployment using Blade syntax.

Envoyer offers a wide range of features that can streamline your deployment process and provide a user-friendly interface

@servers(['production' => '127.0.0.1']) @setup $repository = 'https://chrysanthos.xyz/cdn-cgi/l/email-protection:yourorganization/yourprojectname.git'; $releasesPath = '/home/forge/yoursitename/releases'; $siteRootDirectory = '/home/forge/yoursitename'; $release = date('YmdHis'); $newReleaseDirectory = $releasesPath.'/'. $release; @endsetup @story('deploy') build activate @endstory @task('build') echo 'Cloning repository' git clone --depth 1 {{ $repository }} {{ $newReleaseDirectory }} echo 'Enter New Release directory' cd {{ $newReleaseDirectory }} @if ($commit) echo 'Switching to specific commit with git reset --hard {{ $commit }}' git reset --hard {{ $commit }} @endif echo 'Install composer dependencies' composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist --no-dev --optimize-autoloader php artisan optimize:clear echo 'Linking.env file' ln -nfs {{ $siteRootDirectory }}/.env {{ $newReleaseDirectory }}/.env npm i npm run prod @endtask @task('activate', ['on' => 'production']) echo "Linking storage directory" rm -rf {{ $newReleaseDirectory }}/storage ln -nfs {{ $siteRootDirectory }}/storage {{ $newReleaseDirectory }}/storage cd {{ $newReleaseDirectory }} php artisan optimize php artisan migrate --force php artisan storage:link php artisan nova:publish php artisan horizon:publish echo 'Linking current release' ln -nfs {{ $newReleaseDirectory }} {{ $siteRootDirectory }}/current php artisan horizon:terminate ( flock -w 10 9 || exit 1 echo 'Restarting FPM...'; sudo -S service php8.2-fpm reload ) 9>/tmp/fpmlock @endtask
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners