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

Gbever's avatar

Deployment Best Practices

I am deploying my first Laravel application with Laravel forge on Digital Ocean, hooked into my Git Repository. While scouring the net for deployment script suggestions, I found one that was simple and seemed to suit my needs. I ran it and realized there is a flaw in my understanding of deployment and was hoping for some tips.

In my script, I am running npm run production, in order to produce the production css and js assets. The flaw I realized is that on my next deploy, I get Git errors because app.js and app.css have changed. I can ssh in and fix those issues but that seems to defeat the purpose. Im curious how others deal with this kind of issue, do you commit the production version each time, or is there some other method? I thought I could gitignore those files but they are already in my repository, and my previous attempts to remove files afterwards created some headaches.

Any tips would be greatly appreciated, or any deployment scripts working well for you.

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

I usually run npm run production on my local environment and ship the built versions to the production once I am done and ready to deploy, I am also versioning the files for caching purposes. I first use npm run dev or watch for development.

Btw, you can always add to .gitignore you can remove cached files from git using git rm -r --cached file_name .. and it will be ignored from the commit :)

And btw this is my forge deployment script:

cd /home/forge/project_folder
git pull origin master
composer install --no-interaction
php artisan migrate --force
echo "" | sudo -S service php7.3-fpm reload

Pretty simple.. project_folder should be your project :)

I put the composer.lock in my git so that I have the same versions locally and on production.

2 likes
Gbever's avatar

Thank you, that makes sense. Sort of what i thought about doing, but some confirmation really helps.

Please or to participate in this conversation.