Nginx mit PHP (Rocky)
Version vom 11. November 2025, 05:52 Uhr von Thomas.will (Diskussion | Beiträge) (→NGINX + PHP-FPM auf Rocky Linux 10)
Installation von NGINX und PHP-FPM auf Rocky Linux 10
- dnf install nginx php-fpm firewalld -y
- systemctl enable --now nginx php-fpm firewalld
Firewall konfigurieren
- firewall-cmd --permanent --add-service=http
- firewall-cmd --reload
PHP-Testdatei anlegen
- echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php
NGINX-Konfiguration anpassen
- vi /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Dienste neu starten
- systemctl restart nginx php-fpm
Funktionstest
- curl -I http://127.0.0.1/info.php
- Browser: http://10.20.10.12/info.php
Kontrolle der aktiven Dienste
- ss -ltnp | grep nginx
- ss -lx | grep php-fpm
Fehlerbehebung
- „File not found“ → fastcgi_param SCRIPT_FILENAME prüfen.
- „502 Bad Gateway“ → prüfen, ob /run/php-fpm/www.sock existiert.
- „Permission denied“ → testweise SELinux deaktivieren: setenforce 0