Skip to content

Commit e7b2e72

Browse files
committed
Initial commit
0 parents  commit e7b2e72

File tree

7 files changed

+230
-0
lines changed

7 files changed

+230
-0
lines changed

.vscode/launch.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Listen for Xdebug",
9+
"type": "php",
10+
"request": "launch",
11+
"port": 9003,
12+
"pathMappings": {
13+
"/var/www/html": "${workspaceFolder}/src",
14+
},
15+
"log": true,
16+
},
17+
{
18+
"name": "Launch currently open script",
19+
"type": "php",
20+
"request": "launch",
21+
"program": "${file}",
22+
"cwd": "${fileDirname}",
23+
"port": 0,
24+
"runtimeArgs": [
25+
"-dxdebug.start_with_request=yes"
26+
],
27+
"env": {
28+
"XDEBUG_MODE": "debug,develop",
29+
"XDEBUG_CONFIG": "client_port=${port}"
30+
}
31+
},
32+
{
33+
"name": "Launch Built-in web server",
34+
"type": "php",
35+
"request": "launch",
36+
"runtimeArgs": [
37+
"-dxdebug.mode=debug",
38+
"-dxdebug.start_with_request=yes",
39+
"-S",
40+
"localhost:0"
41+
],
42+
"program": "",
43+
"cwd": "${workspaceRoot}",
44+
"port": 9003,
45+
"serverReadyAction": {
46+
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
47+
"uriFormat": "http://localhost:%s",
48+
"action": "openExternally"
49+
}
50+
}
51+
]
52+
}

compose.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
services:
2+
# PHP Service (using PHP-FPM)
3+
php:
4+
build:
5+
context: ./php
6+
dockerfile: Dockerfile
7+
container_name: my_php_app_php
8+
volumes:
9+
- ./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"
24+
volumes:
25+
- ./src:/var/www/html
26+
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
27+
depends_on:
28+
- php
29+
networks:
30+
- app-network
31+
# Database Service (using MySQL)
32+
db:
33+
image: mysql:8.0
34+
container_name: my_php_app_db
35+
ports:
36+
- "33066:3306"
37+
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
46+
47+
volumes:
48+
db_data:
49+
50+
51+
networks:
52+
app-network:
53+
driver: bridge

nginx/default.conf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
5+
root /var/www/html;
6+
index index.php index.html index.htm;
7+
8+
location / {
9+
try_files $uri $uri/ /index.php?$query_string;
10+
}
11+
12+
location ~ \.php$ {
13+
try_files $uri = 404;
14+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
15+
# The `php` here is the service name defined in compose.yml
16+
fastcgi_pass php:9000;
17+
fastcgi_index index.php;
18+
include fastcgi_params;
19+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
20+
fastcgi_param PATH_INFO $fastcgi_path_info;
21+
}
22+
23+
location ~ /\.ht {
24+
deny all;
25+
}
26+
}

php/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM php:8.3-fpm
2+
3+
WORKDIR /var/www/html
4+
5+
RUN apt-get update && apt-get install -y \
6+
git \
7+
curl \
8+
libpng-dev \
9+
libonig-dev \
10+
libxml2-dev \
11+
libzip-dev \
12+
zip \
13+
unzip \
14+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
15+
16+
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip
17+
18+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
19+
20+
RUN pecl install xdebug && docker-php-ext-enable xdebug
21+
22+
RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
23+
24+
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
25+
COPY dev-settings.ini /usr/local/etc/php/conf.d/zz-dev-settings.ini

php/dev-settings.ini

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error_reporting = E_ALL
2+
display_errors = On
3+
display_startup_errors = On
4+
log_errors = On
5+
; Log errors to stderr so they appear in `docker logs`
6+
; For PHP-FPM, it might already log to stderr/stdout by default,
7+
; but this ensures it if you were using a different SAPI or want to be explicit.
8+
error_log = /dev/stderr
9+
; Alternatively, log to a file inside the container (make sure path is writable)
10+
; error_log = /var/www/html/logs/php_errors.log
11+
12+
; General Development Settings
13+
date.timezone = "America/New_York" ; Set to your local timezone
14+
short_open_tag = Off ; Recommended for compatibility
15+
expose_php = Off ; Good security practice, even in dev
16+
17+
; Resource Limits (Adjust these based on your project's needs)
18+
memory_limit = 512M ; Increased memory limit
19+
post_max_size = 64M ; For larger POST requests (e.g., file uploads)
20+
upload_max_filesize = 64M ; For larger file uploads
21+
max_execution_time = 120 ; Increased execution time for potentially long scripts in dev
22+
max_input_vars = 3000 ; Useful for complex forms or frameworks
23+
24+
; OPcache Settings for Development (Can improve performance, but ensure changes are picked up)
25+
; OPcache is usually enabled by default in recent PHP versions.
26+
; These settings help ensure that code changes are reflected quickly during development.
27+
opcache.enable = 1
28+
opcache.enable_cli = 1 ; Enable for CLI scripts too
29+
opcache.revalidate_freq = 0 ; Check file timestamps on every request (0) or every few seconds (e.g., 1)
30+
opcache.validate_timestamps = 1 ; Crucial: tells OPcache to check for updated scripts
31+
opcache.memory_consumption = 128 ; OPcache memory
32+
opcache.interned_strings_buffer = 16 ;
33+
opcache.max_accelerated_files = 10000 ;
34+
; opcache.jit_buffer_size = 0 ; Consider disabling JIT in dev if you suspect issues, or configure appropriately.
35+
; For PHP 8.0+, JIT is off by default unless explicitly configured.
36+
37+
; Session Settings (Defaults are often fine, but you can customize)
38+
; session.save_handler = files
39+
; session.save_path = "/tmp" ; Ensure this path is writable by the PHP process
40+
; session.gc_probability = 1
41+
; session.gc_divisor = 100
42+
; session.cookie_httponly = 1
43+
; session.cookie_samesite = "Lax"

php/xdebug.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[xdebug]
2+
zend_extension=xdebug
3+
xdebug.mode=debug
4+
xdebug.start_with_request=yes
5+
xdebug.client_host=172.17.0.1
6+
xdebug.client_port=9003 ; Default is 9003
7+
xdebug.log_level=7
8+
xdebug.log=/tmp/xdebug.log ; Optional: for debugging Xdebug itself

src/index.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
echo "<h1>Hello from Dockerized PHP!</h1>";
3+
echo "PHP Version: " . phpversion() . "</br>";
4+
5+
$dbHost = getenv('DB_HOST');
6+
$dbName = getenv('DB_DATABASE');
7+
$dbUser = getenv('DB_USER');
8+
$dbPass = getenv('DB_PASSWORD');
9+
10+
echo "DB HOST: " . $dbHost . "</br>";
11+
12+
if ($dbHost && $dbName && $dbUser && $dbPass) {
13+
try {
14+
$pdo = new PDO("mysql:host={$dbHost};dbName={$dbName}", $dbUser, $dbPass);
15+
echo "Successfully connected to the database: {$dbName}!<br>";
16+
} catch (PDOException $e) {
17+
echo "Database connection failed: " . $e->getMessage() . "<br>";
18+
}
19+
} else {
20+
echo "Database environment variables not fully set.<br>";
21+
}
22+
23+
phpinfo();

0 commit comments

Comments
 (0)