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:will generate an appropriate localhost configuration, use thephp artisan deploy:init your.domain.com -f
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.
Go to the Meta tab of your application page on Forge and change it to the /current/public
directory.
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;
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.
- 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 thephp_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.