A highly configurable PHP-FPM Docker image based on Ubuntu with Xdebug support, designed for development environments.
- Based on Ubuntu (configurable version)
- PHP support (configurable version)
- Xdebug pre-configured
- Composer included
- Symfony CLI included
- Fully configurable via environment variables
- Redis, PostgreSQL, SQLite, and MySQL support
- YAML, AMQP, and APCu extensions
bash
# Pull the image
docker pull yourusername/php-fpm:latest
# Run with Docker
docker run -p 9000:9000 -v $(pwd):/var/www/html yourusername/php-fpm:latest
Create a docker-compose.yml
file:
version: '3.8'
services:
php-fpm:
image: pusachev/php-fpm:latest
ports:
- "9000:9000"
volumes:
- ./:/var/www/html
- ./conf/php/xdebug.ini:/etc/php/8.4/mods-available/xdebug.ini
environment:
PHP_IDE_CONFIG: "serverName=docker"
XDEBUG_ENABLED: "1" # Enable Xdebug (set to 0 to disable)
extra_hosts:
- "host.docker.internal:host-gateway"
Run with:
docker-compose up -d
The image can be configured using a file with the following variables: .env
# Base configuration
UBUNTU_VERSION=24.04
PHP_VERSION=8.4
# PHP configuration
PHP_MEMORY_LIMIT=756M
PHP_UPLOAD_MAX_FILESIZE=100M
PHP_POST_MAX_SIZE=100M
PHP_MAX_EXECUTION_TIME=300
# Working directory
WORKING_DIR=/var/www/html
You can build your own version of the image with custom configurations:
# Clone the repository
git clone https://github.com/pusachev/docker-php-fpm.git
cd docker-php-fpm
# Edit .env file with your preferred settings
# Then build the image
docker build -t custom-php-fpm .
Or specify build arguments directly:
docker build -t custom-php-fpm \
--build-arg UBUNTU_VERSION=22.04 \
--build-arg PHP_VERSION=8.2 \
--build-arg PHP_MEMORY_LIMIT=1024M \
.
Xdebug is pre-configured for use with PhpStorm. The default configuration is:
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.start_with_request=trigger
xdebug.discover_client_host=0
xdebug.idekey=PHPSTORM
You can override this configuration by mounting your own file: xdebug.ini
volumes:
- ./my-xdebug.ini:/etc/php/8.4/mods-available/xdebug.ini
The repository includes a convenient build.sh
script that automates the process of rebuilding and pushing the PHP-FPM Docker image. This script performs the following actions:
- Reads the PHP version from the
.env
file - Stops any running containers that use the image
{vendor}/php-fpm:{php-version}
- Removes the existing image locally
- Rebuilds the image from the Dockerfile
- Pushes the newly built image to Docker Hub
To use the script:
- Make the script executable (first time only)
chmod +x build.sh
- Run the script
./build.sh
Note: This script assumes you are already authenticated with Docker Hub. If not, run docker login
before running the script.
The image comes with the following PHP extensions pre-installed:
- fpm, cli, common
- gd, curl, intl, mbstring
- mysql, xml, zip, bcmath
- soap, xsl, sockets, opcache
- xdebug, ctype, iconv, tokenizer
- dom, simplexml, pdo, pgsql
- sqlite3, redis, apcu, amqp, yaml
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request