skip to Main Content

I’m new to docker and stumbling into a PHP issue.

I can add a WordPress site, Database and phpmyadmin with no issues.

The theme I am using requires PHP version >=8.1.0.

Message displayed:

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0".

Below is the docker-compose.yml file

# version: '3.1'

services:

  wordpress:
    image: wordpress:latest
    container_name: WP_name
    restart: always
    volumes:
      - ./wordpress:/var/www/html
      # - ./src:/var/www/html
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: dbname
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD: password
      # WORDPRESS_TABLE_PREFIX : ''
    ports:
      - 8081:80

  db:
    image: mysql:8
    container_name: mysql_WP
    restart: always
    command: "--default-authentication-plugin=mysql_native_password"
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: dbname
      MYSQL_USER: user
      MYSQL_PASSWORD: password
    #volumes:
      #  - ./database_dump.sql:/docker-entrypoint-initdb.d/exampledb.sql
    volumes:
       - ./schema:/docker-entrypoint-initdb.d

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - 8082:80
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORT: password

  php:
    build:
      dockerfile: ./php/Dockerfile

The PHP build dockerfile at the bottom of docker-compose.yml (Dockerfile) contains:

FROM php:8.1.23-fpm-alpine

Can someone please advise on how I can add PHP version >=8.1.23 to the site (as an image?) in docker?

Any help much appreciated

Tried adding a Dockerfile in /php containing FROM php:8.1.23-fpm-alpine

2

Answers


  1. Chosen as BEST ANSWER

    Adjusting the wordpress image to the below works

    wordpress:6.3.1-php8.1-apache
    

    Full docker-compose.yml file

    # version: '3.1'
    
    services:
    
      db:
        image: mysql:8
        container_name: mysql_WP
        restart: always
        command: "--default-authentication-plugin=mysql_native_password"
        environment:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_DATABASE: dbname
          MYSQL_USER: user
          MYSQL_PASSWORD: password
        # volumes:
        #    - ./schema:/docker-entrypoint-initdb.d
    
      phpmyadmin:
        image: phpmyadmin/phpmyadmin
        restart: always
        ports:
          - 8082:80
        environment:
          PMA_HOST: db
          MYSQL_ROOT_PASSWORT: password
    
      wordpress:
        image: wordpress:6.3.1-php8.1-apache
        container_name: WP_name
        restart: always
        volumes:
          - ./wordpress:/var/www/html
          # - ./src:/var/www/html
        environment:
          WORDPRESS_DB_HOST: db
          WORDPRESS_DB_NAME: dbname
          WORDPRESS_DB_USER: user
          WORDPRESS_DB_PASSWORD: password
          # WORDPRESS_TABLE_PREFIX : ''
        ports:
          - 8081:80
    

  2. Run docker-compose exec php composer install to run composer install inside your container (which runs PHP 8.1.2)

    If you want to open a shell to run more commands, use docker-compose php sh.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search