John Davidson

How to docker-compose up official wordpress latest image in php version 8?

0 comments
Message:


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...



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



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! ????





My Answer:
wordpress:
image: wordpress:latest
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
networks:
- wordpress
depends_on:
- db

db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: examplepass
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
networks:
- wordpress

volumes:
db_data:

In order to deploy the official WordPress image using PHP 8.0, you can specify the PHP version in the Dockerfile. Here is an example of how you can modify the docker-compose.yml file to use PHP 8.0:

wordpress:
image: wordpress:latest
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
networks:
- wordpress
depends_on:
- db

db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: examplepass
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
networks:
- wordpress

volumes:
db_data:

And here is an example of a Dockerfile that specifies PHP 8.0:

FROM wordpress:latest
RUN apt-get update && apt-get install -y software-properties-common
RUN add-apt-repository ppa:ondrej/php
RUN apt-get update && apt-get install -y php8.0

This Dockerfile will build on top of the official WordPress image and install PHP 8.0. You can then run docker-compose up to deploy your WordPress environment using PHP 8.0.

Rate this post

5 of 5 based on 2370 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us