Nginx mit PHP (Rocky): Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
Zeile 1: Zeile 1:
= NGINX + PHP-FPM auf Rocky Linux 10 =
+
= Installation von NGINX und PHP-FPM auf Rocky Linux 10 =
  
*dnf install nginx php-fpm -y
+
*dnf install nginx php-fpm firewalld -y
*systemctl enable --now nginx php-fpm
+
*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
 
*echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php
  
 +
= NGINX-Konfiguration anpassen =
 
*vi /etc/nginx/conf.d/default.conf
 
*vi /etc/nginx/conf.d/default.conf
 
<pre>
 
<pre>
Zeile 19: Zeile 25:
  
 
     location ~ \.php$ {
 
     location ~ \.php$ {
         include /etc/nginx/fastcgi_params;
+
         include fastcgi_params;
 +
        fastcgi_pass unix:/run/php-fpm/www.sock;
 
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php-fpm/www.sock;
 
        fastcgi_index index.php;
 
 
     }
 
     }
 
}
 
}
 
</pre>
 
</pre>
  
 +
= Dienste neu starten =
 +
*systemctl restart nginx php-fpm
  
 
+
= Funktionstest =
*systemctl restart php-fpm nginx
 
*ss -ltnp | grep php-fpm
 
 
*curl -I http://127.0.0.1/info.php
 
*curl -I http://127.0.0.1/info.php
 
*Browser: http://10.20.10.12/info.php
 
*Browser: http://10.20.10.12/info.php
 +
 +
= Kontrolle der aktiven Dienste =
 +
*ss -ltnp | grep nginx
 +
*ss -lx | grep php-fpm
  
 
= Fehlerbehebung =
 
= Fehlerbehebung =

Aktuelle Version vom 11. November 2025, 05:52 Uhr

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

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