Skip to content

Commit cc648e9

Browse files
committed
Refactor environment variables and port configuration
This commit enhances the flexibility and organization of the environment: 1. Add port customization for all services: - Allow configuration of all service ports through environment variables - Provide sensible defaults to prevent conflicts - Enable running multiple instances of the project simultaneously 2. Replace PHP runtime configuration with INI file selection: - Add PHP_INI variable to select the appropriate configuration file - Remove redundant PHP_DISPLAY_ERRORS, PHP_MEMORY_LIMIT variables - Simplify configuration management by centralizing settings in INI files 3. Improve variable organization in .env files: - Group related variables together - Rename APP_NAME for better clarity (was PROJECT_NAME) - Standardize variable naming conventions These changes improve the maintainability, flexibility, and clarity of the environment configuration while reducing duplication and potential inconsistencies.
1 parent 2d6a71d commit cc648e9

File tree

4 files changed

+116
-86
lines changed

4 files changed

+116
-86
lines changed

.env

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
# Development environment configuration
2-
PROJECT_NAME=docker_nginx_php_mysql
2+
3+
# Application configuration
4+
APP_NAME=docker_nginx_php_mysql
5+
APP_WORKSPACE=default
6+
APP_DIR=app
7+
APP_PUBLIC_DIR=$(APP_DIR)/public
38

49
# Common settings
510
NGINX_HOST=localhost
11+
NGINX_PORT=8000
12+
13+
# Nginx SSL Certificate configuration
14+
NGINX_SSL_PORT=3000
15+
NGINX_SSL_COUNTRY=US
16+
NGINX_SSL_STATE=State
17+
NGINX_SSL_LOCALITY=City
18+
NGINX_SSL_ORGANIZATION=Organization
19+
NGINX_SSL_UNIT=IT
20+
NGINX_SSL_EMAIL=admin@example.com
21+
NGINX_SSL_DAYS=365
22+
NGINX_SSL_KEY_SIZE=4096
623

7-
# Service versions
24+
# PHP configuration
825
PHP_VERSION=8.3
926
PHP_TARGET=dev
10-
MYSQL_VERSION=9.2
27+
PHP_INI=php.prod.ini
28+
29+
PHP_DISPLAY_ERRORS=1
30+
PHP_MEMORY_LIMIT=256M
31+
XDEBUG_ENABLED=1
1132

1233
# MySQL configuration
34+
MYSQL_VERSION=9.2
1335
MYSQL_HOST=mysql
36+
MYSQL_PORT=8989
1437
MYSQL_DATABASE=test
1538
MYSQL_ROOT_USER=root
1639
MYSQL_ROOT_PASSWORD=root
1740
MYSQL_USER=dev
1841
MYSQL_PASSWORD=dev
1942

2043
# PHPMyAdmin configuration
44+
PHPMYADMIN_PORT=8080
2145
PHPMYADMIN_PROFILE=dev
2246
PHPMYADMIN_USER=root
2347
PHPMYADMIN_PASSWORD=root
2448
PHPMYADMIN_UPLOAD_LIMIT=100M
2549

26-
# Nginx SSL Certificate configuration
27-
NGINX_SSL_COUNTRY=US
28-
NGINX_SSL_STATE=State
29-
NGINX_SSL_LOCALITY=City
30-
NGINX_SSL_ORGANIZATION=Organization
31-
NGINX_SSL_UNIT=IT
32-
NGINX_SSL_EMAIL=admin@example.com
33-
NGINX_SSL_DAYS=365
34-
NGINX_SSL_KEY_SIZE=4096
35-
36-
# PHP configuration
37-
PHP_DISPLAY_ERRORS=1
38-
PHP_MEMORY_LIMIT=256M
39-
XDEBUG_ENABLED=1
40-
41-
# Application configuration
42-
APP_WORKSPACE=default
43-
APP_DIR=app
44-
APP_PUBLIC_DIR=$(APP_DIR)/public
45-
4650
# MailHog configuration
4751
MAILHOG_SMTP_PORT=1025
4852
MAILHOG_UI_PORT=8025
4953
MAILHOG_STORAGE=memory
5054
MAILHOG_HOSTNAME=mailhog
5155
MAILHOG_CORS_ORIGIN=*
56+
57+
# API documentation configuration
58+
APIDOCS_PORT=8081

.env.dev

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
# Development environment configuration
2-
PROJECT_NAME=docker_nginx_php_mysql
2+
3+
# Application configuration
4+
APP_NAME=docker_nginx_php_mysql
5+
APP_WORKSPACE=default
6+
APP_DIR=app
7+
APP_PUBLIC_DIR=$(APP_DIR)/public
38

49
# Common settings
510
NGINX_HOST=localhost
11+
NGINX_PORT=8000
12+
13+
# Nginx SSL Certificate configuration
14+
NGINX_SSL_PORT=3000
15+
NGINX_SSL_COUNTRY=US
16+
NGINX_SSL_STATE=State
17+
NGINX_SSL_LOCALITY=City
18+
NGINX_SSL_ORGANIZATION=Organization
19+
NGINX_SSL_UNIT=IT
20+
NGINX_SSL_EMAIL=admin@example.com
21+
NGINX_SSL_DAYS=365
22+
NGINX_SSL_KEY_SIZE=4096
623

7-
# Service versions
24+
# PHP configuration
825
PHP_VERSION=8.3
926
PHP_TARGET=dev
10-
MYSQL_VERSION=9.2
27+
PHP_INI=php.dev.ini
28+
29+
PHP_DISPLAY_ERRORS=1
30+
PHP_MEMORY_LIMIT=256M
31+
XDEBUG_ENABLED=1
1132

1233
# MySQL configuration
34+
MYSQL_VERSION=9.2
1335
MYSQL_HOST=mysql
36+
MYSQL_PORT=8989
1437
MYSQL_DATABASE=test
1538
MYSQL_ROOT_USER=root
1639
MYSQL_ROOT_PASSWORD=root
1740
MYSQL_USER=dev
1841
MYSQL_PASSWORD=dev
1942

2043
# PHPMyAdmin configuration
44+
PHPMYADMIN_PORT=8080
2145
PHPMYADMIN_PROFILE=dev
2246
PHPMYADMIN_USER=root
2347
PHPMYADMIN_PASSWORD=root
2448
PHPMYADMIN_UPLOAD_LIMIT=100M
2549

26-
# Nginx SSL Certificate configuration
27-
NGINX_SSL_COUNTRY=US
28-
NGINX_SSL_STATE=State
29-
NGINX_SSL_LOCALITY=City
30-
NGINX_SSL_ORGANIZATION=Organization
31-
NGINX_SSL_UNIT=IT
32-
NGINX_SSL_EMAIL=admin@example.com
33-
NGINX_SSL_DAYS=365
34-
NGINX_SSL_KEY_SIZE=4096
35-
36-
# PHP configuration
37-
PHP_DISPLAY_ERRORS=1
38-
PHP_MEMORY_LIMIT=256M
39-
XDEBUG_ENABLED=1
40-
41-
# Application configuration
42-
APP_WORKSPACE=default
43-
APP_DIR=app
44-
APP_PUBLIC_DIR=$(APP_DIR)/public
45-
4650
# MailHog configuration
4751
MAILHOG_SMTP_PORT=1025
4852
MAILHOG_UI_PORT=8025
4953
MAILHOG_STORAGE=memory
5054
MAILHOG_HOSTNAME=mailhog
51-
MAILHOG_CORS_ORIGIN=*
55+
MAILHOG_CORS_ORIGIN=*
56+
57+
# API documentation configuration
58+
APIDOCS_PORT=8081

.env.prod

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
# Production environment configuration
2-
PROJECT_NAME=docker_nginx_php_mysql
1+
# Development environment configuration
2+
3+
# Application configuration
4+
APP_NAME=docker_nginx_php_mysql
5+
APP_WORKSPACE=default
6+
APP_DIR=app
7+
APP_PUBLIC_DIR=$(APP_DIR)/public
38

49
# Common settings
510
NGINX_HOST=localhost
6-
7-
# Service versions
8-
PHP_VERSION=8.3
9-
PHP_TARGET=base
10-
MYSQL_VERSION=9.2
11-
12-
# MySQL configuration
13-
MYSQL_HOST=mysql
14-
MYSQL_DATABASE=prod
15-
MYSQL_ROOT_USER=root
16-
MYSQL_ROOT_PASSWORD=secure_root_password
17-
MYSQL_USER=app
18-
MYSQL_PASSWORD=secure_app_password
19-
20-
# PHPMyAdmin configuration
21-
PHPMYADMIN_PROFILE=none
11+
NGINX_PORT=8000
2212

2313
# Nginx SSL Certificate configuration
14+
NGINX_SSL_PORT=3000
2415
NGINX_SSL_COUNTRY=US
2516
NGINX_SSL_STATE=State
2617
NGINX_SSL_LOCALITY=City
@@ -31,12 +22,37 @@ NGINX_SSL_DAYS=365
3122
NGINX_SSL_KEY_SIZE=4096
3223

3324
# PHP configuration
34-
PHP_DISPLAY_ERRORS=0
35-
PHP_MEMORY_LIMIT=128M
36-
XDEBUG_ENABLED=0
37-
PHPMYADMIN_PROFILE=none
25+
PHP_VERSION=8.3
26+
PHP_TARGET=dev
27+
PHP_INI=php.prod.ini
3828

39-
# Application configuration
40-
APP_WORKSPACE=default
41-
APP_DIR=app
42-
APP_PUBLIC_DIR=$(APP_DIR)/public
29+
PHP_DISPLAY_ERRORS=1
30+
PHP_MEMORY_LIMIT=256M
31+
XDEBUG_ENABLED=1
32+
33+
# MySQL configuration
34+
MYSQL_VERSION=9.2
35+
MYSQL_HOST=mysql
36+
MYSQL_PORT=8989
37+
MYSQL_DATABASE=test
38+
MYSQL_ROOT_USER=root
39+
MYSQL_ROOT_PASSWORD=root
40+
MYSQL_USER=dev
41+
MYSQL_PASSWORD=dev
42+
43+
# PHPMyAdmin configuration
44+
PHPMYADMIN_PORT=8080
45+
PHPMYADMIN_PROFILE=dev
46+
PHPMYADMIN_USER=root
47+
PHPMYADMIN_PASSWORD=root
48+
PHPMYADMIN_UPLOAD_LIMIT=100M
49+
50+
# MailHog configuration
51+
MAILHOG_SMTP_PORT=1025
52+
MAILHOG_UI_PORT=8025
53+
MAILHOG_STORAGE=memory
54+
MAILHOG_HOSTNAME=mailhog
55+
MAILHOG_CORS_ORIGIN=*
56+
57+
# API documentation configuration
58+
APIDOCS_PORT=8081

docker-compose.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- MYSQL_USER=${MYSQL_USER}
1818
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
1919
ports:
20-
- "8989:3306"
20+
- "${MYSQL_PORT:-8989}:3306"
2121
volumes:
2222
- mysql_data:/var/lib/mysql
2323
- ./docker/mysql/init:/docker-entrypoint-initdb.d
@@ -39,8 +39,8 @@ services:
3939
- "./etc/ssl:/etc/ssl"
4040
- "./web:/var/www/html"
4141
ports:
42-
- "8000:80"
43-
- "3000:443"
42+
- "${NGINX_PORT:-8000}:80"
43+
- "${NGINX_SSL_PORT:-3000}:443"
4444
environment:
4545
- NGINX_HOST=${NGINX_HOST}
4646
- APP_WORKSPACE=${APP_WORKSPACE:-default}
@@ -69,7 +69,7 @@ services:
6969
PHP_TARGET: ${PHP_TARGET:-dev}
7070
restart: always
7171
volumes:
72-
- "./etc/php/php.ini:/usr/local/etc/php/conf.d/99-custom.ini"
72+
- "./etc/php/${PHP_INI:-php.dev.ini}:/usr/local/etc/php/conf.d/99-custom.ini"
7373
- "./web:/var/www/html"
7474
environment:
7575
- PHP_DISPLAY_ERRORS=${PHP_DISPLAY_ERRORS:-1}
@@ -87,7 +87,7 @@ services:
8787
image: phpmyadmin/phpmyadmin
8888
container_name: phpmyadmin
8989
ports:
90-
- "8080:80"
90+
- "${PHPMYADMIN_PORT:-8080}:80"
9191
environment:
9292
- PMA_ARBITRARY=1
9393
- PMA_HOST=${MYSQL_HOST}
@@ -108,13 +108,13 @@ services:
108108
mailhog:
109109
image: mailhog/mailhog
110110
ports:
111-
- "${MAILHOG_SMTP_PORT:-1025}:1025" # SMTP port for sending emails
112-
- "${MAILHOG_UI_PORT:-8025}:8025" # Web interface for viewing emails
111+
- "${MAILHOG_SMTP_PORT:-1025}:1025" # SMTP port for sending emails
112+
- "${MAILHOG_UI_PORT:-8025}:8025" # Web interface for viewing emails
113113
environment:
114-
- MH_SMTP_BIND_ADDR=0.0.0.0:1025 # Binding address for the SMTP server
115-
- MH_API_BIND_ADDR=0.0.0.0:8025 # Binding address for the API
116-
- MH_UI_BIND_ADDR=0.0.0.0:8025 # Binding address for the user interface
117-
- MH_STORAGE=${MAILHOG_STORAGE:-memory} # Storage method (memory, mongodb)
114+
- MH_SMTP_BIND_ADDR=0.0.0.0:1025 # Binding address for the SMTP server
115+
- MH_API_BIND_ADDR=0.0.0.0:8025 # Binding address for the API
116+
- MH_UI_BIND_ADDR=0.0.0.0:8025 # Binding address for the user interface
117+
- MH_STORAGE=${MAILHOG_STORAGE:-memory} # Storage method (memory, mongodb)
118118
- MH_HOSTNAME=${MAILHOG_HOSTNAME:-mailhog} # Hostname to use for EHLO/HELO links
119119
- MH_CORS_ORIGIN=${MAILHOG_CORS_ORIGIN:-*} # CORS Configuration
120120
networks:
@@ -127,12 +127,12 @@ services:
127127
volumes:
128128
- "./docs/api/html:/usr/share/nginx/html:ro"
129129
ports:
130-
- "8081:80"
130+
- "${APIDOCS_PORT:-8081}:80"
131131
networks:
132132
- frontend-network
133133
profiles:
134134
- ${PHPMYADMIN_PROFILE:-dev}
135135

136136
volumes:
137137
mysql_data:
138-
name: ${PROJECT_NAME:-docker_nginx_php_mysql}_mysql_data
138+
name: ${APP_NAME:-docker_nginx_php_mysql}_mysql_data

0 commit comments

Comments
 (0)