phpdockersocketsnginxubuntu-server

NGINX: connect() to unix:/run/php/php8.1-fpm.sock failed (95: Unknown error)


I have tried all of these questions to solve my issue, and nothing is working (1, 2, 3).

These files are from a private repository running a live website. Other people working on this site can copy the repos and run the site locally. However, my local environment is causing me so many issues. The main issue is with the socket that is being created for php-fpm.

The local site that I can develop from loads 95% of pages. It is mainly an OpenLayers map website with other more static content that is connected to the data. I can develop fine on the map portions of the site. However, on the API part there is a 502 Bad Gateway error from nginx/1.18.0 (Ubuntu), at this URL: http://localhost/api/. Most of the API pages are working from PHP, hence the php-fpm. Below are the type of errors I am getting. Here is the full set of environment files (combined into one file).

error.log

2024/12/20 19:44:55 [error] 24#24: *1 connect() to unix:/run/php/php8.1-fpm.sock failed (111: Unknown error) while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET /api/map_dates/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.1-fpm.sock:", host: "localhost", referrer: "http://localhost/us/map2/"
2024/12/20 20:28:05 [crit] 526#526: *4 connect() to unix:/run/php/php8.1-fpm.sock failed (95: Unknown error) while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET /api/map_dates/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.1-fpm.sock:", host: "localhost", referrer: "http://localhost/us/map2/"

Some of the changes from the original repository that have made the API page(s) sort of load correctly. This is only a couple of them others completly do not load.

compose.yaml file changes from link above.

# Commenting out this line
#- ${WEB_RUNTIME_ROOT_DIR}/sitez/var/run:/var/run
# Changing the entry point
#entrypoint: /bin/sh -c "service nginx start; service memcached start; service php8.1-fpm start;tail -f /dev/null"
entrypoint: /bin/sh -c "mkdir -p /run/php && chown www-data:www-data /run/php && service nginx start && service memcached start && service php8.1-fpm start && tail -f /dev/null"

Adding this line to the Dockerfile RUN mkdir -p /run/php && chown www-data:www-data /run/php && chmod 0755 /run/php

Changes to nginx.conf. (Commenting and uncommeting the debug statement for the error log)

# Commenting the line below out in the location ~ [^/]\.php(/|$) { here }
# include snippets/fastcgi-php.conf

# Adding these lines into location /api/ { here }
# proxy_pass http://localhost:9000; # Commented out because this did not work 
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

The final changes to www.conf are moving the listen and refernce to the socket above the user and group, and uncommenting the listen.mode = 0660.

I am trying to edit an API page and it is only working to show the php_info(); or one (not more) print('Here'); statement. From what I can understand the php is not processing like it should. Otherwise without the print or php_info the page returns a 500 error just like the pages that do not work even with the changes jsut mentioned.

I have tried TCP ports as well, which also did not solve the problem.


Solution

  • It turns out that the issue was not having a SSH connection to the computers that can connect to the database. Also, the only change needed to the files is in the yaml file keeping the one line commented out; the entry point does not need to change.