# CraftCMS
This section offers some tips and resources for CraftCMS. If it gets too extensive, it should be broken out into a separate section.
# Updating CraftCMS
# Helpful Resources
Here are two helpful overview resources for updating craft.
- See discussion on discord (opens new window)
- See also Andrew Welch's article (opens new window)
# Update Procedure
The following is the quarterly CraftCMS update procedure for CraftCMS. This assumes you are on composer 2.0. Composer upgrade instructions are available here.
# Backup the production Database
Chose your prefferred method to backup the production database.
# Local Dev Prep
Make sure to pull down any repo changes into local dev. It is a judgement call whether you
want to import the production database into your local dev database. Open the composer.json
file
and make sure to the ^ in front of all the packages you would like to update.
Here is an explanation pulled from Andrew Welch's article (opens new window)
1.0.0 = exactly & only this version
~1.0.0 = this version & any _patch_ release (up to 1.0.99̅)
^1.0.0 = this version & any _minor_ release (up to 1.99̅.99̅)
If we are updating quarterly, then we should choose the latest major version followed by zeros. Here is an example of Craft CMS
"require": {
"craftcms/cms": "^3.0.0",
},
If major version 4 comes out, and we were ready to update to it, we would then put
"require": {
"craftcms/cms": "^4.0.0",
},
This would apply to the versioning of any package in our composer.json file.
# Prepare Composer Scripts (if not done already):
Composer Scripts (opens new window) provides a powerful way to streamline updating CraftCMS directly through composer. The following is a section taking from Andrew Welch's article referenced above with a couple lines taken out to apply it to the Harvest Process.
Note: Make sure to remove the project config line if the site is not using it.
"scripts": {
"craft-update": [
"@pre-craft-update",
"@post-craft-update"
],
"pre-craft-update": [
],
"post-craft-update": [
"@php craft install/check && php craft migrate/all --interactive=0 || exit 0",
"@php craft install/check && php craft project-config/apply --interactive=0 || return 0"
],
"post-root-package-install": [
],
"pre-update-cmd": "@pre-craft-update",
"post-update-cmd": "@post-craft-update"
}
# Production Server Prep
If you haven't already upgraded the production server to Composer 2.0, you will need to SSH in and do this. You will need to have your sudo password on hand and run
sudo composer self-update --2
# Run Composer Update
Next, run composer update
and all the scripts will be run above, and if all goes smoothly, everything will be updated.
Next, click through the pages on the site on local dev to make sure things look right.
Next, log into the CP and make sure things are working right there.
Finally, commit the changes to the repo. Then log into the production CP and finish up the migrations and apply any project config changes.
# Problems in Local Dev
If there is a problem with one of the updates in local dev, you can always import the production database backup you have and lock in a package version in the composer.json file for troubleshooting and run composer update again.
Also, if need be you can use what Andrew Welch calls this the "Composer Nuke command." This can be used to wipe out your vendor directory and reset composer in your project. This also is in the context that there might be some older packages in your vendor directory that are just sitting there, but you don't need. And then, they cause an error.
rm -rf vendor/ && rm composer.lock && composer clear-cache && composer update
# Problems in Production
You basically can do everything menioned above in production when you have a problem with the exception that you would want to lock in the version of the plugins you were last at in production in the composer.json file, and then nuke the vendor directory and import your production database backup. This would put everything back as it was.
# Possible Issues
The composer platform-watch error comes up. See here for more information.
# Looking at CraftCMS Logs
- See discussion on discord (opens new window)
- See Andrew Welch's Article (opens new window)
# Object Storage Upload Failure - Case Study
by: Nathan Bate on March 25, 2021
- See discussion on discord (opens new window)
- See also Andrew Welch's article (opens new window)
I recently randomly had an issue where the fortRabbit
# Adding Redis
See this article here too: https://servd.host/blog/adding-redis-to-craft-cms
- install the
yiisoft/yii2-redis
package with composer
composer require yiisoft/yii2-redis
- Add vars to .env file
################################################
# Cloud Hosted Asset Volumes
################################################
REDIS_HOST="127.0.0.1"
REDIS_PORT="6379"
REDIS_PASSWORD=""
REDIS_KEY_PREFIX=""
- configure multi-environment in
config/app.php
and old installs may need an APP_ID added to .env also
<?php
/**
* Yii Application Config
*
* Edit this file at your own risk!
*
* The array returned by this file will get merged with
* vendor/craftcms/cms/src/config/app.php and app.[web|console].php, when
* Craft's bootstrap script is defining the configuration for the entire
* application.
*
* You can define custom modules and system components, and even override the
* built-in system components.
*
* If you want to modify the application config for *only* web requests or
* *only* console requests, create an app.web.php or app.console.php file in
* your config/ folder, alongside this one.
*/
use craft\helpers\App;
return [
'*' => [
'modules' => [
'id' => App::env('APP_ID') ?: 'CraftCMS',
'my-module' => \modules\Module::class,
],
//'bootstrap' => ['my-module'],
],
'production' => [
'components' => [
'redis' => [
'class' => yii\redis\Connection::class,
'hostname' => getenv('REDIS_HOST'),
'port' => getenv('REDIS_PORT'),
'password' => getenv('REDIS_PASSWORD'),
],
'cache' => [
'class' => yii\redis\Cache::class,
'defaultDuration' => 86400,
'keyPrefix' => getenv('REDIS_KEY_PREFIX'),
],
],
],
];
# Helpful links
https://servd.host/blog/adding-redis-to-craft-cms (opens new window)
https://craftcms.com/docs/3.x/config/#redis-example (opens new window)