Skip to content
Thuan Bui's Blog
Go back

Cài đặt PHP Extensions (ionCube-Loader, gd,...) cho WordPress Docker Image

Updated:

Khi cài đặt WordPress bằng Docker, trong nhiều trường hợp mình cần phải cài thêm PHP Extensions theo yêu cầu của một số plugins đặc biệt.

Bài viết này mình sẽ hướng dẫn cách cài đặt PHP Extensions cho PHP Docker Image, sử dụng script docker-php-extension-installer. Ưu điểm của khi dùng script cài đặt này so với cách cài đặt PHP Extensions thông thường:

1. Tạo website nháp

Để demo, mình sẽ tạo 1 website WordPress theo hướng dẫn ở đây

https://thuanbui.me/wordpress-caddy-docker/

Kiểm tra danh sách PHP Extension đã được cài mặc định

Terminal window
docker compose exec wordpress php -m
Terminal window
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
exif
fileinfo
filter
gd
hash
iconv
imagick
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
random
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache

2. Cài đặt ionCube Loader

Mình muốn cài đặt thêm PHP Extension: Ioncube Loader cho WordPress.

Tạo file Dockerfile trong cùng thư mục với file compose.yml và nhập vào nội dung sau

FROM wordpress:fpm-alpine
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN install-php-extensions ioncube-loader

Chỉnh sửa lại file compose.yml, thay thế mục image: wordpress:fpm-alpine bằng build: .. Phần khai báo woordpress sẽ tương tự như sau

wordpress:
build: .
container_name: wordpress
restart: always
depends_on:
- db
#- redis
volumes:
- ./wordpress/html:/var/www/html
- ./wordpress/custom.ini:/usr/local/etc/php/conf.d/custom.ini
env_file: .env

Cấu hình này sẽ yêu cầu Docker tạo 1 Container mới dựa trên thông số đã được cấu hình trong file Dockerfile

Kích hoạt lại hệ thống

Terminal window
docker compose build
docker compose up -d

Sau đó, kiểm tra lại thông số PHP Extensions. Giờ đã thấy ionCube Loader được bổ sung trong danh sách

Terminal window
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
hash
iconv
imagick
intl
ionCube Loader
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
the ionCube PHP Loader + ionCube24

Để cài thêm cùng lúc nhiều PHP Extensions, bạn sửa lại dòng thứ 3 trong Dockerfile, và thêm vào tên các extensions mong muốn

RUN install-php-extensions ioncube-loader xdebug

Mình đã thử cài đặt thêm PHP Extension cho nhiều phiên bản WordPress khác nhau: wordpress:php8.1-fpm-alpine, wordpress:php7.4-apache, … Tất cả đều hoạt động ngon lành, bất kể Docker OS là Debian, Ubuntu hay Alpine.


Share this post on:

Previous Post
[Hackintosh] Cài đặt macOS Sonoma 14.5 lên HP Elitedesk 800 G4 / G5 Mini
Next Post
Cài đặt Xpenology DSM 7.2 sử dụng RR Loader (Redpill Recovery Loader)