This repository contains a customized Docker image for PHP development with Xdebug support. It provides an easy and consistent environment for PHP developers to write, test, and debug their applications.
- PHP: The image is based on the latest stable version of PHP, ensuring compatibility with modern PHP applications.
- Xdebug: Xdebug is preconfigured and enabled in the image, allowing seamless debugging of PHP code.
- Composer: Composer, the dependency manager for PHP, is preinstalled in the image, making it convenient to manage project dependencies.
- Extensions: The image includes commonly used PHP extensions, such as PDO, mysqli, gd, and mbstring, providing a rich development environment.
- Custom Configuration: The PHP configuration has been customized to suit development needs, including error reporting settings, time zone configuration, and memory limits.
- Docker must be installed on your machine.
-
Clone this repository to your local machine:
git clone https://github.com/your-username/php-dev-docker.git
-
Change into the cloned repository directory:
cd php-dev-docker
-
Build the Docker image:
docker build -t php-dev .
-
Run a container from the image:
docker run -d -p 8080:80 --name my-php-dev php-dev
This will start a container named
my-php-dev
and bind port 8080 of the host to port 80 of the container. You can change the port mapping according to your requirements. -
Open your browser and visit
http://localhost:8080
to see the PHP info page.
To enable debugging with Xdebug, you need to configure your IDE or editor accordingly. Here's an example configuration for Visual Studio Code:
-
Install the PHP Debug extension.
-
Open the project folder in Visual Studio Code.
-
Create a file named
.vscode/launch.json
with the following contents:{ "version": "0.2.0", "configurations": [ { "name": "Listen for Xdebug", "type": "php", "request": "launch", "port": 9000, "log": true, "pathMappings": { "/var/www/html": "${workspaceFolder}" } } ] }
-
Set breakpoints in your PHP code.
-
Start the container in debug mode:
docker run -d -p 8080:80 -p 9000:9000 --name my-php-dev php-dev
-
Start the debugging session in Visual Studio Code by clicking on the "Run and Debug" button or using the
F5
key.
Now, when you access your PHP application in the browser, Visual Studio Code will pause at the breakpoints, allowing you to step through the code and inspect variables.
You can customize the Dockerfile and PHP configuration files according to your specific requirements. Feel free to modify them to suit your needs.
This project is licensed under the MIT License.
Contributions to this project are welcome. Feel free to open issues or submit pull requests to enhance the Docker image or add new features.