Sign inSign up

vnvsa/php

By vnvsa

Updated 3 days ago

PHP Containers for local development

Image
Developer tools
Web servers
1

50K+

vnvsa/php repository overview

PHP Developement container

Docker container for local PHP development :

This image comes with the following tools installed :

Caution

This image is intended for **local development only**, we do not ensure production optimizations and securities measures.

Supported tags

Retired (deprecated) tags

These tags are available on all images. Eg: vnvsa/magento:8.5-cli-trixie, vnvsa/wordpress:8.5-fpm-bookworm

Magento specific tags

Magento retired (deprecated) tags

The composer tags are available on magento images only. Eg: vnvsa/magento:8.4-cli-bullseye-composer2.6

How to use this image

In Gitlab CI/CD

For vnvsa/php, vnvsa/magento and vnvsa/wordpress
stages:
  - test

php:unit_tests:
  stage: test
  image: vnvsa/php:8.5-cli
  variables:
    XDEBUG_MODE: coverage
  coverage: '/^\s*Lines:\s*\d+.\d+\%/'
  before_script:
    - composer install --optimize-autoloader --no-interaction --no-progress
  script:
    - vendor/bin/phpunit --colors=never --log-junit phpunit-report.xml --coverage-text --coverage-cobertura=coverage.cobertura.xml
  artifacts:
    reports:
      junit: phpunit-report.xml
      coverage_report:
        coverage_format: cobertura
        path: coverage.cobertura.xml
    when: always
  cache:
    key:
      files:
        - composer.lock
    paths:
      - ./vendor
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
    when: never
    - if: '$CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_PIPELINE_SOURCE == "webide"'
For vnvsa/symfony
stages:
	- test

php:unit_tests:
	stage: test
	image: vnvsa/symfony:8.5-cli
	variables:
		XDEBUG_MODE: coverage
	coverage: '/^\s*Lines:\s*\d+.\d+\%/'
	before_script:
		- composer install --optimize-autoloader --no-interaction --no-progress
	script:
		- vendor/bin/simple-phpunit --colors=never --log-junit phpunit-report.xml --coverage-text --coverage-cobertura=coverage.cobertura.xml
	artifacts:
		reports:
			junit: phpunit-report.xml
      coverage_report:
        coverage_format: cobertura
        path: coverage.cobertura.xml
		when: always
	cache:
		key:
			files:
				- composer.lock
		paths:
			- ./vendor
	rules:
		- if: '$CI_PIPELINE_SOURCE == "schedule"'
		when: never
		- if: '$CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_PIPELINE_SOURCE == "webide"'

In a Dockerfile

For vnvsa/php
# Optionally define the time zone
# ARG TZ="UTC"

FROM vnvsa/php:8.5-cli

# Reset to "root" user
USER root

# Install something
RUN apt-get install -yqq vim \
	&& pie install phpredis/phpredis

COPY . /app # or mount a folder directly to /app

# Restore "dev" user
USER dev

CMD [ "php", "./your-script.php" ]
For vnvsa/symfony
FROM vnvsa/symfony:8.5-fpm

# Reset to "root" user
USER root

# Install something
RUN apt-get install -yqq vim \
	&& pie install phpredis/phpredis

COPY . /app # or mount a folder directly to /app

# Restore "symfony" user
USER symfony
For vnvsa/magento
# Optionally define the time zone
# ARG TZ="UTC"

FROM vnvsa/magento:8.5-fpm

# Reset to "root" user
USER root

# Install something
RUN apt-get install -yqq vim \
	&& pie install phpredis/phpredis

COPY . /app # or mount a folder directly to /app

# Restore "magento" user
USER magento
For vnvsa/wordpress
# Optionally define the time zone
# ARG TZ="UTC"

FROM vnvsa/wordpress:8.5-fpm

# Reset to "root" user
USER root

# Install something
RUN apt-get install -yqq vim \
	&& pie install phpredis/phpredis

COPY . /app # or mount a folder directly to /app

# Restore "wordpress" user
USER wordpress

In a docker-compose.{yml,yaml} stack

For vnvsa/php, vnvsa/magento and vnvsa/wordpress
services:
    # PHP FPM needs a web server to serve requests
    php-fpm:
		# Replace the image with the variant you need for your project (eg. magento, wordpress)
        image: vnvsa/php:8.5-fpm
        entrypoint: ./docker/php/entrypoint.sh
        user: dev
        tty: true
        environment:
            - TERM=xterm-256color
        volumes:
            - ./:/app

    # NGINX or Apache
    web:
        image: nginx:latest
        ports:
            - "8000:80"
        volumes:
            - ./:/app:delegated
            # A configuration
            - ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf
        depends_on:
            - php-fpm

with the following site.conf for NGINX

server {
    listen 80 default_server;
    server_name localhost;
    root /app/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        # Must be the name of the "php" service defined in docker-compose stack. Eg: "php-fpm"
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Your application is now available at http://localhost:8000

For vnvsa/symfony

Since the vnvsa/symfony comes with symfony-cli tool, it use the bundled webserver from symfony "server:start" command to serve requests with HTTPS support, so we don't need another webserver like NGINX or Apache.

services:
  php:
    image: vnvsa/symfony:8.5-fpm
    user: symfony
    tty: true
    environment:
      - TERM=xterm-256color
    ports:
      - 8000:8000
    volumes:
      - ./:/app

Your application is now available at https://localhost:8000.

Configurations

User

This image run as the following user by default depending on the base image :

  • vnvsa/php run as dev
  • vnvsa/symfony run as symfony
  • vnvsa/magento run as magento
  • vnvsa/wordpress run as wordpress

Volumes

There is only one base volume configured in all images and it's the /app directory.

Exposed ports

Note

**Only for `fpm` images variant !**

The default exposed port is 9000 (from php-fpm process).

Symfony

An additional port is available for vnvsa/symfony images : 8000.

Because it use the symfony-cli to serve requests with HTTPS support by default.

By default, images allow connections from all networks interfaces/IPs (using SYMFONY_ALLOW_ALL_IP=true environment variable). If you don't want that, you can set this environment variable SYMFONY_ALLOW_ALL_IP=false and add this option to symfony-cli server:start command in your entrypoint.sh :

/usr/bin/symfony "server:start" --use-gzip --listen-ip="192.168.0.1"

PHP

These are the default PHP INI configuration values used for the image.

SettingDefault value
date.timezoneEurope/Zurich
memory_limit-1
opcache.enable1
opcache.fast_shutdown1
opcache.interned_strings_buffer16
opcache.max_accelerated_files10000
opcache.max_wasted_percentage10
opcache.memory_consumption192
opcache.revalidate_freq0
opcache.validate_timestamps1
short_open_tag (Symfony only)Off

PHP extensions

These are the extensions installed and enabled by default :

  • bcmath
  • brotli
  • exif
  • gd (with freetype, webp and xpm support)
  • imagick
  • intl
  • opcache
  • pcntl
  • pdo
  • pdo_mysql
  • pdo_pgsql
  • mysqli (Magento & Wordpress only)
  • pgsql
  • sockets
  • zip
  • xdebug
  • ftp (Magento only)
  • soap (Magento only)
  • xsl (Magento only)
  • zstd

Image variants

php:<version>-cli

Use this for your CLI applications or in CI/CD for running tests.

php:<version>-fpm

Use this for your web applications (when you need to serve requests with HTTP/HTTPS from a webserver).

Contributing

Pull requests, bug reports, and feature requests are welcome.

Contacts

License

MIT License. See the LICENSE file.

Tag summary

Content type

Image

Digest

sha256:2fe0fddbd

Size

487.1 MB

Last updated

3 days ago

docker pull vnvsa/php:8.5-cli-trixie