Skip to content

Commit b4eae9c

Browse files
committed
Revisions to 5.x upgrade guide
There is still some confusion regarding collation and character sets!
1 parent 0a4b15e commit b4eae9c

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

docs/5.x/upgrade.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Take a peek at what’s new in Craft 5.
55

66
# Upgrading from Craft 4
77

8-
The smoothest way to upgrade to Craft 5 is to start with a [fully-updated Craft 4 project](/4.x/updating.md).
8+
The smoothest way to upgrade to Craft 5 is to start with a [fully-updated Craft 4 project](/4.x/updating.md). We recommend approaching the upgrade in three phases: [preparation](#preparing-for-the-upgrade), a [local upgrade](#performing-the-upgrade), and [rollout](#going-live) to live environments.
99

1010
<!-- more -->
1111

@@ -54,14 +54,14 @@ ddev start
5454
1. Run `php craft project-config/rebuild` and allow any new background tasks to complete.
5555
1. Capture a database backup of your _local_ environment, just in case things go sideways.
5656
1. Note your current **Temp Uploads Location** setting in **Settings** &rarr; **Assets** &rarr; **Settings**.
57-
1. Add your database’s current character set and collation to `.env`. If you have always used Craft’s defaults, this will be:
57+
1. MySQL users: Add your database’s _current_ character set and collation to `.env`. If you have always used Craft’s defaults, this will be:
5858

5959
```bash
6060
CRAFT_DB_CHARSET="utf8mb3"
6161
CRAFT_DB_COLLATION="utf8mb3_general_ci"
6262
```
6363

64-
If you _have_ changed the character set or collation, make sure your settings agree with [these recommendations](#database-character-set-and-collation).
64+
Read more about this process in the [Database Character Set and Collation](#database-character-set-and-collation) section, below.
6565

6666
1. Edit your project’s `composer.json` to require `"craftcms/cms": "^5.0.0"` and Craft-5-compatible plugins, all at once.
6767

@@ -70,26 +70,39 @@ ddev start
7070
:::
7171

7272
While you’re at it, review your project’s [other dependencies](#entry-scripts)! You may also need to add `"php": "8.2"` to your [platform](https://getcomposer.org/doc/06-config.md#platform) requirements, or remove it altogether.
73+
7374
1. Run `composer update`.
7475
1. Make any required changes to your [configuration](#configuration).
7576
1. Run `php craft up`.
76-
1. Remove your database character set and collation settings from `.env` (and `db.php`—even if you didn’t modify it during the upgrade), then run `php craft db/convert-charset`.
77+
1. MySQL users: Remove your database character set and collation settings from `.env` (and `db.php`—even if you didn’t modify it during the upgrade), then run `php craft db/convert-charset`.
7778

7879
Your site is now running Craft 5! If you began this process with no deprecation warnings, you’re nearly done.
7980

8081
::: warning
8182
Thoroughly review the list of changes on this page, making note of any features you use in templates or modules. Only a fraction of your site’s code is actually evaluated during an upgrade, so it’s your responsibility to check templates and modules for consistency. You may also need to follow any plugin-specific upgrade guides.
8283
:::
8384

84-
Once you’ve verified everything’s in order, commit your updated `composer.json`, `composer.lock`, and `config/project/` directory (along with any template, configuration, or module files that required updates) and deploy those changes normally in each additional environment.
85+
## Going Live
86+
87+
The Craft 5 upgrade can be run largely unattended during a routine deployment. Once you’ve performed the upgrade in your local environment and everything is working as expected, commit your updated `composer.json`, `composer.lock`, and `config/project/` directory, as well as any template, configuration, or module files that required updates.
88+
89+
::: warning
90+
MySQL users must add the correct [character set and collation settings](#database-character-set-and-collation) to each remote environment for the duration of the upgrade.
91+
:::
92+
93+
Deploy your changes to each environment, then run `php craft up`.
94+
95+
If you added temporary character set or collation settings for the upgrade, remove them now, then run `php craft db/convert-charset` to apply Craft 5’s new defaults to all tables.
96+
97+
Read more about this part of the upgrade in the [Database Character Set and Collation](#database-character-set-and-collation) section, below.
8598

86-
### Cleanup + Optional Steps
99+
## Cleanup + Optional Steps
87100

88101
#### Entry Scripts
89102

90103
Older projects may use versions of [`vlucas/phpdotenv`](repo:vlucas/phpdotenv) (the library that loads variables from your `.env` file) that depend on features deprecated in PHP 8.1. If you encounter errors during (or after) installation, change your `vlucas/phpdotenv` dependency in `composer.json` to `^5.6.0`, then run `composer update`.
91104

92-
Along with this update, you’ll need to integrate changes from our [starter project](repo:craftcms/craft)’s `web/index.php` script and `craft` executable. If you have done any low-level customization of Craft via [bootstrap constants](configure.md#bootstrap-config), make sure those values are preserved in the appropriate file(s)—constants shared between the two files can be moved to the new [`bootstrap.php` file](repo:craftcms/craft/blob/5.x/bootstrap.php).
105+
Along with this update, you’ll need to integrate changes from our [starter project](repo:craftcms/craft)’s `web/index.php` script and `craft` executable. If you have done any low-level customization of Craft via [bootstrap constants](configure.md#bootstrap-config), make sure those values are preserved in the appropriate file(s)—constants shared between the two files can be moved to a common [`bootstrap.php` file](repo:craftcms/craft/blob/5.x/bootstrap.php).
93106

94107
## Breaking Changes and Deprecations
95108

@@ -107,26 +120,33 @@ The following settings have been changed.
107120

108121
MySQL 8.0 [deprecated the `utf8mb3` character set](https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb3.html), as well as [the use of `utf8` as an alias for `utf8mb3`](https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8.html). MySQL [recommends `utf8mb4`](https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb4.html) instead, and it’s expected that `utf8` will become an alias for `utf8mb4` in MySQL 8.1.
109122

110-
To ease that transition, Craft 5 is proactively treating `utf8` as `utf8mb4` for MySQL and MariaDB installs. Since that will be different from what most Craft installs are already using, you will need to start explicitly setting the charset and collation using the non-aliased names, to avoid a SQL error during the upgrade.
123+
To ease that transition, Craft 5 is proactively treating `utf8` as `utf8mb4` for MySQL and MariaDB installs.
111124

112-
Ensure the following are set in your `.env` file:
125+
<Block label="During the Upgrade">
126+
127+
Explicitly setting the character set and collation ensures compatibility of new tables _during_ the upgrade—afterwards, those settings can be scrubbed and the tables can be converted via Craft’s CLI. Here’s how this will look, in practice.
128+
129+
If you have never customized character set or collation settings for your database connection, set these variables in your `.env` file during the upgrade:
113130

114131
```bash
115132
CRAFT_DB_CHARSET="utf8mb3"
116133
CRAFT_DB_COLLATION="utf8mb3_general_ci"
117134
```
118135

119-
::: tip
120-
Once the upgrade is complete, you can convert your tables to `utf8mb4` by removing the `CRAFT_DB_CHARSET` and `CRAFT_DB_COLLATION` environment variables, or updating them to the appropriate values:
136+
If you _are_ using these settings (either from `.env` or `db.php`), they can be left as-is, for now.
137+
138+
Once the upgrade is complete in an environment, convert your tables to `utf8mb4` by _removing_ the `CRAFT_DB_CHARSET` and `CRAFT_DB_COLLATION` environment variables (and clearing any `charset` and `collation` settings from `db.php`)…
121139

122140
```bash
141+
# …or set them to Craft’s defaults…
123142
CRAFT_DB_CHARSET="utf8mb4"
124143
CRAFT_DB_COLLATION="utf8mb4_0900_ai_ci" # MySQL
125144
CRAFT_DB_COLLATION="utf8mb4_unicode_ci" # MariaDB
126145
```
127146

128-
Then run `php craft db/convert-charset` to update all existing database tables.
129-
:::
147+
…then running `php craft db/convert-charset`.
148+
149+
</Block>
130150

131151
#### Template Priority
132152

0 commit comments

Comments
 (0)