|
|
| Zeile 1: |
Zeile 1: |
| = NGINX mit PHP-FPM betreiben =
| | *[[Nginx php Debian]] |
| | | *[[Nginx php Rocky]] |
| Diese Anleitung zeigt, wie man eine einfache PHP-Webanwendung mit NGINX und PHP-FPM unter Debian oder Ubuntu betreibt.
| |
| | |
| == Voraussetzungen ==
| |
| * Debian- oder Ubuntu-System mit root-Rechten | |
| * Paketverwaltung via apt
| |
| * Standardwebverzeichnis: /var/www/html
| |
| * PHP 8.2 als Beispiel | |
| | |
| == Installation ==
| |
| * apt update
| |
| * apt install nginx php-fpm
| |
| | |
| == PHP-FPM prüfen ==
| |
| * systemctl status php8.2-fpm
| |
| | |
| Die Socket-Datei für FastCGI-Kommunikation liegt standardmäßig hier:
| |
| /var/run/php/php8.2-fpm.sock
| |
| | |
| == NGINX-Konfiguration anpassen ==
| |
| Datei: /etc/nginx/sites-available/default
| |
| | |
| <pre>
| |
| server {
| |
| listen 80;
| |
| server_name localhost;
| |
| | |
| root /var/www/html;
| |
| index index.php index.html;
| |
| | |
| location / {
| |
| try_files $uri $uri/ =404;
| |
| }
| |
| | |
| location ~ \.php$ {
| |
| include snippets/fastcgi-php.conf;
| |
| fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
| |
| }
| |
| | |
| location ~ /\.ht {
| |
| deny all;
| |
| }
| |
| }
| |
| </pre>
| |
| | |
| * ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
| |
| * nginx -t
| |
| * systemctl reload nginx
| |
| | |
| == Testseite anlegen ==
| |
| * echo "<?php phpinfo(); ?>" > /var/www/html/info.php
| |
| | |
| == Dienste neustarten ==
| |
| * systemctl restart php8.2-fpm
| |
| * systemctl restart nginx
| |
| | |
| == Funktion prüfen ==
| |
| Im Browser aufrufen:
| |
| http://localhost/info.php
| |
| | |
| == Hinweise ==
| |
| * .htaccess-Dateien werden von NGINX '''nicht''' unterstützt – Rewrite-Regeln müssen direkt in der NGINX-Konfiguration erfolgen.
| |
| * Der Pfad zur php-fpm.sock kann je nach PHP-Version abweichen.
| |
| * Falls du TCP statt Socket verwenden willst, lautet der fastcgi_pass z. B.:
| |
| fastcgi_pass 127.0.0.1:9000;
| |
| * Für mehrere PHP-Versionen empfiehlt sich der Einsatz separater Pools und Versionen über update-alternatives oder manuelles Umschalten.
| |