Review follow-up (PR #61 review 121): - create-vhost.sh ignores DOCROOT_SUBDIR (log line) unless environment=DEV, and entrypoint.sh only creates the folder in DEV. Defence in depth so a production container cannot move its web root through the env, even if a site owner got the variable into the container (WHP also denies it now). - dev-mode.sh: XDEBUG_START defaults to trigger instead of yes, so CLI runs (wp-cli) do not print "Could not connect to debugging client" without an IDE. XDEBUG_START=yes still connects on every request. - README/CLAUDE.md updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
10 KiB
Cloud Apache Container
This is a base container for running PHP-based applications, supporting multiple PHP versions (7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5, 8.6; 8.6 is cac and cac-fpm only, no LiteSpeed lsphp86 yet). The container is based on AlmaLinux 10 and uses Apache with mod_ssl. It is designed for both development and production use.
You must have Docker or compatible containerization software running.
Which PHP version do I get? The image tag decides, nothing else. cac:php83 is PHP 8.3, cac:php84 is 8.4, cac:php85 is 8.5, and so on. cac:latest is the same image as cac:php85, so latest = PHP 8.5 today (not 8.3). The PHPVER environment variable does not switch the PHP version of a running container: docker run -e PHPVER=83 cac:php85 still runs PHP 8.5. In DEV mode a PHPVER that does not match the image's PHP prints a warning at start.
What's New?
- Optimized Image: The Dockerfile has been refactored for smaller size, faster builds, and improved security. Unnecessary files and caches are removed during build.
- Pre-built Images for Each PHP Version: On every push, images for all supported PHP versions are built and pushed to the registry. You can pull the exact version you need (e.g.,
cac:php74,cac:php84, orcac:latest, which is PHP 8.5). - .dockerignore Added: The build context is now minimized, making builds faster and more secure.
Quick Start: Local Development with local-dev.sh
The easiest way to start a local development environment is with the provided local-dev.sh script. This script automates container setup, volume creation, log directories, and WordPress installation.
Usage Example
./local-dev.sh -n local-dev
Flags:
-nName of the container (required)-pHTTP port (default: 80)-sHTTPS port (default: 443)-rRoot path for files and database (default: current directory)-aPHP version (default: 83; options: 74, 80, 81, 82, 83, 84, 85, 86). Selects the image tagcac:phpNN-dWeb root folder insidepublic_html, e.g.publicfor Laravel / CodeIgniter 4 (setsDOCROOT_SUBDIR)-xInstall and enable Xdebug (setsXDEBUG=1, see Debugging)-vEnable verbose mode-hShow help
The script will:
- Create a user directory and log folders
- Create a Docker volume for MySQL
- Pull and start
cac:php<NN>for the version you asked for, with the correct environment variables - Wait until the container is healthy (first start installs MariaDB and memcached, about a minute)
- Generate helper scripts in your root path:
instance_start– Start the containerinstance_stop– Stop the containerinstance_logs– Tail Apache logsinstance_db_info– Show MySQL credentials
- Install WordPress in your web root
- Print MySQL credentials
Manual Docker Usage
You can also run the container manually:
mkdir -p local-development/domain.tld
cd local-development/domain.tld
mkdir user
docker volume create local-dev-mysql
docker run -d -it -p 80:80 -p 443:443 \
-e environment=DEV -e PHPVER=84 \
--mount type=bind,source="$(pwd)"/user,target=/home/"$(whoami)" \
-v local-dev-mysql:/var/lib/mysql \
-e uid=$(id -u) -e user=$(whoami) -e domain=localhost \
--name local-dev \
repo.anhonesthost.net/cloud-hosting-platform/cac:php84
Notes:
uidmust be your own uid ($(id -u)) anduseryour own username: the entrypoint chowns the mounted directory to that uid, so a fixed value such as 30001 leaves you unable to edit the files on the host. Do not createlogs/yourself; the container does.- The tag (
cac:php84) selects PHP 8.4.PHPVER=84is informational only (DEV mode warns if it disagrees with the tag). - Do not bind-mount anything over
/var/logor/etc/httpd/logs; logs are written touser/logs/apacheanduser/logs/php-fpm. - With a non-default HTTPS port (
-p 8443:443) also pass-e PUBLIC_HTTPS_PORT=8443so the HTTP to HTTPS redirect keeps the port.
Accessing the Container
docker exec -it local-dev /bin/bash
WordPress Installation
If using local-dev.sh, WordPress is installed automatically. For manual setup:
cat /home/myuser/mysql_creds
su - myuser
cd ~/public_html
wp core download
Then visit https://localhost (accept the SSL warning) to complete setup.
Features
- Multiple PHP Versions: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5, 8.6 (8.6: cac and cac-fpm only). Selected by the image tag (
cac:php84) or the-aflag oflocal-dev.sh;latest= 8.5 - Pre-built Images: Pull the image for your desired PHP version directly from the registry. No need to build locally unless customizing.
- Optimized Build: Smaller, faster, and more secure images thanks to the improved Dockerfile and
.dockerignore. - Automatic Database Setup: MariaDB is started in DEV mode, credentials are auto-generated and stored in
/home/$user/mysql_creds. - Database Backups: Cron job backs up the database every 15 minutes to
/home/$user/_db_backups. - Log Management: Log rotation compresses logs older than 3 days and deletes those older than 7 days.
- Memcached: Started automatically in DEV mode.
- SSL: Self-signed certificate enabled by default.
- Default Web Content:
/home/$user/public_htmlis the web root./pingendpoint andphpinfo.phpare available for diagnostics. - Helper Scripts:
instance_start,instance_stop,instance_logs,instance_db_info(created bylocal-dev.sh).
Environment Variables
Required:
uid– User ID for file permissionsuser– Username for file permissionsdomain– Primary domain for configuration
Optional:
environment– Set toDEVto start memcached and MariaDB locally for development (see "DEV mode" below)serveralias– Comma-separated list of alternative hostnamesPHPVER– Informational only. The PHP version is the image tag; in DEV mode a mismatch prints a warningDOCROOT_SUBDIR– (DEV mode only: in production mode it is ignored, with a log line in the container output) Servepublic_html/<subdir>instead ofpublic_html(e.g.public,web/public). Default empty =public_html, unchanged. Rules (same as the WHP panel): up to 4 folders; letters, digits,.,_,-; no folder starting with.or-; no./..;cgi-binis reserved. An invalid value stops the container with a message. The folder is created if missing. Everything above it (vendor/,.env,app/) is not reachable over HTTP, andpublic_html/.htaccessis no longer readPUBLIC_HTTPS_PORT– DEV only: the host port mapped to 443, so the HTTP to HTTPS redirect keeps it (e.g.8443)
DEV mode only (environment=DEV; production containers never read these):
XDEBUG–1installs and enables Xdebug 3 for the image's PHP at start (see below)XDEBUG_MODE(defaultdebug),XDEBUG_START(triggerdefault: only requests with theXDEBUG_TRIGGERcookie/parameter connect to the IDE;yesconnects on every request, but then every CLI call such as wp-cli prints "Could not connect to debugging client" when no IDE is listening),XDEBUG_CLIENT_HOST(defaulthost.docker.internal),XDEBUG_CLIENT_PORT(default9003)
DEV mode
environment=DEV is for your laptop, not production. At start it:
- installs MariaDB (11.4 from mariadb.org, falling back to AlmaLinux's 10.11) and memcached, starts them, and writes a random database login to
/home/$user/mysql_creds(backups every 15 minutes to_db_backups); - turns on
display_errorsand setsopcache.revalidate_freq=0(PHP file edits show immediately);error_reportingstays at the production value (no deprecation notices), set it in your app or.user.iniif you want them; - installs the
posixextension (php-process); - exits with an error (non-zero) and a loud message in
docker logsif MariaDB, memcached or a requested Xdebug cannot be installed or started, instead of looking healthy. The first start needs internet access.
Debugging with Xdebug (DEV mode only)
./local-dev.sh -n myproject -a 84 -x # or: docker run ... -e XDEBUG=1 --add-host host.docker.internal:host-gateway ...
Xdebug 3 is installed from the same Remi module stream as the image's PHP. Configure your IDE as a debug client listening on port 9003, with a path mapping from your project folder (./user/public_html) to /home/<user>/public_html in the container. The container connects out to host.docker.internal:9003 (--add-host host.docker.internal:host-gateway is needed on Linux; local-dev.sh adds it). By default (XDEBUG_START=trigger) only requests that carry the XDEBUG_TRIGGER cookie/parameter (e.g. the browser extension's "Xdebug helper") start a session; use XDEBUG_START=yes to connect on every request, and XDEBUG_MODE=debug,develop etc. to change the mode.
Laravel / CodeIgniter 4 / Symfony style apps
These serve from a public/ folder inside the project. Put the whole project in user/public_html/ and start with DOCROOT_SUBDIR=public (./local-dev.sh -n app -d public): the web root becomes public_html/public, so vendor/, .env and app/ are not served.
Helpful Notes
- To restart the instance:
./instance_startordocker start {container-name} - To stop:
./instance_stopordocker stop {container-name} - To view logs:
./instance_logsordocker logs -f {container-name} - To get DB credentials:
./instance_db_infoorcat /home/$user/mysql_creds - To delete a container:
docker rm {container-name}(does not delete user files or DB volume) - To view running containers:
docker ps - To view all containers:
docker ps --all - To view images:
docker images
Troubleshooting
- The first run may take several minutes as dependencies are installed (DEV mode needs internet access). If it fails you will see
FATAL: DEV mode could not set up ...indocker logsand the container exits. - If you need to change PHP version, stop and remove the container, then recreate it from the other image tag (
cac:php85, ...);PHPVERdoes not switch versions. - For advanced configuration, see the scripts in the
scripts/directory. - The image is optimized for size and speed, but local development in DEV mode installs additional packages (MariaDB, memcached, optionally Xdebug) at runtime using dnf.
- The build context is minimized by the included
.dockerignorefile.