Add project files

This commit is contained in:
Frank Woeckener
2025-03-18 10:42:10 +01:00
parent e429c37f62
commit 3011456ddc
28 changed files with 757 additions and 4 deletions

View File

@@ -0,0 +1,20 @@
FROM php:8.1-fpm
WORKDIR /var/www/html
COPY composer.json ./
RUN apt-get update && apt-get install -y \
zip \
unzip \
&& docker-php-ext-install pdo pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install --no-scripts --no-autoloader
COPY . .
RUN composer dump-autoload --optimize
EXPOSE 9000
CMD ["php-fpm"]

View File

@@ -0,0 +1,14 @@
{
"name": "example/php-docker-demo",
"description": "Eine einfache PHP-Anwendung für Docker",
"type": "project",
"require": {
"php": ">=8.1",
"monolog/monolog": "^2.8"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}

View File

@@ -0,0 +1,29 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 9090;
server_name localhost;
root /var/www/html/public;
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
include servers/*;
}

View File

@@ -0,0 +1,51 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
use App\HelloWorld;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// Logger initialisieren
$log = new Logger('app');
$log->pushHandler(new StreamHandler('php://stdout', Logger::INFO));
$log->info('Anwendung gestartet');
// HelloWorld-Klasse verwenden
$hello = new HelloWorld();
$message = $hello->getMessage();
?>
<!DOCTYPE html>
<html>
<head>
<title>Docker PHP Demo</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; line-height: 1.6; }
.container { max-width: 800px; margin: 0 auto; }
.status { padding: 10px; margin: 10px 0; border-radius: 4px; }
.success { background-color: #d4edda; color: #155724; }
.error { background-color: #f8d7da; color: #721c24; }
</style>
</head>
<body>
<div class="container">
<h1>PHP Docker Demo</h1>
<p>Dies ist eine einfache PHP-Anwendung für Docker-Demo.</p>
<h2>Status</h2>
<div class="status success">
<p><?php echo $message; ?></p>
</div>
<h2>PHP Info</h2>
<p>PHP Version: <?php echo phpversion(); ?></p>
<p>Loaded Extensions:</p>
<ul>
<?php foreach(get_loaded_extensions() as $ext): ?>
<li><?php echo $ext; ?></li>
<?php endforeach; ?>
</ul>
</div>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<?php
namespace App;
class HelloWorld
{
public function getMessage(): string
{
return 'Hallo Welt! Die PHP-Anwendung läuft in Docker.';
}
}