Installing Pgadmin4 on a server with ispmanager 6
To manage PostgreSQL within the ispmanager 6 control panel, you can use the PgAdmin 4 web application.
Authentication in PgAdmin 4 is performed with one account, after which you can connect to PostgreSQL as the specific user you require.
First, install the PgAdmin 4 application:
curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /etc/apt/keyrings/packages-pgadmin-org.gpg
sudo sh -c 'echo "deb [signed-by=/etc/apt/keyrings/packages-pgadmin-org.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
apt install pgadmin4-web
rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm
yum install pgadmin4-web
Configure the installed PgAdmin 4:
This configuration is supported for Nginx + Apache Prefork
/usr/pgadmin4/bin/setup-web.sh
Create a configuration file for PgAdmin 4 in the Nginx directory:
touch /etc/nginx/vhosts-includes/pgadmin4-nginx.conf
Add the following configuration to the file you created:
location = /pgadmin4 {
return 301 /pgadmin4/;
}
location /pgadmin4/ {
proxy_pass http://127.0.0.1:8080/pgadmin4/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Script-Name /pgadmin4;
proxy_redirect http://127.0.0.1:8080/pgadmin4/ /pgadmin4/;
proxy_redirect http://127.0.0.1:8080 /;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
proxy_cookie_path /pgadmin4 /pgadmin4;
}
If you have specified a different port for PgAdmin 4, update it accordingly in the proxy_pass directive..
Restart Nginx:
service nginx restart
The PgAdmin 4 web interface is now accessible via the /pgadmin4 path on your server's IP address or any domain hosted in the panel—for example: https://192.168.0.10/pgadmin4 or https://domain.com/pgadmin4.
To add a button for accessing the web interface in the Main menu, create the following two files:
touch /usr/local/mgr5/etc/xml/ispmgr_mod_pgadmin.xml
touch /usr/local/mgr5/addon/myaddon.sh
Add the following configuration to the file /usr/local/mgr5/etc/xml/ispmgr_mod_pg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<mgrdata>
<mainmenu level="user+">
<modernmenu>
<node name="my_pgadmin4" customicon="/manimg/icons/pg.svg">
<node name="open_pgadmin4" function="https://<ip-адрес_сервера>/pgadmin4" />
</node>
</modernmenu>
</mainmenu>
<handler name="myaddon.sh" type="xml">
<func name="open_pgadmin4" />
</handler>
<lang name="en">
<messages name="desktop">
<msg name="modernmenu_my_pgadmin4">PostgreSQL</msg>
<msg name="modernmenu_open_pgadmin4">Pgadmin4</msg>
</messages>
</lang>
</mgrdata>
In the function value, specify your IP address or domain name. You can use any website hosted in the panel; in this case, PgAdmin 4 will be accessed via that website’s address and will be secured by the website’s SSL certificate (if one is installed).
Add a single line to the file /usr/local/mgr5/addon/myaddon.sh:
#!/bin/bash
Restart the panel:
/usr/local/mgr5/sbin/mgrctl -m ispmgr -R