This repository sets up a development environment using Docker for a PHP application with Nginx, MySQL or PostgreSQL, Redis, and Composer. This environment is suitable for developing applications like Laravel and Moodle.
- Docker
- Docker Compose
git clone https://github.com/your-repository.git
cd your-repository
cp .env.example .env
Update the .env file with your preferred settings. You can set PHP version, database configuration, and PHP extensions as needed.
docker compose up --build
This command will build the Docker images and start the containers for Nginx, PHP, MySQL/PostgreSQL, and Redis.
project-root/
├── README.md
├── bin
│ └── php
│ └── Dockerfile
├── config
│ ├── nginx
│ │ ├── default.conf
│ │ ├── laravel.conf
│ │ └── moodle.conf
│ └── php
│ └── php.ini
├── data
│ ├── certbot
│ │ ├── conf
│ │ └── www
│ ├── mysql
│ └── postgres
├── docker-compose.yml
└── www
└── info.php
To install the dependencies defined in composer.json, run:
docker-compose run --rm php composer install
To update the dependencies, run:
docker-compose run --rm php composer update
By default, the .env
file is configured to use MySQL. To switch to PostgreSQL:
- Change the
DB_CONNECTION
variable in the.env
file topostgres
. - Change the
DB_HOST
variable topostgres
. - Change the
DB_PORT
variable to5432
. - Comment out or delete the MySQL service definition in
docker-compose.yml
. - Uncomment or add the PostgreSQL service definition in
docker-compose.yml
.
Example .env
for PostgreSQL
DB_CONNECTION=postgres
DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=my_database
DB_USERNAME=user
DB_PASSWORD=password
POSTGRES_DB=my_database
POSTGRES_USER=user
POSTGRES_PASSWORD=password
Example .env
for MySQL
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=my_database
DB_USERNAME=user
DB_PASSWORD=password
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=my_database
MYSQL_USER=user
MYSQL_PASSWORD=password
The PHP configuration file is located at config/php/php.ini
. You can modify this file to change PHP settings such as memory limit, upload size, etc.
The Nginx configuration file is located at config/nginx/default.conf
. You can modify this file to change the server settings as needed.
To enable HTTPS support using Let's Encrypt, follow these steps:
Open the .env
file and set ENABLE_HTTPS=true
. Make sure to also set LETSENCRYPT_DOMAIN
to your domain name and LETSENCRYPT_EMAIL
to your email address.
Example:
ENABLE_HTTPS=true
LETSENCRYPT_DOMAIN=yourdomain.com
LETSENCRYPT_EMAIL=[email protected]
Uncoment https configuration section in config/nginx/default.conf
Uncoment https port in nginx section docker-compose.yml
Run the following command to build and start the containers:
docker-compose up --build
Certbot will automatically generate Let's Encrypt certificates for the specified domain. Nginx will be configured to use these certificates to enable HTTPS.
The database data is persisted in the data directory:
- MySQL data is stored in data/mysql.
- PostgreSQL data is stored in data/postgres.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is maintained by Betuah Anugerah.