100-Days-Of-DevOps-Challenge-KodeKloud

Configure Nginx + PHP-FPM Using Unix Sock

The Nautilus application development team is planning to launch a new PHP-based application, which they want to deploy on Nautilus infra in Stratos DC. The development team had a meeting with the production support team and they have shared some requirements regarding the infrastructure. Below are the requirements they shared:

Steps

  1. Login into App Server and run the following commands:

     sudo dnf update -y
     sudo dnf install nginx -y
     sudo dnf module install php:8.2 -y # change version here if requires
    
    • It will update packge repo
    • Install nginx and php with expected version
  2. Configure php-fpm config:

     sudo mkdir -p /var/run/php-fpm
     sudo vi /etc/php-fpm.d/www.conf
    
    • listen = /run/php-fpm/www.sock update this line with expected directory. It should be listen = /var/run/php-fpm/default.sock
  3. Configure nginx

     sudo vi /etc/nginx/nginx.conf
    
    • change port 80 to 8093
  4. Configure php with nginx

     sudo vi /etc/nginx/default.d/php.conf
    
    • Update fastcgi_pass php-fpm; to this: fastcgi_pass unix:/var/run/php-fpm/default.sock;
  5. Restart php-fpm and nginx

     sudo systemctl enable --now nginx
     sudo systemctl enable --now php-fpm
    
  6. Test: curl http://stapp01:8093/index.php

Good to Know?

PHP-FPM (FastCGI Process Manager)

Communication Methods

NGINX + PHP-FPM Benefits

Configuration Best Practices