Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 3.01 KB

how-to-forge.md

File metadata and controls

57 lines (42 loc) · 3.01 KB

How to deploy with Laravel Forge?

Set up your deploy.php

Enabling a localhost access is particularly helpful when using Laravel Forge to maintain your servers. Simply set up your configurations by using the forge user and the /home/forge/your.domain.com deployment path. If your ~/.ssh/id_rsa SSH key is already registered within forge, you're good to go. Otherwise you can configure which SSH key and configs to use.

set('default_stage', 'prod');

host('your.domain.com')
    ->stage('prod')
    ->set('deploy_path', '/home/forge/your.domain.com')
    ->user('forge');

localhost()
    ->stage('local')
    ->set('deploy_path', '/home/forge/your.domain.com')
    ->user('forge');

🔥 Pro tips:

  • When generating your deploy.php file, running:
    php artisan deploy:init your.domain.com -f
    will generate an appropriate localhost configuration, use the forge user and provide better default values when asking you questions.
  • Combine with the -a (--all) option to skip any console interaction whilst using a maximum of features — npm, migrations, horizon, etc.

Update web directory

Go to the Meta tab of your application page on Forge and change it to the /current/public directory.

Enter /current/public on Meta > Update Web Directory

Make OPcache work with symlinks

Next, you need to pass the real application path instead of the symlink path to PHP FPM. Otherwise, PHP's OPcache may not properly detect changes to your PHP files. Add the following lines after the rest of your fastcgi configurations in the location block of your nginx configurations.

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;

Edit your nginx configuration file

Add more fastcgi configs to your location block

Edit your deploy script

Your deploy script in Forge is now unnecessary since your whole deployment logic is define by Laravel Deployer. Replace it with the following script to deploy using Laravel Deployer when you deloy in Forge.

cd /home/forge/your.domain.com/current
php artisan deploy local

Now if you have Quick Deploy turned on, every time you push to your repository, it will deploy using Laravel Deployer.

Extra things to configure

  • If you wish to reload php-fpm after each deployment like Forge does by default, you will need to use the fpm:reload task and set up your version of php-fpm within the php_fpm_service option. Read more here.
  • If you have a Daemon running Horizon in Forge, read this to make sure it restarts after each deployment.