Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jgravois's avatar

How can I add a series of commands to Forge's Quick Deploy

I have to run these commands after every deployment or else I lose all of my symbolic links in production.

cd public
rm avatars
rm forms
rm media
rm occms
rm tickets
cd ..
php artisan storage:link

This is the current deploy script

cd /home/forge/www.my-uam.com
git stash
git pull origin master
$FORGE_COMPOSER install --no-interaction --prefer-dist --optimize-autoloader

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

if [ -f artisan ]; then
    $FORGE_PHP artisan migrate --force
fi
0 likes
4 replies
devingray_'s avatar

You can use a composer hook for this

post-install-cmd

Create a new Laravel Command that does all of what you need it to do.

Then in your composer.json

add this to your scripts

"scripts": {
        "pre-install-cmd": [
            "@php artisan your:command "
        ],
    }

This will run the command anytime composer installs.

A second option would be to handle the command in the deploy script

cd /home/forge/www.my-uam.com
git stash
git pull origin master
$FORGE_COMPOSER install --no-interaction --prefer-dist --optimize-autoloader

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

if [ -f artisan ]; then
    $FORGE_PHP artisan migrate --force
    $FORGE_PHP artisan your:command
fi
berestnevao27@gmail.com's avatar

I’ve used Lar­avel Forge for quite a while in my work­flow. It’s a con­ve­nient way to set up servers, quick­ly add secu­ri­ty cer­tifi­cates, and deploy sites. I’ve got a num­ber of my own sites and client sites using it and I’ve been very pleased with it.

https://www.indigocard.one/

jgravois's avatar

This is the start of my command (never written one like THIS before):

public function handle(): int
    {
        exec("cd public");
        exec("pwd", $output);

        $this->comment( implode( PHP_EOL, $output ) );

        return 0;
    } // end function

The output is /Users/jongravois/code/eight which is the root of the app. It appears as though it ignored the ``change directory``` command.

devingray_'s avatar
Level 8
public function handle(): int
    {
        collect(['avatars', 'forms', 'media', 'occms', 'tickest'])
            ->each(function ($item) {
                File::delete(public_path($item));
            });
        $this->call('storage:link');

        return 0;
    }

Please or to participate in this conversation.