Nginx mit PHP (Rocky): Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „*dnf install nginx php-fpm -y *systemctl enable --now nginx php-fpm *echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php *vi /etc/nginx/conf.d/default.…“)
 
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
*dnf install nginx php-fpm -y
+
= Installation von NGINX und PHP-FPM auf Rocky Linux 10 =
*systemctl enable --now nginx php-fpm
+
 
 +
*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
 
*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>
 
server {
 
server {
  listen 80;
+
    listen 80;
  root /usr/share/nginx/html;
+
    server_name _;
  index index.php index.html;
+
    root /usr/share/nginx/html;
  location ~ \.php$ {
+
    index index.php index.html;
    fastcgi_pass 127.0.0.1:9000;
+
 
    include fastcgi.conf;
+
    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;
 +
    }
 
}
 
}
 
</pre>
 
</pre>
*systemctl reload nginx
+
 
*http://10.20.10.12/info.php prüfen
+
= 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

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