Metainformationen zur Seite
  •  

Dies ist eine alte Version des Dokuments!


Webtrees in einem docker container

How to Set Up Nginx, MariaDB, and PHP with Docker Compose

docker-compose.yaml

docker-compose.yaml
version: '3.8'
 
# Services
services:

    # PHP Service
    php:
        build:
            dockerfile: php-dockerfile
        volumes:
            - './php-files:/var/www/html'
            - './php.ini:/usr/local/etc/php/php.ini'

        depends_on:
            - mariadb
 
    # Nginx Service
    nginx:
        image: nginx:latest
        ports:
            - 8087:80
        links:
            - 'php'
        volumes:
            - './php-files:/var/www/html'
            - './nginx-conf:/etc/nginx/conf.d'
        depends_on:
            - php
 
    # MariaDB Service
    mariadb:
        image: mariadb:10.9
        environment:
            MYSQL_ROOT_PASSWORD: uhpc49C5+#
        volumes:
            - mysqldata:/var/lib/mysql
 
    # phpMyAdmin Service
    phpmyadmin:
        image: phpmyadmin/phpmyadmin:latest
        ports:
            - 8082:80
        environment:
            PMA_HOST: mariadb
            UPLOAD_LIMIT: 100M
        depends_on:
            - mariadb
 
# Volumes
volumes:

  mysqldata:

php-dockerfile

php-dockerfile
FROM php:8.1-fpm

# Installing dependencies for the PHP modules
RUN apt-get update && \
    apt-get install -y zip libzip-dev libpng-dev

# Installing additional PHP modules
RUN docker-php-ext-install mysqli pdo pdo_mysql gd zip mbstring curl exif fileinfo intl

php-files/index.php

<?php phpinfo(); ?>

nginx-conf/nginx.conf

nginx.conf
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    
    server_name localhost;

    root /var/www/html;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~* \.php$ {
        fastcgi_pass php:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    }
}

How to Create Nginx Virtual Host (Server Block)