A comprehensive LNMP (Linux, Nginx, MySQL, PHP) environment with Docker for development and testing purposes. This setup includes additional services such as Redis, MailHog, and Ofelia for a complete development ecosystem.
- Docker LNMP Environment
├── config.ini
├── docker-compose.yml
├── LICENSE
├── nginx
│ ├── conf
│ │ ├── fastcgi_params
│ │ ├── mime.types
│ │ ├── nginx.conf
│ │ ├── sites-conf
│ │ │ ├── general.conf
│ │ │ ├── php.conf
│ │ │ └── proxy.conf
│ │ ├── sites-enabled
│ │ │ └── domain.conf.example
│ │ └── ssl
│ │ ├── domain.com.crt
│ │ └── domain.com.key
│ └── Dockerfile
├── php-fpm
│ ├── conf
│ │ ├── pear.conf
│ │ ├── php
│ │ │ ├── conf.d
│ │ │ │ ├── docker-php-ext-*.ini
│ │ │ │ └── docker-php-ext-xdebug.ini.example
│ │ │ └── php.ini
│ │ ├── php-fpm.conf
│ │ ├── php-fpm.conf.default
│ │ └── php-fpm.d
│ │ ├── docker.conf
│ │ ├── www.conf
│ │ ├── www.conf.default
│ │ └── zz-docker.conf
│ ├── Dockerfile
│ └── mhsendmail_linux_amd64
└── README.md
-
Clone this repository:
git clone https://github.com/hirale/docker.git cd docker
-
Copy the example environment file:
cp .env.example .env
-
Set up your domain configuration in Nginx:
cp nginx/conf/sites-enabled/domain.conf.example nginx/conf/sites-enabled/your-domain.conf
-
(Optional) Set up SSL configuration:
# Place your SSL certificate and key in the nginx/conf/ssl directory cp your-ssl-cert.crt nginx/conf/ssl/domain.com.crt cp your-ssl-key.key nginx/conf/ssl/domain.com.key
-
Customize the
.env
file with your preferred settings.
The .env
file contains important configuration variables. Key variables include:
NGINX_VERSION
,PHP_VERSION
,MYSQL_VERSION
: Specify the versions of Nginx, PHP, and MySQL to use.MYSQL_DATABASE
,MYSQL_USER
,MYSQL_PASSWORD
,MYSQL_ROOT_PASSWORD
: MySQL configuration.WEB_ROOT
: The path to your web projects.NGINX_CONFIG
,PHP_CONFIG
,OFELIA_CONFIG
: Paths to configuration directories.
The docker-compose.yml
file defines the following services:
nginx
: Web serverphp-fpm
: PHP FastCGI Process Managermysql
: MySQL database servermailhog
: Email testing toolredis
: In-memory data structure storeofelia
: Job scheduler
Starting the environment:
docker compose -p your-project-name up -d
Stopping the environment:
docker compose -p your-project-name down
Accessing containers (e.g., php-fpm):
docker exec -it -u www-data php-fpm /bin/bash
- Main configuration:
nginx/conf/nginx.conf
- Site configurations:
nginx/conf/sites-enabled/
- SSL certificates:
nginx/conf/ssl/
- PHP-FPM configuration:
php-fpm/conf/php-fpm.conf
- PHP INI:
php-fpm/conf/php/php.ini
- PHP extensions:
php-fpm/conf/php/conf.d/
To enable and configure Xdebug for PHP debugging:
-
Enable
xdebug
:mv php-fpm/conf/php/conf.d/docker-php-ext-xdebug.ini.example php-fpm/conf/php/conf.d/docker-php-ext-xdebug.ini docker restart php-fpm
-
Configure your IDE to listen for PHP Debug connections on port 9003.
MySQL is configured using environment variables in the docker-compose.yml
file and .env
file.
Redis uses the default configuration. To customize, add a redis.conf
file and mount it as a volume in docker-compose.yml
.
MailHog uses the default configuration. The mhsendmail_linux_amd64
binary in the php-fpm
directory can be used to send emails to MailHog for testing.
Ofelia is configured using the config.ini
file in the root directory.
This script allows you to easily manage multiple PHP versions in your Docker LNMP environment. You can add or remove PHP versions and their corresponding configurations with simple commands.
The script provides two main functionalities:
- Add a new PHP version: This will copy the existing
php-fpm
configuration and create a new service(e.g.,php-fpm74
) in thedocker-compose.yml
file. - Remove an existing PHP version: This will remove the corresponding service from
docker-compose.yml
and delete the relatedphp-fpm
directory.
./manage-php-version.sh
Services are connected to a custom network named backend
with predefined IP addresses. The network uses the subnet 172.20.0.0/16.
mysql
: Persists MySQL data
- Check Docker logs:
docker compose -p your-project-name logs
- Verify running containers:
docker compose -p your-project-name ps
- Ensure correct paths in
.env
file - Check for port conflicts
Contributions to hirale/docker are welcome! Please submit Pull Requests or open Issues on the GitHub repository.
This project is licensed under the MIT License - see the LICENSE file for details.