I am using “PHP & MySQL: Novice to Ninja, 7th Edition” to brush up on my PHP skills, and liked the idea of the Docker Desktop. However, I can’t change the PHP version. Does anyone who has used this book (PHP & MySQL: Novice to Ninja, 7th Edition) to set up Docker know how to change the PHP version?
You should be able to change it in the Dockerfile
.
It starts with a FROM
directive that indicates the base PHP container. You can indicate which version you want there.
Note that you do need to rebuild your container when you change this, it doesn’t update on the fly.
I see this line in my docker file.
FROM php:fpm-alpine
So I should change it to something like this?
FROM php:8.1.4-fpm-alpine
You can usually change the PHP version by editing the Dockerfile or using a different image tag. What version are you trying to switch to?
I’m tring to switch to 8.1.4, it is currently on 8.4
Docker hub shows a list of available PHP tags. Pick the one you need and put that in the FROM directive of your dockerfile.
For 8.1.4 that would indeed be php:8.1.4-fpm-alpine
. See https://hub.docker.com/layers/library/php/8.1.4-fpm-alpine/images/sha256-df31b124e71de2d08260a307b8eeeb7d42e51aa2afe1a98bbc6ae8df0c2f2288
I changed the docker file from…
FROM php:fpm-alpine
To…
FROM php:8.1.4-fpm-alpine
Docker seemed run ok but when I went to the local url https://v.je it did not work (problem loading page).
Just so you know I am using the docker files supplied by the book “PHP & MySQL: Novice to Ninja, 7th Edition” and this is the only change I have made.
I am a complete nubie to docker so any advise is welcome.
After you changed the PHP version, did you rebuild the container?
yes I did
Does docker compose logs php
tell anything?
Just to help you help me
this are the original docker files used to create the container.
To change the PHP version in a Docker Desktop container, update the Dockerfile
or use a different PHP image tag. For example, modify your Dockerfile
like this:
FROM php:8.2-apache
Then rebuild the container:
docker-compose down
docker-compose up --build
Or if using plain Docker:
docker build -t my-php-app .
docker run -p 80:80 my-php-app
Make sure to replace 8.2
with your desired PHP version.