The Braz PHP Docker project provides a set of Docker images tailored for various PHP environments and use cases.
It simplifies the process of setting up PHP development environments by offering pre-configured images for different frameworks and tools, such as Vanilla PHP, Composer, Symfony, WP-CLI, and Phalcon.
These images support multiple PHP versions and architectures, ensuring compatibility and flexibility for developers.
We also provide an AI generated DeepWiki Page with more technical information.
💡 For a complete list of available images, please visit the PHP System Docs page.
To use the images, you can pull them from Docker Hub and run them with your PHP scripts or commands. Here are some examples of how to use the images:
Docker Image | Entrypoint | Command Example | Build Status |
---|---|---|---|
php-cli | /usr/bin/php |
docker run -v $(pwd):/workspace --rm fbraz3/php-cli:8.4 myscript.php |
|
phalcon | /usr/bin/php |
docker run -v $(pwd):/workspace --rm fbraz3/php-cli:8.4-phalcon myscript.php |
|
php-composer | /usr/local/bin/composer |
docker run -v $(pwd):/workspace --rm fbraz3/php-composer:8.4 init |
|
wp-cli | /usr/local/bin/wp |
docker run -v $(pwd):/workspace --rm fbraz3/wp-cli:8.4 plugin install bbpress |
|
symfony-cli | /usr/local/bin/symfony |
docker run -v $(pwd):/workspace --rm fbraz3/symfony-cli:8.4 server:start |
# Run a standalone PHP script
docker run -it --rm fbraz3/php-cli:latest php myscript.php
# Run a PHP built-in server with Phalcon framework support
docker run -it --rm -v $(pwd):/workspace -p 8000:8000 fbraz3/php-cli:latest-phalcon php -S localhost:8000
# Install a fresh wordpress using wp-cli
docker run -it --rm -v $(pwd):/workspace fbraz3/wp-cli:latest core download --path=/workspace
# Install a fresh symfony using symfony-cli
docker run -it --rm -v $(pwd):/workspace fbraz3/symfony-cli:latest new my_project_name
You may want to add these executable aliases to your .bashrc
or .zshrc
for convenience.
PHP_VERSION=8.4 # Replace with your preferred PHP version
php() { docker run -v "$(pwd):/workspace" --rm fbraz3/php-cli:$PHP_VERSION "$@"; }
composer() { docker run -v "$(pwd):/workspace" --rm fbraz3/php-composer:$PHP_VERSION "$@"; }
wp() { docker run -v "$(pwd):/workspace" --rm fbraz3/wp-cli:$PHP_VERSION "$@"; }
symfony() { docker run -v "$(pwd):/workspace" --rm fbraz3/symfony-cli:$PHP_VERSION "$@"; }
Each image is tagged with the PHP version. For example:
fbraz3/php-cli:8.4
for PHP 8.4fbraz3/php-cli:8.4-phalcon
for PHP 8.4 with Phalcon extensionfbraz3/php-composer:8.4
for PHP 8.4 with Composerfbraz3/symfony-cli:8.4
for PHP 8.4 with Symfony CLIfbraz3/wp-cli:8.4
for PHP 8.4 with WP-CLI
This project includes the following flavors:
- Vanilla PHP: A base PHP image with essential extensions and tools.
- Composer: An image with Composer pre-installed for dependency management.
- Symfony: An image with the Symfony CLI pre-installed for Symfony projects.
- WP-CLI: An image with WP-CLI pre-installed for managing WordPress installations.
- Phalcon: An image with the Phalcon PHP framework pre-installed.
Each flavor supports multiple PHP versions, ranging from 5.6 to 8.4, and is available for both amd64
and arm64
architectures.
The images are designed to run as the php
user by default (uid 1000). If you need to run commands as the root user, you can use the --user
flag when running the container.
If you need to write to a mounted volume, ensure that the php
user has the necessary permissions. You can set the ownership of the mounted directory to the php
user by running:
chown -R 1000:1000 /path/to/your/directory
A workaround for this is to chmod the mounted directory to 777
before running the container. This will allow all users to read, write, and execute files in that directory. However, this is not recommended for production environments due to security concerns.
There is another workaround for this running the container with the --user
flag set to root
, but this is also not recommended for production environments.
The default directory for the container is /workspace
, but you can change it by setting the WORKDIR
environment variable in your Dockerfile or when running the container.
All images have ssmtp pre-installed and configured to send emails. The default SMTP server is localhost
on port 25
. You can use the mail()
function in PHP to send emails from the container.
It's recommended to change the default SMTP server to your own SMTP server. You can do this by setting the SMTP
environment variable when running the container. For example:
docker run -v $pwd:/workspace -e SMTP_MAIL_SERVER=smtp.example.com -e SMTP_AUTH_USER=username -e SMTP_AUTH_PASSWORD=password --rm fbraz3/php-cli:8.4 mail_sending.php
For example, create a .env
file with the following content:
SMTP_MAIL_SERVER=smtp.example.com
SMTP_AUTH_USER=username
SMTP_AUTH_PASSWORD=password
Then run the container with the --env-file
option:
docker run -v $pwd:/workspace --env-file .env --rm fbraz3/php-cli:8.4 mail_sending.php
To validate all environment variables you can use for mail sending, please check the file ssmtp.sh.
Is also recommended to refer to ssmtp documentation for more information about its configuration.
Contributions are welcome! Feel free to open issues or submit pull requests to improve the project.
Please visit the CONTRIBUTING.md file for guidelines on how to contribute to this project.
I spend a lot of time and effort maintaining this project. If you find it useful, consider supporting me with a donation:
This project is licensed under the Apache License 2.0, so you can use it for personal and commercial projects. However, please note that the images are provided "as is" without any warranty or guarantee of any kind. Use them at your own risk.