Skip to content
10% off any project with promo code10% off with code

Docker for PHP Developers: A Minimal Setup

Contents
  1. Project layout
  2. Dockerfile for PHP 8.3
  3. docker-compose.yml
  4. Starting it
Published
Reading time
~1 min
Views
131
Reader rating
10 reviews
Author
Yevhen Fostenko
Senior Backend & DevOps Engineer
Docker for PHP Developers: A Minimal Setup Article
Need help with your website?
Describe the task on Telegram — I will assess it and suggest where to start. Reply within a day.
Message on Telegram
Free consultation and estimate. I reply quickly.

Docker lets you run the same stack locally and on the server. Here is a minimal configuration for a PHP project (OpenCart or WordPress).

Project layout

project/
├── docker-compose.yml
├── .docker/
│   ├── nginx/default.conf
│   └── php/Dockerfile
└── public_html/   # your PHP project

Dockerfile for PHP 8.3

FROM php:8.3-fpm
RUN apt-get update && apt-get install -y     libzip-dev libpng-dev libjpeg-dev libwebp-dev
RUN docker-php-ext-install pdo_mysql gd zip opcache
RUN pecl install redis && docker-php-ext-enable redis
WORKDIR /var/www/html

docker-compose.yml

services:
  nginx:
    image: nginx:alpine
    ports: ["80:80"]
    volumes:
      - ./public_html:/var/www/html
      - ./.docker/nginx:/etc/nginx/conf.d
    depends_on: [php]

  php:
    build: ./.docker/php
    volumes:
      - ./public_html:/var/www/html

  db:
    image: mariadb:11
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: mydb
    volumes: [db_data:/var/lib/mysql]

  redis:
    image: redis:alpine

volumes:
  db_data:

Starting it

docker compose up -d
docker compose ps  # check the status

Want Docker set up on your own server? Order a Docker configuration.

Tags: dockerphpnginxdevelopmentcontainers
Need help with your website?
Describe the task on Telegram — I will assess it and suggest where to start. Reply within a day.
Message on Telegram
Free consultation and estimate. I reply quickly.

Reader reviews

5.0
Write a review