OpenCart sur OxPHP
OpenCart est une application en mode traditionnel dotée de deux contrôleurs frontaux physiques : index.php (boutique) et admin/index.php (panneau d'administration), ainsi que des ressources statiques sous image/ et catalog/view/. Sa racine web est la racine du projet elle-même. Le mode de routage traditionnel d'OxPHP — celui par défaut lorsque ENTRY_FILE n'est pas défini — sert les deux points d'entrée comme de vrais fichiers ainsi que les ressources statiques depuis le disque ; PHP_DENY_PATHS empêche l'exécution directe des composants internes du framework.
La stack en un coup d'œil
- Image OxPHP :
ghcr.io/oxphp/oxphp:0.10.0-php8.4-alpine3.23(PHP 8.4) - Mode de routage : Traditionnel (pas de
ENTRY_FILE;DOCUMENT_ROOT= racine du projet, remplace la valeur par défaut…/public) - Extensions ajoutées :
gd,mysqli,zip,mbstring - Services : OxPHP + MySQL
- URL :
http://localhost:8095· admin/admin/· internehttp://localhost:9096/health
OpenCart 4 requiert PHP 8.0+ mais son code source est antérieur à la 8.5 ; épinglez l'image PHP 8.4. OpenCart utilise le pilote mysqli, pas PDO. (Remarque : OpenCart 3.x ne fonctionnera pas sur PHP 8.4+ — utilisez OpenCart 4.x.)
Structure du projet
OpenCart est distribué sous forme d'archive de release, pas sous forme de paquet Composer. La racine web correspond au contenu du répertoire upload/ de l'archive :
mkdir -p opencart-oxphp/src
curl -sL https://github.com/opencart/opencart/releases/download/4.1.0.3/opencart-4.1.0.3.zip -o /tmp/oc.zip
unzip -q /tmp/oc.zip -d /tmp/oc
cp -a /tmp/oc/upload/. opencart-oxphp/src/
# the installer needs these to exist and be writable:
: > opencart-oxphp/src/config.php
: > opencart-oxphp/src/admin/config.phpDockerfile et Compose
Le Dockerfile est src/Dockerfile.oxphp, nommé ainsi pour ne pas entrer en conflit avec le Dockerfile fourni par OpenCart.
ARG OXPHP_VERSION=0.10.0
ARG PHP_VERSION=8.4
ARG ALPINE_VERSION=3.23
# ── PHP base: OpenCart runtime extensions ─────────────────────
FROM php:${PHP_VERSION}-zts-alpine${ALPINE_VERSION} AS php-base
RUN apk add --no-cache \
libpng libjpeg-turbo freetype oniguruma libzip \
&& apk add --no-cache --virtual .build-deps \
libpng-dev libjpeg-turbo-dev freetype-dev oniguruma-dev libzip-dev \
&& docker-php-ext-configure gd --with-jpeg --with-freetype \
&& docker-php-ext-install -j"$(nproc)" gd mysqli zip mbstring \
&& apk del .build-deps
# ── Composer ──────────────────────────────────────────────────
FROM composer:2 AS composer
# ── OxPHP artifacts (PHP 8.4 image) ───────────────────────────
FROM ghcr.io/oxphp/oxphp:${OXPHP_VERSION}-php${PHP_VERSION}-alpine${ALPINE_VERSION} AS oxphp
# ── dev: OxPHP server + PHP CLI + Composer ────────────────────
FROM php-base AS dev
RUN apk add --no-cache libgcc
COPY --from=composer /usr/bin/composer /usr/local/bin/composer
COPY --from=oxphp /usr/local/bin/oxphp /usr/local/bin/oxphp
COPY --from=oxphp /usr/local/lib/liboxphp_bridge.so /usr/local/lib/
COPY --from=oxphp /usr/local/lib/php/extensions/ /tmp/oxphp-ext/
RUN cp /tmp/oxphp-ext/*/oxphp_sapi.so "$(php -r 'echo ini_get("extension_dir");')/" \
&& rm -rf /tmp/oxphp-ext \
&& echo "extension=oxphp_sapi.so" > /usr/local/etc/php/conf.d/oxphp-ext.ini
RUN { \
echo "[opcache]"; echo "opcache.enable=1"; echo "opcache.enable_cli=1"; \
echo "opcache.validate_timestamps=1"; echo "opcache.revalidate_freq=0"; \
} > /usr/local/etc/php/conf.d/opcache-dev.ini
RUN { \
echo "memory_limit=256M"; echo "upload_max_filesize=64M"; \
echo "post_max_size=64M"; echo "max_execution_time=300"; \
} > /usr/local/etc/php/conf.d/opencart.ini
RUN getent passwd www-data >/dev/null \
|| adduser -D -H -u 82 -G www-data -s /sbin/nologin www-data
RUN mkdir -p /var/www/html && chown -R www-data:www-data /var/www/html
ENV LD_LIBRARY_PATH=/usr/local/lib
WORKDIR /var/www/html
EXPOSE 80 9090
CMD ["oxphp"]services:
app:
build:
context: ./src
dockerfile: Dockerfile.oxphp
target: dev
image: opencart-oxphp/app:dev
container_name: opencart-oxphp
ports:
- "8095:80"
- "9096:9090"
volumes:
- ./src:/var/www/html
environment:
# LISTEN_ADDR defaults to 0.0.0.0:80, so it is omitted.
DOCUMENT_ROOT: /var/www/html # webroot IS the project root (overrides default /…/public)
INTERNAL_ADDR: 0.0.0.0:9090 # (no ENTRY_FILE → traditional mode)
ACCESS_LOG: all
# Block direct HTTP execution of framework internals and the web installer.
PHP_DENY_PATHS: "/system/**,/install/**"
depends_on:
db:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://0.0.0.0:9090/health"]
interval: 10s
timeout: 3s
retries: 5
start_period: 5s
db:
image: mysql:8.0
container_name: opencart-oxphp-db
ports:
- "3311:3306"
environment:
MYSQL_DATABASE: opencart
MYSQL_USER: opencart
MYSQL_PASSWORD: opencart
MYSQL_ROOT_PASSWORD: root
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-proot"]
interval: 5s
timeout: 5s
retries: 30
start_period: 15s
restart: unless-stopped
volumes:
db_data:Installation et premier lancement
OpenCart 4 est livré avec un installeur en CLI :
docker compose up -d db
docker compose run --rm app php install/cli_install.php install \
--username admin --password 'admin123' --email [email protected] \
--http_server 'http://localhost:8095/' --language en-gb \
--db_driver mysqli --db_hostname db --db_username opencart \
--db_password opencart --db_database opencart --db_port 3306 --db_prefix oc_
# OpenCart recommends removing the installer afterwards:
rm -rf opencart-oxphp/src/install
docker compose up -d appNotes OxPHP
- Le mode traditionnel sert deux contrôleurs frontaux.
index.php(boutique) etadmin/index.php(admin) sont tous deux des points d'entrée physiques ; le mode traditionnel exécute chacun comme un vrai fichier. Le mode framework canaliserait tout vers un uniqueindex.phpet casserait l'admin. PHP_DENY_PATHSprotège les composants internes. Avec la racine web à la racine du projet,system/etinstall/se trouvent à l'intérieur deDOCUMENT_ROOT.PHP_DENY_PATHS=/system/**,/install/**empêche l'exécution HTTP directe de ces scripts — la correspondance est évaluée avant toute I/O disque, donc il n'y a pas d'oracle d'existence. L'installeur en CLI s'exécute via le shell et n'est pas affecté. Voir Liste de refus d'exécution PHP.- Les fichiers cachés sont déjà protégés. Les chemins de type
.envet ceux comportant des segments en point renvoient404grâce au blocage des chemins en point ; aucune règle n'est nécessaire. - Les URL SEO sont désactivées par défaut. Par défaut, OpenCart utilise le routage par paramètre de requête
index.php?route=…, que le mode traditionnel gère directement sans aucune règle de réécriture.
Vérification
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8095/ # 200 storefront
curl -s -o /dev/null -w "%{http_code}\n" "http://localhost:8095/index.php?route=common/home" # 200
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8095/admin/ # 200 admin login
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8095/system/startup.php # 404 (denied)
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:9096/health # 200Voir aussi
- Routage · Liste de refus d'exécution PHP · Blocage des chemins en point
- WordPress — l'autre recette en mode traditionnel