Apache with PHP module featured by XDebug, adminer.php and dev. oriented settings out of the box.
6.0K
This project is a source of 200ms/phpapache_dev2 docker image.
200ms/phpapache_dev2 belongs to a set of images that can be described as "Dev^2 suit".
The idea behind this is to develop Docker images and complementing tools aimed to ease development and testing of LAMP applications.
The main goals are:
200ms/phpapache_dev2 holds Apache server pre-configured to support development with XDebug, verbose messaging and more.
Docker image can be pulled with:
docker pull 200ms/phpapache_dev2
Other images implementing that idea are:
200ms/wpapache_dev2 - Wordpress with WPC-CLI and more200ms/mariadb_dev2 - MariaDB database with automatic DB creation and more200ms/prestashop_dev2 - Prestashop with helper scripts 200ms/phpapache_dev2 image has NOT been tested on other OS then Linux.
Therefore at this point only this OS is supported.This image internally uses Dev2FS that requires Linux FUSE
module to be loaded but also elevated privileges for each Docker container based on this image.
It might be required to modprobe fuse prior to using all features of the image.
Moreover it is required to run container with:
docker ... --cap-add SYS_ADMIN --device /dev/fuse ...
parameters. Or in the case of docker-compose.yaml:
services:
proj:
...
cap_add: ['SYS_ADMIN']
devices:
- /dev/fuse
...
This elevates container's permissions allowing FUSE based Dev2FS to work.
Dev2FS has been developed to fix mismatch of shared file permissions, therefore it is actually one of the key elements of Dev2 suit.
PHP code and other files must be shared between container and host. For 200ms/phpapache_dev2 directory named:
/code
has been chosen as a code share point. Data shared with /code is accessed by Apache server, additionally container will handle proper uid:gid remapping.
To create container call:
docker run --cap-add SYS_ADMIN --device /dev/fuse \
-it -p 8080:80 -v $(pwd)/src:/code \
200ms/phpapache_dev2
As indicated just above, --cap-add SYS_ADMIN --device /dev/fuse is to elevate permissions.
/code is a path to be shared with a host. $(pwd)/src is a source directory for PHP app
see example below.
MySQL database is a very common for PHP projects, thus 200ms/phpapache_dev2 image provides an option to run it among with Apache server.
To launch MySQL (MariaDB fork):
LOCALMYSQL variable to yes (or y, on, 1), like bellow:docker run --cap-add SYS_ADMIN --device /dev/fuse \
-e LOCALMYSQL=yes \
-it -p 8080:80 -v $(pwd)/src:/code \
200ms/phpapache_dev2
MYSQL_HOST to 'localhost':docker run --cap-add SYS_ADMIN --device /dev/fuse \
-e MYSQL_HOST=localhost \
-it -p 8080:80 -v $(pwd)/src:/code \
200ms/phpapache_dev2
This triggers new container to launch both: Apache and MariaDB services. Database is configured automatically, settings can be changed (from default) or read via environment variables.
Functionalities of Apache server can be tuned with PHP modules. 200ms/phpapache_dev2 comes with the following installed - bold font, and available (for installation) - regular font, modules:
Additional modules can be installed with dev2_docker-apache-ext.sh, or trough EXTR_MOD variable, e.g.:
# install GD and Intl extensions:
docker <Dev2 PHP Apache container> dev2_docker-apache-ext.sh gd intl
# ext. names can be separated by commas:
docker <Dev2 PHP Apache container> dev2_docker-apache-ext.sh gd,intl
and trough EXTR_MOD:
docker run --cap-add SYS_ADMIN --device /dev/fuse \
-e EXTR_MOD=gd,intl \
-it -p 8080:80 -v $(pwd)/src:/code \
200ms/phpapache_dev2
Module names can be separated by space, or commas, commas are more convenient in command line, spaces in Docker/configuration files see example below.
This is an example of LAMPhp project organisation with Docker and Dev2 PHP Apache:
.
├── ReadMe.md
├── doc/
├── docker/
│ ├── Dockerfile
│ ├── docker-compose.yaml
│ └── settings.env
├── src/
└── test/
Content of Dockerfile:
FROM 200ms/phpapache_dev2
LABEL maintainer="..." \
version="..." \
dev2.framework="PHP app"
# install packages:
RUN dev2_addtools.sh $PACKGS
# install Apache extensions:
RUN dev2_docker-apache-ext.sh $EXTR_MOD
and docker-compose.yaml
services:
proj:
build: .
ports:
- 8080:80
volumes:
- ../src:/code
cap_add: ['SYS_ADMIN']
devices:
- /dev/fuse
env_file:
- settings.env
Variables PACKGS and EXTR_MOD are not defined neither in Dockerfile nor docker-compose.yaml.
This to separate configuration from docker 'build' files, here last file of this example settings.env:
# Additional packages (if needed):
PACKGS=sl tree
# and Apache extensions:
# Note: by default 'xdebug' is already
# installed, add extensions needed by
# your project, such as gd, intl
EXTR_MOD=gd
Finally run Apache with XDebug and other dev. features:
cd docker
docker compose up
As in the example, host's ./src directory is shared with container's /code. This opens an access for Apache with Xdebug to source files making debugging a pleasure.
If set to yes, y, or on container will initialise MySQL server to be run locally through container's lifetime.
This variable can be used to indicate database host name or address. If LOCALMYSQL is set to yes, MYSQL_HOST is set automatically to localhost.
But if MYSQL_HOST is set to localhost container will initialise MySQL server for local usage as it would do if LOCALMYSQL would be set to yes.
MySQL port number of socket path (for local DB).
If LOCALMYSQL is set to yes, or MYSQL_HOST points to localhost or other destination default port 3306 is assigned.
Otherwise variable is not set.
MySQL root user password.
If LOCALMYSQL is set to yes, or MYSQL_HOST points to localhost but value has not been set, random password is assigned.
Otherwise variable is not set.
If MySQL is set for local usage, appropriate action is performed to set password as indicated.
MySQL database name.
If LOCALMYSQL is set to yes, or MYSQL_HOST points to localhost but value has not been set, 'mydb' is assigned.
Otherwise variable is not set.
If MySQL is set for local usage, appropriate action is performed to create desired database.
MySQL standard user name.
If LOCALMYSQL is set to yes, or MYSQL_HOST points to localhost but value has not been set, 'user' is assigned.
Otherwise variable is not set.
If MySQL is set for local usage, appropriate action is performed to create desired user granted with all permissions to database defined in DB_NAME.
Password for DB_USER.
If LOCALMYSQL is set to yes, or MYSQL_HOST points to localhost but value has not been set, random password is assigned.
Otherwise variable is not set.
If MySQL is set for local usage, appropriate action is performed to set password as indicated.
If set to yes, y, on or 1 prints a lot of debugging messages. Used for Dev2 development purposes and bug hunting.
User can define own scripts that will be called at the launch time:
Scripts should be located in /usr/local/bin.
Scripts are launched in alphabetical order, naming convention can be such as dev2app-deploy-stage0.sh, dev2app-deploy-stage1.sh etc.
First 'deploy' scripts are launched, followed by 'start' scripts. At the second and later container's launches only 'start' is executed.
Apache web root directory is stored in HTROOT that is available for 'deploy' and 'start' scripts. It points to standard /var/www/html -
it's recommended to use variable as rather then fixed path.
Enjoy!
Content type
Image
Digest
sha256:198a5e50d…
Size
262.9 MB
Last updated
11 months ago
docker pull 200ms/phpapache_dev2