Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
## php version
PHP_VERSION=8.4
PHP_VERSION=8.5
#PHP_VERSION=8.1
#PHP_VERSION=8.0

## php extensions (space separated)
PHP_EXTENSIONS=gd pdo_mysql bcmath soap intl zip imagick redis xdebug curl simplexml mbstring sqlite3 xml mysqli @composer
PHP_EXTENSIONS="gd pdo_mysql bcmath soap intl zip imagick redis xdebug curl simplexml mbstring sqlite3 xml mysqli @composer"

## database credentials
#MYSQL_DATABASE=database
MYSQL_USER=
MYSQL_PASSWORD=
MYSQL_ROOT_PASSWORD=

MSSQL_PASSWORD="sa04JTLsa04JTL!"

## bash extensions (space separated)
BASH_EXTENSIONS=git default-mysql-client openssh-client wget curl nano unzip
BASH_EXTENSIONS="bash git default-mysql-client openssh-client wget curl nano unzip"

## node version (node for latest version, else use xx.xx.x)
NODE_VERSION=

## apache modules (space separated)
APACHE_EXTENSIONS=vhost_alias rewrite proxy_fcgi
APACHE_EXTENSIONS="vhost_alias rewrite proxy_fcgi"

## local Name, User ID and Group ID (GID/UID should usually be 1000)
USERNAME=
UID=
GID=

WORKDIR=../../Public/

38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ Required Modules: vhost_alias rewrite proxy_fcgi

2. Use `docker compose --build` this will start pulling and building the images. This process will take a lot of time so be patient. If the **PHP_VERSION** is changed in the **.env** file the build process for the cli container needs to be repeated. This step is only needed once for every **PHP_VERSION** if you need them.

3. If you need to switch the server php-fpm version, create an empty file in your project root with one of the following names: 80.phpversion / 81.phpversion / 82.phpversion no restart required.
3. If you need to switch the server php-fpm version, create an empty file in your project root with one of the following names: **80.phpversion** / **81.phpversion** / **82.phpversion** no restart required.

4. Once the images are built, the container can be started with `docker compose up -d`.

5. All your projects will be reachable via wildcard domain, the pattern is **foldername.localhost** to reach the **root** of your project or **foldername.public.localhost** to reach the **public** folder of your project, if you wish to change the domain ending it has to be changed in **./data/apache/wildcard.conf** on line 2
5. All your projects will be reachable via wildcard domain, the pattern is **foldername.test** to reach the **root** of your project or **foldername.public.test** to reach the **public** folder of your project, if you wish to change the domain ending it has to be changed in **./data/apache/wildcard.conf**.

6. Domains ending in .localhost always loop back to 127.0.0.1 so there is no need for a dns service like dnsmasq.
6. Domains ending in .test require a local DNS resolver like **dnsmasq** or manual entries in **/etc/hosts** (e.g. `127.0.0.1 foldername.test`) to resolve to 127.0.0.1.

7. **.ssh** and **.gitconfig** for the **cli** image will be mounted from the host home directory to the container user home directory as defined in the .env file. So the files need to be created and stored on the host first.

Expand All @@ -68,3 +68,35 @@ Required Modules: vhost_alias rewrite proxy_fcgi
10. **MariaDB Database** can be accessed with external database management tool like **dbeaver** and alike using **localhost:3306** as host. Databases will be persisted in **./databases** folder.

11. To access the **bash cli** run the following command to start a cli container which closes itself after exiting: `docker compose run --rm cli`

## Shell Aliases
To make working with the container easier, you can register a set of aliases that wrap the most common `docker compose` commands so you can run them from any directory.

To avoid hardcoding the path, run the following snippet **from the repository root** (the directory containing `docker-compose.yml`). It captures the current path with `$(pwd)` and writes the aliases with the absolute path baked in into your `~/.zshrc` (use `~/.bashrc` for bash):

```bash
DEV_CONTAINER_PATH="$(pwd)"
cat >> ~/.zshrc <<EOF

# php-dev-container aliases
alias devup="(cd $DEV_CONTAINER_PATH && docker compose up -d)"
alias devdown="docker compose -f $DEV_CONTAINER_PATH/docker-compose.yml down"
alias devrestart="(cd $DEV_CONTAINER_PATH && docker compose down && docker compose up -d)"
alias devlogs="docker compose -f $DEV_CONTAINER_PATH/docker-compose.yml logs"
EOF
```

Since the heredoc is unquoted, `$DEV_CONTAINER_PATH` is expanded **at the time the snippet runs**, so the resulting lines in `~/.zshrc` will contain the absolute path of the repository.

The start aliases (`devup` / `devrestart`) `cd` into the repository in a subshell instead of pointing at `docker-compose.yml` directly. This way `docker compose` automatically merges a `docker-compose.override.yml` if one is present. The subshell `( ... )` ensures the working directory of your shell does not change.

After running it, reload your shell config (e.g. `source ~/.zshrc`) and use the aliases as follows:

>- **devup**
> Starts the dev container in detached mode.
>- **devdown**
> Stops and removes the dev container.
>- **devrestart**
> Stops the container and starts it again in detached mode.
>- **devlogs**
> Shows the logs of the dev container.
2 changes: 1 addition & 1 deletion data/php/php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ auto_globals_jit = On
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; https://php.net/post-max-size
post_max_size = 8M
post_max_size = 256M

; Automatically add files before PHP document.
; https://php.net/auto-prepend-file
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
wawidb:
platform: linux/amd64

16 changes: 14 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
stop_grace_period: 0.3s
networks:
default:
aliases:
#aliases:
# enter urls that should be available via curl in the web container here, e.g.:
# - myapp.test
php-8.0:
Expand All @@ -30,8 +30,10 @@ services:
dockerfile: fpm.dockerfile
args:
- PHP_EXTENSIONS=${PHP_EXTENSIONS}
- BASH_EXTENSIONS=${BASH_EXTENSIONS}
- PHP_VERSION=8.0
- USERNAME=${USERNAME}
- NODE_VERSION=${NODE_VERSION}
user: ${UID}:${GID}
volumes:
- ${WORKDIR}:/var/www/html/
Expand All @@ -47,8 +49,10 @@ services:
dockerfile: fpm.dockerfile
args:
- PHP_EXTENSIONS=${PHP_EXTENSIONS}
- BASH_EXTENSIONS=${BASH_EXTENSIONS}
- PHP_VERSION=8.1
- USERNAME=${USERNAME}
- NODE_VERSION=${NODE_VERSION}
user: ${UID}:${GID}
volumes:
- ${WORKDIR}:/var/www/html/
Expand All @@ -64,8 +68,10 @@ services:
dockerfile: fpm.dockerfile
args:
- PHP_EXTENSIONS=${PHP_EXTENSIONS}
- BASH_EXTENSIONS=${BASH_EXTENSIONS}
- PHP_VERSION=8.2
- USERNAME=${USERNAME}
- NODE_VERSION=${NODE_VERSION}
user: ${UID}:${GID}
volumes:
- ${WORKDIR}:/var/www/html/
Expand All @@ -81,8 +87,10 @@ services:
dockerfile: fpm.dockerfile
args:
- PHP_EXTENSIONS=${PHP_EXTENSIONS}
- BASH_EXTENSIONS=${BASH_EXTENSIONS}
- PHP_VERSION=8.3
- USERNAME=${USERNAME}
- NODE_VERSION=${NODE_VERSION}
user: ${UID}:${GID}
volumes:
- ${WORKDIR}:/var/www/html/
Expand All @@ -98,8 +106,10 @@ services:
dockerfile: fpm.dockerfile
args:
- PHP_EXTENSIONS=${PHP_EXTENSIONS}
- BASH_EXTENSIONS=${BASH_EXTENSIONS}
- PHP_VERSION=8.4
- USERNAME=${USERNAME}
- NODE_VERSION=${NODE_VERSION}
user: ${UID}:${GID}
volumes:
- ${WORKDIR}:/var/www/html/
Expand All @@ -115,8 +125,10 @@ services:
dockerfile: fpm.dockerfile
args:
- PHP_EXTENSIONS=${PHP_EXTENSIONS}
- BASH_EXTENSIONS=${BASH_EXTENSIONS}
- PHP_VERSION=8.5
- USERNAME=${USERNAME}
- NODE_VERSION=${NODE_VERSION}
user: ${UID}:${GID}
volumes:
- ${WORKDIR}:/var/www/html/
Expand All @@ -141,7 +153,7 @@ services:
container_name: mssql
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=
- MSSQL_SA_PASSWORD=${MSSQL_PASSWORD}
- MSSQL_OID=Express
- MSSQL_COLLATION=Latin1_General_CI_AS
ports:
Expand Down
13 changes: 13 additions & 0 deletions dockerfiles/fpm.dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
ARG PHP_VERSION=${PHP_VERSION}
ARG NODE_VERSION=${NODE_VERSION:24}

##########################################################################################################

FROM node:${NODE_VERSION}-alpine AS node

FROM php:${PHP_VERSION}-fpm-alpine

#update/upgrade packages
RUN apk update && apk upgrade

#install desired bash extensions
ARG BASH_EXTENSIONS=${BASH_EXTENSIONS}
RUN apk add ${BASH_EXTENSIONS}

#include php extension installer script because image provided method sucks balls
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions
Expand All @@ -15,4 +22,10 @@ RUN chmod +x /usr/local/bin/install-php-extensions
ARG PHP_EXTENSIONS=${PHP_EXTENSIONS}
RUN install-php-extensions ${PHP_EXTENSIONS}

#copy node files from other image
COPY --from=node /usr/local/bin/node /usr/local/bin/node
COPY --from=node /usr/local/bin/npm /usr/local/bin/npm
COPY --from=node /usr/local/bin/npx /usr/local/bin/npx
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules

##########################################################################################################