Chapter

Nginx and PHP

How nginx serves PHP through PHP-FPM over FastCGI, from a plain PHP page to a full Laravel server block.

Nginx Basics 4 Lessons from courses

About this chapter

Nginx cannot run PHP by itself. In this chapter you'll learn how it hands PHP requests to PHP-FPM over FastCGI, then build a working PHP site and the canonical Laravel server block, line by line.

Lessons from courses

  1. 1 How nginx runs PHP How nginx runs PHP with PHP-FPM: nginx never executes PHP, it passes .php requests to PHP-FPM over FastCGI. Follow the full request flow, step by step.
  2. 2 The fastcgi_pass block The nginx fastcgi_pass PHP-FPM config, line by line: fastcgi_pass, include fastcgi_params, and why SCRIPT_FILENAME picks the file. Unix socket vs TCP.
  3. 3 A working PHP site A complete nginx PHP-FPM server block example for a plain PHP site: listen, root, try_files, and the FastCGI location. Copy it, add phpinfo, test that PHP runs.
  4. 4 A Laravel server block The canonical nginx Laravel server block config: root at /public, try_files to index.php, the PHP-FPM location, and dotfile protection, explained line by line.
Nginx Basics Go to course