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

Cushty's avatar
Level 4

Forge deploy script

Hi, what is the best script to use in Forge? Ive seen:

Is this optimal? Thanks

0 likes
5 replies
Snapey's avatar

Why do you need to use other than the default?

You can just run optimize instead of poinlessly clearing caches and then caching (which clears anyway)

Cushty's avatar
Level 4

@Snapey Hi, so should you run optimize in script?

npm i && npm run build was not in the defaults, should i keep this? Sorry for the noob questions.

martinbean's avatar

@Cushty You’d run npm i && npm run build if you have assets you need building with Vite.

Cushty's avatar
Level 4

@martinbean thank mate, yeah I ran with those npm i && npm run build, just checking if I should also add PHP artisan optimize. Thanks

martinbean's avatar

@Cushty As @snapey says, they just call all the *:cache commands any way:

https://github.com/laravel/framework/blob/cbaca59289fc41bceea4405c5cecb36e40afcef6/src/Illuminate/Foundation/Console/OptimizeCommand.php#L34-L39

And each of those *:cache commands automatically clear before running:

https://github.com/laravel/framework/blob/cbaca59289fc41bceea4405c5cecb36e40afcef6/src/Illuminate/Foundation/Console/ConfigCacheCommand.php#L58

So basically, php artisan optimize is just a shorthand that will clear all those caches, and then re-cache those assets.

Given that you’re (hopefully) not going to be editing things like views, routes, and configuration on your production server between deployments, it makes sense to cache them to get any performance boost. But you should never run those commands outside of your Forge/production environment.

Please or to participate in this conversation.