Docs / Web Servers / How to Install PHP with Nginx

How to Install PHP with Nginx

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 189 views · 1 min read

PHP-FPM processes PHP files and works with Nginx to serve dynamic websites.

Install PHP-FPM

apt install php-fpm php-mysql php-curl php-xml php-mbstring php-zip -y

Configure Nginx for PHP

Add to your server block:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}

Adjust the PHP version in the socket path to match your installed version.

Test

echo "<?php phpinfo();" > /var/www/html/info.php
nginx -t
systemctl reload nginx

Visit http://YOUR_IP/info.php to verify. Delete the file after testing:

rm /var/www/html/info.php

Was this article helpful?