Running PHP 8.4RC4 in Docker

Scott Keck-Warren • November 10, 2024

We're just a couple of weeks away from the release of PHP 8.4 and while it's still in Release Candidate (RC) stage if you're like me you at least want to experiment with the new features but you're not willing to run RC code on your day-to-day computer.

With Docker we can run a self container image on our computer so we don't have to worry about version mismatches!

To do this we're going to create a new directory with a "Dockerfile" with the following contents:

from php:8.4.0RC4-cli

I'm also going to create a "test.php" file so we can more easily experiment instead of having to type in the code from scratch every time:

<?php
echo PHP_VERSION;

Then we're going to build our docker image using the command below. Please note that this is going to name our image "php8.4rc4" which we'll use to reference it later. You can call it something different if you would like.

docker build -t php8.4rc4 .

Now we can run our file using the command line below which will run our image and map the current directory to "/app/" inside the container and then run the "test.php" file with the php excutable inside the image.

docker container run --rm -v $(pwd):/app/ php8.4rc4 php /app/test.php

This will produce the following output:

8.4.0RC4

Now you can experiment with the new features but just rerunning the docker container run command from above.

References: