Documentation
Why Are My Environments Behaving Differently?
We've all been there, Production and Staging appears to be identical but for some reason they're not quite behaving the same. So what could be behind it?
Let's take a look at some of the most common reasons that we've observed on Servd.
1. Environment-Specific Craft Config #
Open up your codebase's config/general.php file and check for any environment-specific config blocks. There may be configuration in the staging block that's different from the production block, or vice versa.
It's also worth noting that Servd's environment keys are restricted to production, staging and development. Any other keys (e.g.stage, testing, live, prod, etc) won't be activated so may cause unexpected behaviour.
2. Different Environment Variables #
By design, environment variables facilitate different configuration in different environments. So if you're seeing a discrepancy in behaviour between environments, be sure to check the following:
- All environment variables have been added to your project's Staging and Production Environment Variables page. It can be useful to compare what you have in your local .env file with what's shown in the list.
- That each environment variable has the correct values for its' respective environment.
3. Different Deployed Bundles #
If you having different bundles deployed to Staging and Production, then there's a chance that they may contain different project config or PHP config files. Try the following:
- Visit your Staging and Production settings pages to check what's currently deployed.
- Find a bundle you're happy to deploy to both environments.
- In both environments, find the bundle in the "Select a Bundle " section and click the "Select" button.
- Click the 'Sync" button to deploy the bundles.
4. Different Database Data and Structure #
Your project's database data and structure can cause vastly different behaviour between environments. It can be hard to diagnose database-related variations, especially if your tables house gigabytes of data.
An easy way to rule out your database as the source of differing behaviour is to use Servd's environment clone tool. Try importing your Production database into your Staging database (or vice versa). This should leave them in an identical state. Note: doing so will overwrite existing data in the target environment, so take a manual backup if you want to keep the existing database data.
5. Different Assets #
By default, Servd Asset Volumes store assets in environment-specific directories on the Servd CDN. You'll see production/, staging/ and local/ directories already initialised when you connect. Each stores a complete and independent copy of your project's assets for each environment.
If you're seeing that assets are loading on one environment, but not on another, then chances are the assets exist in one of the environment's CDN directories, but not the other. You can use Servd's environment clone tool to copy assets between the environment directories. Note: doing so will overwrite existing assets in the target environment directory, so take a manual backup if you want to keep the existing assets.
6. Performance Differences #
Each plan on Servd allocates different amounts of compute resource to Staging and Production environments. As Staging won't be hit by a lot of traffic, it isn't allocated the same amount of memory and CPU time as Production. This is the case for nearly all parts of your project infrastructure, such as the PHP instances that run Craft, the database and the background queue runner.
This difference in performance may be responsible if you're seeing comparable requests or jobs...
- Taking longer on Staging versus Production.
- Running out of memory on Staging, but not on Production.
If you'd like to upgrade your Staging environment so it's resources match Production, get in touch via our live chat or drop us an email at hello@servd.host and we can fix you up with a custom plan.
7. Load Balancing Differences #
Servd's Enhanced and Pro plans increase the number of PHP instances that run in Production. Or in other words, there's sometimes more than one copy of your project's Craft code running in Production. But in Staging, there's always just a single instance running.
With a single instance, files which are created and stored on the instance's filesystem at runtime will be accessible by Craft (not forever though!). With multiple instances, a file created on one filesystem won't be accessible to all instances, because each instance's filesystem is independent of each others.
In these circumstances, file data should instead be stored in a persistent, centralised location that can be accessed by all PHP instances e.g. in a table in your project's database, on the Servd CDN, on S3, etc.