How to Set Up Unix Domain Sockets with Nginx and PHP‑FPM on Linux
This guide explains what Unix domain sockets are, shows how to create a socket file, and provides step‑by‑step Nginx and PHP‑FPM configuration instructions for establishing inter‑process communication on a Linux server.
What is a Unix Domain Socket
Unix domain socket (also called IPC socket ) is an endpoint that allows two or more processes on the same operating system to exchange data. Unlike pipes, Unix domain sockets can use both byte streams and datagram queues. Their API resembles Internet sockets, but they do not rely on network protocols; instead they use a file system path as their address, enabling kernel‑level communication without network traffic.
— Wikipedia
Create the Socket File
In /dev/shm run the following commands:
touch php-fcgi.sock
chown admin:admin php-fcgi.sock
chmod 777 php-fcgi.sockNginx Configuration
server {
listen 80;
server_name cdai.net;
autoindex off;
error_page 403 /index.php;
error_page 404 /index.php;
if ($fastcgi_script_name ~ \..*\/.*php) {
return 403;
}
location / {
index index.php;
root /home/cdai;
}
location ~ \.php$ {
root /home/cdai;
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /cdai.net$fastcgi_script_name;
}
}PHP‑FPM Configuration
Edit /etc/php-fpm.d/www.conf with the following changes:
listen = /tmp/php-fcgi.sock
listen.owner = admin
listen.group = adminRestart Services
Reload Nginx and restart PHP‑FPM. Use a full stop‑and‑start sequence rather than a USR2 graceful reload.
nginx -s reload
# then restart PHP‑FPM (service php-fpm restart)After restarting, the socket file type changes to s, indicating that the communication channel has been successfully established.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
