skip to Main Content

I am using dockers official wordpress image to deploy local wordpress environments using docker compose.

After running docker-compose up -d and then running phpinfo() function in my local theme code, the current running php version is 7.4

enter image description here

But if you look at the official wordpress image repo on github, you can see the latest wordpress version supports php version 8.0…

enter image description here

My question is, how can I deploy my wordpress docker image using php8.0?

Here is my docker-compose.yml file…

version: '3.7'

networks:
  wordpress:
    ipam:
      config:
        - subnet: 172.25.0.0/16

services:

  # here is our mysql database
  db:
    image: mysql:5.7
    volumes:
     - ./db:/var/lib/mysql:delegated
     #- ./docker/db-dumps:/docker-entrypoint-initdb.d:delegated
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - wordpress

  # here is our wordpress server
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      # our persistent local data re routing
      - ./themes/example:/var/www/html/wp-content/themes/example:delegated
      - ./plugins:/var/www/html/wp-content/plugins
      - ./mu-plugins:/var/www/html/wp-content/mu-plugins
      - ./uploads:/var/www/html/wp-content/uploads
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
    ports:
      - "80:80"
    restart: always
    networks:
      - wordpress
    environment:

      # our local dev environment
      WORDPRESS_DEBUG: 1

      # docker wp-config settings
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_AUTH_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_SECURE_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_LOGGED_IN_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_NONCE_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_SECURE_AUTH_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_LOGGED_IN_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_NONCE_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
      WORDPRESS_CONFIG_EXTRA: |

        /* development parameters */
        define('WP_CACHE', false);
        define('ENVIRONMENT', 'local');

        /* configure mail server */
        define('WORDPRESS_SMTP_AUTH', false);
        define('WORDPRESS_SMTP_SECURE', '');
        define('WORDPRESS_SMTP_HOST', 'mailhog');
        define('WORDPRESS_SMTP_PORT', '1025');
        define('WORDPRESS_SMTP_USERNAME', null);
        define('WORDPRESS_SMTP_PASSWORD', null);
        define('WORDPRESS_SMTP_FROM', '[email protected]');
        define('WORDPRESS_SMTP_FROM_NAME', 'Example');

        if(!defined('WP_HOME')) {
          /* force our home url */
          define('WP_HOME', 'http://localhost');
          define('WP_SITEURL', WP_HOME);
        }

  # here is our mailhog server
  mailhog:
    image: mailhog/mailhog:latest
    ports:
      - "8025:8025"
    networks:
      - wordpress

How do I define which php version to use from the wordpress:latest image, so every time I docker-compose up -d it uses the php8.0 version?

Any ideas or advice would be hugely appreciated! 🙂

2

Answers


  1. The current wordpress:latest is on 7.4 but you can use one of the supported tags in your docker-compose file.
    In my case I used image: wordpress:6.0-php8.1-apache

    Login or Signup to reply.
  2. I agree with Duncan you need a tagged version

    image: wordpress:6.0.2-php8.0-apache
    

    Note: If your wordpress crashes and burns when you run it you can composer down and change it back again. It is best to disable any plugins and non official themes before switching as they could contain old code that is likely to not work on the latest php version.

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