This repository contains a Dockerized PHP application setup with hot reload functionality for PHP file changes. This setup uses Docker and Docker Compose to streamline the development environment.
Before you begin, ensure you have the following installed on your local machine:
- Docker: Install Docker
- Docker Compose: Install Docker Compose
Follow these steps to set up and run the Dockerized PHP application locally:
git clone <repository-url>
cd <repository-directory>Run the following command to build and start the Docker containers defined in docker-compose.yml:
docker-compose up --buildOpen your web browser and go to http://localhost:8080 to view the PHP application.
- PHP Version: PHP 7.4 with Apache server.
- Composer: Dependencies are managed using Composer.
composer installis automatically run during the Docker build process to install PHPMailer and other dependencies. - Hot Reload: Uses
inotifywaitto monitor PHP file changes and trigger actions like cache clearing or Apache server restart for instant updates.
The project directory structure is as follows:
my-php-app/
├── Dockerfile
├── docker-compose.yml
└── src/
├── index.php
└── composer.json
Dockerfile: Defines the Docker image for PHP application setup.docker-compose.yml: Orchestrates multiple Docker containers (PHP and Composer).src/: Contains PHP application files (index.php) andcomposer.jsonfor Composer dependencies.
To enable hot reload for PHP file changes, a watch.sh script is provided:
-
Enter the PHP container:
docker-compose exec php bash -
Run the
watch.shscript:./watch.sh
The script monitors changes in the src/ directory and triggers actions (e.g., Apache server restart) for instant updates.
- Modify
composer.jsonin thesrc/directory to add or update PHP dependencies. - Adjust the
Dockerfileordocker-compose.ymlfor specific PHP configurations or additional services.
- This setup is intended for development environments. Review security and performance considerations before deploying to production.
- Ensure proper permissions and file paths are set up, especially with volume mounts and file watching mechanisms.