0PricingLogin
PHP Academy · Lesson

Nginx and PHP-FPM Configuration

Set up Nginx as a reverse proxy to PHP-FPM for serving PHP applications.

Why Nginx + PHP-FPM?

Nginx is a high-performance web server and reverse proxy. PHP-FPM (FastCGI Process Manager) manages a pool of PHP worker processes. Nginx passes PHP requests to FPM via FastCGI.

Basic Nginx Server Block

A minimal Nginx configuration for a PHP application.

# /etc/nginx/sites-available/myapp
server {
    listen 80;
    server_name example.com;
    root /srv/myapp/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }
}

All lessons in this course

  1. Nginx and PHP-FPM Configuration
  2. Environment Variables and .env Files
  3. Deploying with GitHub Actions
  4. Dockerizing a PHP Application
← Back to PHP Academy