Nginx is a high performance web server that’s free to use. Nginx is designed for speed and scalability with capabilities of reverse proxy and load balancing to a number of backend servers both with HTTP, TCP and UDP protocols. This website is powered by WordPress and Nginx and the performance is really good. Nginx has small memory footprint as compared to Apache, handling same number of concurrent connections. In this tutorial we perform an installation of Nginx With PHP-FPM on Ubuntu Linux system.
Key Features of Nginx
- Content Cache – Cache static and dynamic content
- Load Balancing – HTTP, TCP, and UDP load balancing with Layer 7 request routing using URI, cookie, args, and more.
- Reverse proxy multiple protocols: HTTP, gRPC, memcached, PHP‑FPM, SCGI, uwsgi
- Handle hundreds of thousands of clients simultaneously
- Stream HTTP video: FLV, HDS, HLS, MP4
- HTTP/2 gateway with HTTP/2 server push support
- Dual‑stack RSA/ECC SSL/TLS offload
- Monitoring plugins: AppDynamics, Datadog, Dynatrace plug‑ins
This guide has been created to help users running Ubuntu server to install Nginx web server and configure PHP-FPM (FastCGI Process Manager).
Step 1: Update Ubuntu server
Before you begin, you should have a running Ubuntu server that has been updated and upgraded to the latest available packages.
sudo apt update && sudo apt -y full-upgrade
[ -f /var/run/reboot-required ] && sudo reboot -f
Step 2: Install Nginx on Ubuntu
After the system is updated, proceed to install Nginx package on Ubuntu.
sudo apt install nginx
The service should be started automatically after installation.
$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2025-01-06 10:55:36 UTC; 1s ago
Docs: man:nginx(8)
Main PID: 6449 (nginx)
Tasks: 2 (limit: 2344)
Memory: 3.8M
CGroup: /system.slice/nginx.service
├─6449 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─6451 nginx: worker process
Jan 06 10:55:36 ubuntu24-cloudspinx-com systemd[1]: Starting A high performance web server and a reverse proxy server...
Jan 06 10:55:36 ubuntu24-cloudspinx-com systemd[1]: Started A high performance web server and a reverse proxy server.
Notice that you cannot run both Apache and Nginx on same port. You’ll need to disable Apache web server or change port of one of them to not http standard port.
sudo systemctl disable --now apache2
sudo systemctl restart nginx
UFW firewall can be configured to allow port 80:
sudo ufw allow proto tcp from any to any port 80,443
Step 3: Install PHP-FPM on Ubuntu
If you’re planning on using PHP with Nginx, consider installing PHP-FPM package.
sudo apt update
sudo apt install php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
PHP-FPM has the service that should be running.
$ systemctl status php*-fpm.service
● php8.3-fpm.service - The PHP 8.3 FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php8.3-fpm.service; enabled; preset: enabled)
Active: active (running) since Mon 2025-01-06 10:57:16 UTC; 59s ago
Docs: man:php-fpm8.3(8)
Process: 1698222 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.3/fpm/>
Main PID: 1698218 (php-fpm8.3)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 3 (limit: 19151)
Memory: 10.1M (peak: 10.9M)
CPU: 88ms
CGroup: /system.slice/php8.3-fpm.service
├─1698218 "php-fpm: master process (/etc/php/8.3/fpm/php-fpm.conf)"
├─1698220 "php-fpm: pool www"
└─1698221 "php-fpm: pool www"
Jan 06 10:57:16 ubuntu24-cloudspinx-com systemd[1]: Starting php8.3-fpm.service - The PHP 8.3 FastCGI Process Manager>
Jan 06 10:57:16 ubuntu24-cloudspinx-com systemd[1]: Started php8.3-fpm.service - The PHP 8.3 FastCGI Process Manager.
PID and Socket file are located in the directory:
ls /run/php/
Step 4: Configure PHP-FPM with Nginx
Edit FPM default www
pool configuration file
sudo vim /etc/php/*/fpm/pool.d/www.conf
Set Unix socket path
listen = /run/php/php-fpm.sock
Edit your Application Nginx configuration file and set fastcgi_pass section to load through FPM socket. See below snippet.
$ sudo vim /etc/nginx/php_fastcgi.conf
# 404
try_files $fastcgi_script_name =404;
# default fastcgi_params
include fastcgi_params;
# fastcgi settings
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_hide_header X-Powered-By;
fastcgi_hide_header X-CF-Powered-By;
Reload Nginx and open your application on the web to confirm it is working as expected.
Check other Nginx articles:
Nginx Books to read: