Install Craft 5 Beta

How to install Craft 5 beta locally so you can become familiar with the changes.

Image

You can get Craft 5 up and run­ning local­ly in three ways. 

  1. Fresh instal­la­tion local­ly (ide­al­ly using DDEV)
  2. Upgrade an exist­ing project (like if you have a vanil­la Craft project you use for testing).
  3. Use Andrew Welch’s Spin Up Craft project to spin up a copy of Craft 5 in Github Codespaces. 

No mat­ter which way you run Craft 5 local­ly, Craft 5 requires PHP 8.2, so keep that in mind, espe­cial­ly if you’re run­ning a local set­up that uses local PHP instead of some­thing eas­i­ly con­fig­urable in a Dock­er container.

We’ll use DDEV but you do you.

Let’s walk through each one briefly and learn which one is best for you!

Fresh Instal­la­tion of Craft 5 Beta #

To set up a fresh copy of Craft 5, we’ll use DDEV as our local­host­ing tool.

First, let’s cre­ate the direc­to­ry where we want the project to live. I use a ~/training direc­to­ry in my user home directory. 

cd ~/training
mkdir craft5
cd craft5

Now that we’re in the project, we need to con­fig­ure it for DDEV, using the ddev configure com­mand. We’ll pass in some options with the com­mand so we don’t need to go through the wiz­ard steps.

ddev config --project-type=craftcms --docroot=web --create-docroot --php-version=8.2

Okay, now we can grab the Craft starter project via Com­pos­er using the ddev composer create com­mand (which is slight­ly dif­fer­ent than the composer create-project com­mand but does the same thing).

ddev composer create -y --no-scripts craftcms/craft=5.0.x-dev

We’re pass­ing in some options to skip the wiz­ard and to use the 5.0.x‑dev ver­sion of the appli­ca­tion from Packagist.

Final­ly, we’re ready to install Craft in our local environment:

ddev craft install

After com­plet­ing every­thing, let’s nav­i­gate to the brows­er and check out Craft 5!

Updat­ing an Exist­ing Craft 4 Project #

One caveat to using this set­up: this should be a vanil­la Craft project and not a project that is set up with mul­ti­ple third-par­ty plu­g­ins or a cus­tom mod­ule. You will like­ly fail with the update since the plu­g­ins you use still need to sup­port Craft 5

Our pur­pose here is to only learn about Craft, not upgrade an actu­al project.

First things first, we need to make sure our exist­ing DDEV envi­ron­ments (or what­ev­er envri­on­ment you’re run­ning local­ly) sup­ports PHP 8.2. For DDEV it’s as sim­ple as updat­ing the config.yaml file or run­ning the fol­low­ing command:

ddev config --php-version=8.2

Then we need to restart DDEV to rebuild with the new ver­sion of PHP:

ddev restart

We also need to update the composer.php file to require PHP 8.2 — this is impor­tant to ensure we have Com­pos­er pack­age com­pat­i­bil­i­ty with the PHP ver­sion we’re running.

Stay­ing in the composer.php file, we need to change the ver­sion of craftcms/craft to the 5.0 dev version:

craftcms/cms: '5.0.0-beta.1'

If you have the first-par­ty plu­g­in Craft Gen­er­a­tor installed, then you’ll also need to update it.

craftcms/generator: '2.0.x-dev'

Now we’re ready to update Craft!

First, Com­pos­er, so we get the updat­ed ver­sion of our dependencies:

ddev composer update

And then we’ll do any project con­fig and migra­tions via craft up:

ddev craft up

And, we’re done!

Spin Up Craft 5 in Github Code­spaces #

Anoth­er option to start work­ing with Craft 5, and the one that requires the least amount of work is to use Andrew Welch’s Spin Up Craft 5 repository.

Andrew cre­at­ed a Github repos­i­to­ry that makes it sim­ple to spin up a vanil­la Craft 5 project in the cloud, using Github Code­spaces, with­out any set­up of your own. 

Github Code­spaces allows devel­op­ers to cre­ate and man­age ful­ly-con­fig­ured devel­op­ment envi­ron­ments direct­ly with­in the GitHub ecosys­tem. Devel­op­ers can work on their projects in a web-based edi­tor or even con­nect to their favorite desk­top IDE. It elim­i­nates the need for local devel­op­ment setups and pro­vides a con­sis­tent and repro­ducible envi­ron­ment for col­lab­o­ra­tive coding.

Pret­ty cool.

Make sure you’re logged in to your Github account and then go to Andrew’s Craft 5 Spin Up repository.

Scroll down to the README and click the Open in Github Code­spaces” button.