Zum Inhalt springen
Ubuntu / Linux

After Upgrading Ubuntu 20.04 to 22.04: Fix Nginx and PHP-FPM (PHP 7.4 → 8.1)

Install php8.1-fpm and the extensions your sites need, change every fastcgi_pass from php7.4-fpm.sock to php8.1-fpm.sock, run nginx -t and reload.

Getestet mit Ubuntu 22.04 LTS (upgraded from 20.04)

An in-place upgrade from Ubuntu 20.04 to 22.04 replaces PHP 7.4 with PHP 8.1. Your Nginx server blocks still pass PHP requests to /run/php/php7.4-fpm.sock, which no longer exists – so sites show 502 Bad Gateway, a blank page or “File not found”.

Step 1 – Install PHP 8.1-FPM and extensions

Terminal
sudo apt updatensudo apt install php8.1-fpm php8.1-cli php8.1-mysql php8.1-mbstring php8.1-xml php8.1-curl php8.1-gd php8.1-zip php8.1-intl php8.1-bcmath php8.1-imagick

Compare with what you used before (dpkg -l | grep php7.4) and install the 8.1 equivalents.

Step 2 – Point Nginx at the new socket

Find every reference to PHP 7.4:

Terminal
grep -rn u0022php7.4u0022 /etc/nginx/

Replace them in all site files at once (a backup of each file is kept with a .bak extension):

Terminal
sudo sed -i.bak 's/php7.4-fpm.sock/php8.1-fpm.sock/g' /etc/nginx/sites-available/*.conf

Step 3 – Carry over PHP settings

Custom values such as upload_max_filesize or memory_limit were in /etc/php/7.4/fpm/. Copy them to /etc/php/8.1/fpm/php.ini (and any custom pool files in pool.d/).

Step 4 – Test and reload

Terminal
sudo nginx -tnsudo systemctl restart php8.1-fpmnsudo systemctl reload nginx

Check WordPress compatibility

PHP 8.1 is stricter than 7.4. Update WordPress, themes and plugins before switching; check /var/log/nginx/error.log and the site’s debug log for deprecations. When everything works, remove PHP 7.4: sudo apt purge "php7.4*".

Setting up a new site instead? The Nginx Server Block Generator writes a complete config for any PHP version.

Inder Kochar

Geschrieben von

Inder Kochar

System- & Netzwerkingenieur – Ich schreibe die Lösungen auf, die ich bei Kunden einsetze – getestet auf echten Systemen. Hängen Sie an etwas Ähnlichem fest?

Weiterlesen

Stellen Sie eine Frage oder teilen Sie Ihre Lösung

Ihre E-Mail-Adresse wird nicht veröffentlicht. Kommentare werden moderiert – bitte beim Thema bleiben.