Hello,
I am struggling a lot with managing my development - staging environments.
Today what im developing some saas project that I have with Laravel.
Its looks like that
Local (Rsync files) -> Staging (connected to git) -> production.
How are you synchronizing the staging and local environments?
I have a lot of issues when im installing packages on staging env with composer and then im syncing and its changing back to old compose.lock and composer.json files and it's causing so many errors.
Any advice will be welcome here!
I use Forge to host all of my Laravel apps. I just create a new site for staging and the deploy scripts are the same for staging & production.
I would definitely read up on creating Reproducible Builds. This is definitely possible with PHP and Composer.
It may seem like overkill, but what you need is some kind of build pipeline/process that will build your app (i.e. install dependencies, compile native code, etc) for a given environment. I personally use Docker to build and deploy the apps Ive built (running them on Kubernetes) to keep everything consistent. This gives me the advantage of only needing to configure one "environment" (the Docker container) and not worrying about the raw machine it might be running on. This way, I can take the same container and run it locally on my mac, on Kubernetes, or even (probably...) on a Windows machine if I need to.
My process is typically:
That third step could be changed based on your own environment. You could ssh to your target environment and run a script to pull in the new container version and start it.
You dont even need to use containers if you dont want. Step 2, assuming your runner and target environment are the same OS and have the same versions of shared libraries, could build your application, generate a tarball of the build, and then ssh it over to your target environment.
Generally your builds should flow in one direction (local --> staging --> production). Doing that should keep everything more consistent and prevent weird transient errors that may crop up because your two environments differ in some way.
Happy to help with any other questions you might have! Creating a build/deploy process can get a little tricky at times.