1

i try to build website in ubuntu vps using nginx, php7.4, and PostgreSQL. my goal is using unix socket to communicate through ajax-phpfpm-postgresql to execute query sql in PHP program.

i have change my serverblock to use php7.4-fpm

location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

sudo nano /etc/php/7.4/fpm/pool.d/www.conf and change variable to bellow

listen = /run/php/php7.4-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

and sudo nano /etc/postgresql/13/main/postgresql.conf and turn

listen address='*'
 unix_socket_directories = '/var/run/postgresql'
#if I change unix socket directories to /run/php/, I cant access postgresql through terminal#

and change pg_hba.conf. the local method into thrust (because I still confused what should id do)

local   all             all                                     trust

and change pg_connect variable in php program to use unix

$host = 'var/run/postgresql';
$dbname = 'confidential';
$user = 'confidential';
$password = 'confidential';

it's still not working even i try to check all of the error log in nginx, PHP, and postgresql,and the ajax respond is still error output,
my question

  1. which one unix socket I have to use in this server in each file above? php7.4-fpm.sock or the PostgreSQL
  2. do anybody have complete tutorial that have the same goal with mine?


source of tutorial(maybe i miss some tutorial link)
https://www.tecmint.com/connect-nginx-to-php-fpm/
https://medium.com/@danilsyah/install-web-server-nginx-php8-0-fpm-postgresql-v12-in-ubuntu-server-22-04-d0113495115d
https://gustavostraube.wordpress.com/2009/10/02/connecting-php-to-postgresql-via-unix-sockets/
https://www.php.net/manual/en/function.pg-connect.php https://www.digitalocean.com/community/tutorials/php-fpm-nginx
1
  • Per docs libpq: If a host name looks like an absolute path name, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored. (On Unix, an absolute path name begins with a slash. .... So /var/run/postgresql. Commented Mar 17, 2024 at 15:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.