You should look at the nginx logs in /var/log/nginx
to see what it is doing - both the access and error log
Hi Alistair,
here are the logs:
cat /var/log/nginx/error.log
2023/11/16 02:39:50 [crit] 1658#0: *1 connect() to unix:/run/php-fpm/www.sock failed (2: No such file or directory) while connecting to upstream, client: 172.16.238.2, server: _, request: “GET /index.php HTTP/1.1”, upstream: “fastcgi://unix:/run/php-fpm/www.sock:”, host: “stapp01:8093”
2023/11/16 02:39:50 [error] 1658#0: *1 open() “/var/www/html/50x.html” failed (2: No such file or directory), client: 172.16.238.2, server: _, request: “GET /index.php HTTP/1.1”, upstream: “fastcgi://unix:/run/php-fpm/www.sock”, host: “stapp01:8093”
cat /var/log/nginx/access.log
172.16.238.2 - - [16/Nov/2023:02:39:50 +0000] “GET /index.php HTTP/1.1” 404 169 “-” “curl/7.61.1” “-”
thanks
ngnix is not connecting to the socket given in the question. Therefore the curl test will fail, and the question will not pass.
Hi Alistair,
This is the changes to nginx.conf
server {
listen 8097;
listen [::]:8097;
server_name _;
root /var/www/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/default.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
And www.conf
user = nginx
group = nginx
listen = /run/php-fpm/default.sock
ls /var/run/php-fpm
default.sock php-fpm.pid
did I miss out anything? I still get the same error from nginx log
Thanks
Hello Alistair,
do you have any idea where I have gone wrong?
Thanks
Hi Alistair,
I have solve it and the task is completed.
from How to Connect NGINX to PHP-FPM Using UNIX or TCP/IP Socket
vi /etc/nginx/nginx.conf : add the below block
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
vi /etc/nginx/conf.d/php-fpm.conf
# PHP-FPM FastCGI server
# network or unix domain socket configuration
upstream php-fpm {
server unix:/run/php-fpm/default.sock;
}
And it works.
Hello @Alistair_KodeKloud ,
“I got the same error twice. Please help me with this. I’m running Nginx on the right server, and I’m using the curl command as given in the task. If the port is wrong, then how is that command working, especially considering that the same port is used in that command?”
It can work if you have configured the port consistently through the task, but if the port is not the one the question asks for then it will be incorrect.
The port is likely to be different each time you retry the question.
I have just done the lab again and it is working
At the end, you must exit from the app server back to jump host and the curl command must work from there too (see part d.
of question).
[thor@jump_host]$ curl http://stapp03:8093/index.php
Welcome to xFusionCorp Industries![thor@jump_host]$
@34_Aniket-Kale Just to make absolutely sure the lab isn’t broken I did it a second time and it is not broken, so if it is not working for you, then you have made a mistake somewhere.
I have written up a detailed solution here.
Thank You its working now
Respected Sir,
Following steps i did to accomplish the task
Install Nginx
sudo yum install -y nginx
sudo systemctl enable nginx
Configure NGINX for the app
Edited /etc/nginx/nginx.conf:
sudo vi /etc/nginx/nginx.conf
server {
listen 8095;
listen [::]:8095;
server_name stapp03;
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;
}
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
sudo systemctl restart nginx
Install PHP-FPM 8.1
sudo dnf install epel-release -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
sudo dnf module list php
sudo dnf module enable php:remi-8.1 -y
sudo dnf install php-fpm php php-cli php-common php-mysqlnd php-gd php-xml php-mbstring php-pdo php-opcache -y
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
php-v
sudo systemctl status php-fpm
Configure PHP-FPM
Edited /etc/php-fpm.d/www.conf:
sudo vi /etc/php-fpm.d/www.conf
listen = /var/run/php-fpm/default.sock
;listen.owner = nginx
;listen.group = nginx
;listen.mode = 0660
sudo mkdir -p /var/run/php-fpm
sudo chown -R nginx:nginx /var/run/php-fpm
sudo systemctl enable --now php-fpm
Testing
From the Jump Host, I ran:
Curl… command
Error : php-fpm is not congigured to use ‘/var/run/php-fpm/default.sock’ socket App Server 3
Kindly detect the error in the whole process.
Found my mistake. Completed now!!!
change ```
fastcgi_pass unix:/var/run/php-fpm/default.sock;
to ```
fastcgi_pass php-fpm;
Then go to /etc/nginx/conf.d/php-fpm.conf and put this "/var/run/php-fpm/default.sock" in the upstream{}
Many Thanks for your reply.
I’ve successfully completed my task.
This is what i did to accomplish the task:
Install Nginx
sudo yum install -y nginx
sudo systemctl enable nginx
Configure NGINX for the app
Edited /etc/nginx/nginx.conf:
sudo vi /etc/nginx/nginx.conf
server {
listen 8091 ;
listen [::]:8091;
server_name stapp03;
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;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
sudo systemctl restart nginx
Install PHP-FPM 8.3
sudo dnf install epel-release -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
sudo dnf module list php
sudo dnf module enable php:remi-8.3 -y
sudo dnf install php-fpm php php-cli php-common php-mysqlnd php-gd php-xml php-mbstring php-pdo php-opcache -y
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
php -v
sudo systemctl status php-fpm
Configure PHP-FPM
Edited /etc/php-fpm.d/www.conf:
sudo vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx
listen = /var/run/php-fpm/default.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
Also, ensure the directory exists:
sudo mkdir -p /var/run/php-fpm
sudo chown -R nginx:nginx /var/run/php-fpm
sudo systemctl enable --now php-fpm
Testing:
From the Jump Host, I ran:
Curl… command