Add project files
This commit is contained in:
26
php-compose-project/docker-compose.override.yml
Normal file
26
php-compose-project/docker-compose.override.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
nginx:
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- ./src:/var/www/html:delegated
|
||||
environment:
|
||||
- NGINX_HOST=localhost
|
||||
- NGINX_PORT=80
|
||||
|
||||
php:
|
||||
build:
|
||||
context: ./docker/php
|
||||
dockerfile: Dockerfile.dev
|
||||
volumes:
|
||||
- ./src:/var/www/html:delegated
|
||||
environment:
|
||||
- PHP_IDE_CONFIG=serverName=docker
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
|
||||
db:
|
||||
ports:
|
||||
- "3306:3306"
|
||||
50
php-compose-project/docker-compose.yml
Normal file
50
php-compose-project/docker-compose.yml
Normal file
@@ -0,0 +1,50 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
ports:
|
||||
- "8000:80"
|
||||
volumes:
|
||||
- ./src:/var/www/html
|
||||
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
|
||||
depends_on:
|
||||
- php
|
||||
networks:
|
||||
- frontend
|
||||
- backend
|
||||
|
||||
php:
|
||||
build:
|
||||
context: ./docker/php
|
||||
dockerfile: Dockerfile
|
||||
volumes:
|
||||
- ./src:/var/www/html
|
||||
environment:
|
||||
- DB_HOST=db
|
||||
- DB_USER=root
|
||||
- DB_PASS=secret
|
||||
- DB_NAME=testdb
|
||||
networks:
|
||||
- backend
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
db:
|
||||
image: mysql:8.0
|
||||
command: --default-authentication-plugin=mysql_native_password
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=secret
|
||||
- MYSQL_DATABASE=testdb
|
||||
volumes:
|
||||
- db_data:/var/lib/mysql
|
||||
networks:
|
||||
- backend
|
||||
|
||||
networks:
|
||||
frontend:
|
||||
backend:
|
||||
internal: true
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
17
php-compose-project/docker/nginx/default.conf
Normal file
17
php-compose-project/docker/nginx/default.conf
Normal file
@@ -0,0 +1,17 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /var/www/html;
|
||||
index index.php index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
fastcgi_pass php:9000;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
}
|
||||
}
|
||||
27
php-compose-project/docker/php/Dockerfile
Normal file
27
php-compose-project/docker/php/Dockerfile
Normal file
@@ -0,0 +1,27 @@
|
||||
FROM php:8.1-fpm
|
||||
|
||||
# Abhängigkeiten installieren
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libfreetype6-dev \
|
||||
libjpeg62-turbo-dev \
|
||||
libpng-dev \
|
||||
libzip-dev \
|
||||
zip \
|
||||
unzip
|
||||
|
||||
# PHP Extensions installieren
|
||||
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
|
||||
&& docker-php-ext-install -j$(nproc) \
|
||||
gd \
|
||||
pdo \
|
||||
pdo_mysql \
|
||||
zip
|
||||
|
||||
# OPCache für Produktion aktivieren
|
||||
RUN docker-php-ext-install opcache \
|
||||
&& docker-php-ext-enable opcache
|
||||
|
||||
WORKDIR /var/www/html
|
||||
|
||||
# Produktionskonfiguration nutzen
|
||||
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
|
||||
30
php-compose-project/docker/php/Dockerfile.dev
Normal file
30
php-compose-project/docker/php/Dockerfile.dev
Normal file
@@ -0,0 +1,30 @@
|
||||
FROM php:8.1-fpm
|
||||
|
||||
# Abhängigkeiten installieren
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libfreetype6-dev \
|
||||
libjpeg62-turbo-dev \
|
||||
libpng-dev \
|
||||
libzip-dev \
|
||||
zip \
|
||||
unzip
|
||||
|
||||
# PHP Extensions installieren
|
||||
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
|
||||
&& docker-php-ext-install -j$(nproc) \
|
||||
gd \
|
||||
pdo \
|
||||
pdo_mysql \
|
||||
zip
|
||||
|
||||
# Development-Konfiguration nutzen
|
||||
RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
|
||||
|
||||
# Xdebug installieren
|
||||
RUN pecl install xdebug \
|
||||
&& docker-php-ext-enable xdebug
|
||||
|
||||
# Xdebug-Konfiguration kopieren
|
||||
COPY xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
|
||||
|
||||
WORKDIR /var/www/html
|
||||
7
php-compose-project/docker/php/xdebug.ini
Normal file
7
php-compose-project/docker/php/xdebug.ini
Normal file
@@ -0,0 +1,7 @@
|
||||
zend_extension=xdebug
|
||||
|
||||
xdebug.mode=develop,debug
|
||||
xdebug.start_with_request=yes
|
||||
xdebug.client_host=host.docker.internal
|
||||
xdebug.client_port=9003
|
||||
xdebug.log=/var/log/xdebug.log
|
||||
59
php-compose-project/src/db-test.php
Normal file
59
php-compose-project/src/db-test.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
$host = getenv('DB_HOST') ?: 'db';
|
||||
$user = getenv('DB_USER') ?: 'root';
|
||||
$pass = getenv('DB_PASS') ?: 'secret';
|
||||
$dbname = getenv('DB_NAME') ?: 'testdb';
|
||||
|
||||
echo "<h1>Datenbank-Verbindungstest</h1>";
|
||||
echo "<p>Verbindungsversuch zu: $host</p>";
|
||||
|
||||
try {
|
||||
// Verbindung erstellen
|
||||
$conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
|
||||
|
||||
// PDO-Fehlerbehandlung aktivieren
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
echo "<div style='color:green;'>Verbindung erfolgreich!</div>";
|
||||
|
||||
// Prüfen, ob Testtabelle existiert, sonst erstellen
|
||||
$stmt = $conn->query("SHOW TABLES LIKE 'test_table'");
|
||||
if ($stmt->rowCount() == 0) {
|
||||
$conn->exec("CREATE TABLE test_table (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
message VARCHAR(255),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)");
|
||||
$conn->exec("INSERT INTO test_table (message) VALUES ('Testdaten 1')");
|
||||
$conn->exec("INSERT INTO test_table (message) VALUES ('Testdaten 2')");
|
||||
echo "<p>Testtabelle erstellt und mit Daten gefüllt.</p>";
|
||||
}
|
||||
|
||||
// Daten auslesen
|
||||
$stmt = $conn->query("SELECT * FROM test_table");
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo "<h2>Daten aus der Datenbank:</h2>";
|
||||
echo "<table border='1'>";
|
||||
echo "<tr><th>ID</th><th>Nachricht</th><th>Erstellt am</th></tr>";
|
||||
|
||||
foreach ($rows as $row) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . $row['id'] . "</td>";
|
||||
echo "<td>" . $row['message'] . "</td>";
|
||||
echo "<td>" . $row['created_at'] . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
|
||||
} catch(PDOException $e) {
|
||||
echo "<div style='color:red;'>Verbindungsfehler: " . $e->getMessage() . "</div>";
|
||||
}
|
||||
|
||||
// Verbindung schließen
|
||||
$conn = null;
|
||||
?>
|
||||
|
||||
<p>Seite geladen um: <?php echo date('H:i:s'); ?></p>
|
||||
<p><a href="index.php">Zurück zur Startseite</a></p>
|
||||
29
php-compose-project/src/image-test.php
Normal file
29
php-compose-project/src/image-test.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// Test für GD Extension
|
||||
header('Content-Type: image/png');
|
||||
|
||||
// Canvas erstellen (300x200px)
|
||||
$image = imagecreatetruecolor(300, 200);
|
||||
|
||||
// Farben definieren
|
||||
$background = imagecolorallocate($image, 0, 153, 204);
|
||||
$text_color = imagecolorallocate($image, 255, 255, 255);
|
||||
$border_color = imagecolorallocate($image, 0, 0, 0);
|
||||
|
||||
// Hintergrund füllen
|
||||
imagefill($image, 0, 0, $background);
|
||||
|
||||
// Rahmen zeichnen
|
||||
imagerectangle($image, 0, 0, 299, 199, $border_color);
|
||||
|
||||
// Text schreiben
|
||||
$text = "GD funktioniert!";
|
||||
imagestring($image, 5, 60, 80, $text, $text_color);
|
||||
|
||||
// Zeit anzeigen
|
||||
$time = date('H:i:s');
|
||||
imagestring($image, 3, 100, 120, "Zeit: $time", $text_color);
|
||||
|
||||
// Bild ausgeben
|
||||
imagepng($image);
|
||||
imagedestroy($image);
|
||||
36
php-compose-project/src/index.php
Normal file
36
php-compose-project/src/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>PHP Docker Demo</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
|
||||
h1 { color: #0066cc; }
|
||||
.info { background-color: #f0f0f0; padding: 15px; border-radius: 5px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>PHP-FPM mit Nginx Docker Demo</h1>
|
||||
|
||||
<div class="info">
|
||||
<p>PHP Version: <?php echo phpversion(); ?></p>
|
||||
<p>Server Software: <?php echo $_SERVER['SERVER_SOFTWARE']; ?></p>
|
||||
<p>Ausgeführt von: <?php echo exec('whoami'); ?></p>
|
||||
<p>Zeitstempel: <?php echo date('Y-m-d H:i:s'); ?></p>
|
||||
</div>
|
||||
|
||||
<h2>Extension Tests</h2>
|
||||
<ul>
|
||||
<li><a href="image-test.php">GD Image Test</a> (benötigt GD Extension)</li>
|
||||
<li><a href="db-test.php">Datenbank-Test</a> (benötigt MySQL/MariaDB Verbindung)</li>
|
||||
</ul>
|
||||
|
||||
<h3>Installierte PHP Extensions:</h3>
|
||||
<ul>
|
||||
<?php foreach(get_loaded_extensions() as $ext): ?>
|
||||
<li><?php echo $ext; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user