Skip to content

Commit c74e3cb

Browse files
committed
v2
1 parent 142c201 commit c74e3cb

File tree

16 files changed

+139
-164
lines changed

16 files changed

+139
-164
lines changed

.envexample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MYSQL_ROOT_PASSWORD="root"
2+
MYSQL_DATABASE="localdb"
3+
MYSQL_USER="admin"
4+
MYSQL_PASSWORD="1234"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

.vscode/launch.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
"request": "launch",
1111
"port": 9003,
1212
"pathMappings": {
13-
"/var/www/html": "${workspaceFolder}/src",
14-
},
15-
"log": true,
13+
"/var/www/html": "${workspaceFolder}/src"
14+
}
1615
},
1716
{
1817
"name": "Launch currently open script",

Caddyfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
localhost {
2+
reverse_proxy nginx:80
3+
}
4+
5+
pma.localhost {
6+
reverse_proxy phpmyadmin:80
7+
}

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
## Purpose
22

33
The purpose of this repository is so that I can continuously improve my local development environment by adapting good practices and using my experience while using this structure.
4+
5+
## Install
6+
7+
**Prerequisites:**
8+
9+
* You need Docker and Docker Compose installed.
10+
* You need to add the following entry to your system's `hosts` file to access the phpMyAdmin page:
11+
```
12+
127.0.0.1 pma.localhost
13+
```
14+
15+
**Running the Environment:**
16+
17+
1. Navigate to the root directory of this project in your terminal.
18+
2. Run the following command to build and start the services in detached mode:
19+
```bash
20+
docker-compose up -d
21+
```

build/php/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM php:8.3-fpm
2+
RUN apt-get update && apt-get install -y --no-install-recommends \
3+
git unzip zip curl pkg-config \
4+
libzip-dev libicu-dev libpng-dev libjpeg-dev libfreetype6-dev \
5+
libxml2-dev default-libmysqlclient-dev libonig-dev \
6+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
7+
RUN docker-php-ext-install pdo pdo_mysql mbstring xml intl opcache bcmath
8+
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
9+
&& docker-php-ext-install gd
10+
RUN pecl install xdebug && docker-php-ext-enable xdebug
11+
RUN pecl install redis && docker-php-ext-enable redis
12+
RUN rm -rf /tmp/pear
13+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

compose.yml

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,52 @@
11
services:
2-
# PHP Service (using PHP-FPM)
3-
php:
4-
build:
5-
context: ./php
6-
dockerfile: Dockerfile
7-
container_name: my_php_app_php
2+
caddy:
3+
image: caddy:alpine
4+
ports:
5+
- "80:80"
6+
- "443:443"
7+
- "443:443/udp"
8+
volumes:
9+
- ./Caddyfile:/etc/caddy/Caddyfile:ro
10+
- caddy_data:/data
11+
- caddy_config:/config
12+
restart: unless-stopped
13+
nginx:
14+
image: nginx:alpine
15+
restart: unless-stopped
816
volumes:
17+
- ./config/nginx:/etc/nginx/conf.d:ro
918
- ./src:/var/www/html
10-
working_dir: /var/www/html
11-
environment:
12-
DB_HOST: "db"
13-
DB_DATABASE: "myappdb"
14-
DB_USER: "myappuser"
15-
DB_PASSWORD: "myapppassword"
16-
networks:
17-
- app-network
18-
# Web Server Service (using nginx)
19-
webserver:
20-
image: nginx:stable-alpine
21-
container_name: my_php_app_webserver
22-
ports:
23-
- "8080:80"
19+
depends_on:
20+
- php-fpm
21+
php-fpm:
22+
build: ./build/php/
23+
restart: unless-stopped
2424
volumes:
2525
- ./src:/var/www/html
26-
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
26+
- ./config/php/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini:ro
27+
- ./config/php/zz-php-fpm.ini:/usr/local/etc/php-fpm.d/zz-php-fpm.ini:ro
28+
- ./config/php/zz-php.ini:/usr/local/etc/php/conf.d/zz-php.ini:ro
2729
depends_on:
28-
- php
29-
networks:
30-
- app-network
31-
# Database Service (using MySQL)
30+
- db
31+
environment:
32+
DB_HOST: "db" # The db service
33+
DB_NAME: ${MYSQL_DATABASE}
34+
DB_USER: ${MYSQL_USER}
35+
DB_PASSWORD: ${MYSQL_PASSWORD}
36+
phpmyadmin:
37+
image: phpmyadmin/phpmyadmin
38+
environment:
39+
PMA_HOST: db
40+
PMA_PORT: 3306
3241
db:
33-
image: mysql:8.0
34-
container_name: my_php_app_db
35-
ports:
36-
- "33066:3306"
42+
image: mysql
43+
restart: always
3744
environment:
38-
MYSQL_ROOT_PASSWORD: "rootpassword"
39-
MYSQL_DATABASE: "myappdb"
40-
MYSQL_USER: "myappuser"
41-
MYSQL_PASSWORD: "myapppassword"
42-
volumes:
43-
- db_data:/var/lib/mysql
44-
networks:
45-
- app-network
45+
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
46+
MYSQL_DATABASE: ${MYSQL_DATABASE}
47+
MYSQL_USER: ${MYSQL_USER}
48+
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
4649

4750
volumes:
48-
db_data:
49-
50-
51-
networks:
52-
app-network:
53-
driver: bridge
51+
caddy_data:
52+
caddy_config:

config/nginx/nginx.conf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
server {
2+
listen 80;
3+
listen [::]:80;
4+
server_name localhost;
5+
6+
#access_log /var/log/nginx/host.access.log main;
7+
root /var/www/html;
8+
index index.php index.html index.htm;
9+
10+
location / {
11+
try_files $uri $uri/ /index.php?$query_string;
12+
}
13+
14+
#error_page 404 /404.html;
15+
16+
# redirect server error pages to the static page /50x.html
17+
#
18+
error_page 500 502 503 504 /50x.html;
19+
location = /50x.html {
20+
root /usr/share/nginx/html;
21+
}
22+
23+
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
24+
#
25+
#location ~ \.php$ {
26+
# proxy_pass http://127.0.0.1;
27+
#}
28+
29+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
30+
#
31+
location ~ \.php$ {
32+
try_files $uri =404;
33+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
34+
# The `php` here is the service name defined in compose.yml
35+
fastcgi_pass php-fpm:9000;
36+
fastcgi_index index.php;
37+
include fastcgi_params;
38+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
39+
fastcgi_param PATH_INFO $fastcgi_path_info;
40+
}
41+
42+
# deny access to .htaccess files, if Apache's document root
43+
# concurs with nginx's one
44+
#
45+
#location ~ /\.ht {
46+
# deny all;
47+
#}
48+
}
49+

php/xdebug.ini renamed to config/php/xdebug.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
zend_extension=xdebug
33
xdebug.mode=debug
44
xdebug.start_with_request=yes
5-
xdebug.client_host=172.17.0.1
5+
xdebug.discover_client_host=true
66
xdebug.client_port=9003 ; Default is 9003
77
xdebug.log_level=7
88
xdebug.log=/tmp/xdebug.log ; Optional: for debugging Xdebug itself

config/php/zz-php-fpm.ini

Whitespace-only changes.

0 commit comments

Comments
 (0)