Day 20: Configure Nginx + PHP-FPM Using Unix Sock

Day 20: Configure Nginx + PHP-FPM Using Unix Sock

I’m 100% sure about the port and configured it correctly because I copied the command from the task to make sure my task is correct, but still the task is getting failed

- 'nginx' is not using correct port on App Server 3

I was able to solve this.

It would be helpful if you could also explain what steps you missed or what wasn’t done properly. That way, others who face the same issue can learn from your experience and avoid the same mistakes.

I was using custom app.conf file to define custom port for nginx. In that case, I have to edit /etc/nginx/nginx.conf file and comment the complete following block

#server {
#    listen       80 default_server;
#   listen       [::]:80 default_server;
#    ...
#}

Save the file and restart the nginx service.

Yes, that makes sense. Without commenting this out, Nginx will still listen on the default port 80 and show the default Nginx page.

@sarangm , can you kindly provide the steps to install php

sudo apt install php php-fpm -y

Hi @dpakmishra.1983

Example for php-fpm 8.2

sudo dnf install epel-release -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.2 -y

I’m having the same issue. Has anyone found a solution?


Same problem here, this is the command used to check completion and when I hit check it says I got the wrong port configured.

This is my fourth time doing this, I’m using the correct port and the correct command to check.

The required port is seen here and the command used to check.

Hi guys,

I didn’t have any issues with this task. Please see my code and the screenshot below.

Install nginx and php-fpm with require version

Create a custom site config:
sudo vi /etc/nginx/conf.d/phpapp.conf

server {
    listen 8099;
    server_name stapp01;

    root /var/www/html;
    index index.php index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php-fpm/default.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
sudo nginx -t
sudo systemctl reload nginx

Edit the PHP-FPM pool config:
Update:
listen = /var/run/php-fpm/default.sock
listen.owner = nginx
listen.group = nginx

sudo mkdir -p /var/run/php-fpm
sudo chown nginx:nginx /var/run/php-fpm

Start & enable PHP-FPM:

sudo systemctl enable php-fpm
sudo systemctl start php-fpm

After multiple tries I was able to find the issue.

server_name _; has to be updated to mach the server name e.g: server_name stapp01;

I was able to resolve this by removing the TLS Server block in the nginx.conf file, only issue is that that server block is COMMENTED so nginx is NOT reading it, it shouldn’t be an issue. Seems like the "check’ button only checks for plaintext and not what the actual conf file is doing. I had to do this lab six times and I finally decided to delete that commented server block.