Integrate PHP-FPM with Nginx on Arch Linux
Prerequisites
- Nginx installed and running
- PHP-FPM installed (see Install PHP-FPM on Arch Linux)
Step 1 – Confirm PHP-FPM socket path
grep -E '^listen' /etc/php-fpm.d/www.conf 2>/dev/null || \
grep -E '^listen' /etc/php/*/fpm/pool.d/www.conf 2>/dev/null
Default socket: /run/php-fpm/php-fpm.sock
Step 2 – Update the Nginx server block
server {
listen 80;
server_name example.com;
root /var/www/example.com/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
Step 3 – Test configuration and reload
nginx -t && systemctl reload nginx 2>/dev/null || \
nginx -t && rc-service nginx reload 2>/dev/null || \
nginx -t && rcctl reload nginx
Step 4 – Create a test PHP file
echo '<?php phpinfo(); ?>' > /var/www/example.com/html/info.php
Visit http://example.com/info.php in a browser. Remove the file afterwards:
rm /var/www/example.com/html/info.php