phpPgAdmin-5.1安装配置

phpPgAdmin-5.1安装配置


官方网站:http://phppgadmin.sourceforge.net/doku.php
参考文档:
https://raw.githubusercontent.com/phppgadmin/phppgadmin/master/INSTALL
http://www.postgresql.org/docs/9.0/static/runtime-config-file-locations.html#GUC-IDENT-FILE
http://www.postgresql.org/docs/9.0/static/auth-username-maps.html


环境:
CentOS6.5 x64
PHP 5.3.3
Apache-2.2.15
postgres (PostgreSQL) 8.4.18
phpPgAdmin-5.1



一.安装postgresql,php,httpd
[root@sentinel ~]# yum -y install postgresql-server postgresql php php-pgsql


二.配置php
[root@sentinel ~]# vim /etc/php.ini
safe_mode_allowed_env_vars = PHP_,PG
safe_mode_exec_dir = /usr/bin



三.配置postgresql
1.启postgresql服务
[root@sentinel ~]# postgres --version
postgres (PostgreSQL) 8.4.18
[root@sentinel ~]# service  postgresql initdb
Initializing database: [  OK  ]
[root@sentinel ~]# service postgresql start
Starting postgresql service: [  OK  ]
[root@sentinel ~]# chkconfig postgresql on
[root@sentinel ~]# chkconfig --list postgresql
postgresql         0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@sentinel ~]# netstat -tunlp|grep post
tcp            0 127.0.0.1:5432              0.0.0.0:*                   LISTEN      1709/postmaster
 
2.配置postgresql
a.主配置文件/var/lib/pgsql/data/postgresql.conf
[root@sentinel ~]# vim /var/lib/pgsql/data/postgresql.conf
listen_addresses = '*'
port = 5432
track_activities = on
track_counts = on

[root@sentinel ~]# service postgresql restart
Stopping postgresql service: [  OK  ]
Starting postgresql service: [  OK  ]
[root@sentinel ~]# netstat -tunlp|grep post
tcp            0 0.0.0.0:5432                0.0.0.0:*                   LISTEN      3149/postmaster
b.客户端认证配置文件/var/lib/pgsql/data/pg_hba.conf
http://www.postgres.cn/docs/9.4/auth-pg-hba-conf.html
[root@sentinel ~]# vim /var/lib/pgsql/data/pg_hba.conf
local   all         all                               md5
host    all         all         127.0.0.1/32          md5
host    all         all         ::1/128               md5
host    all         all         192.168.8.0/24        md5

注意:local   all         all                               md5
做实验想最快看到效果,需要把验证方式全部换成非ident如md5,ident的话需要额外配置pg_ident.conf文件,如果不改,在网页版登录界面即使输入了正确的用户名和密码也总会提示"login failed"
[root@sentinel ~]# tail -f /var/lib/pgsql/data/pg_log/postgresql-Wed.log
LOG:  could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL:  Ident authentication failed for user "postgres"

重新加载认证配置文件
[root@sentinel ~]# su - postgres -c "pg_ctl reload"
server signaled

3.测试postgresql
PostgreSQL数据库安装完成后默认会创建一个linux系统用户postgres
a.修改系统用户postgres默认用户密码
[root@sentinel ~]# id postgres
uid=26(postgres) gid=26(postgres) groups=26(postgres)
[root@sentinel ~]# echo postgres:postgres|chpasswd
b.创建测试数据库
[root@sentinel ~]# su - postgres
-bash-4.1$ psql
psql (8.4.18)
Type "help" for help.

postgres=# alter user postgres with password 'postgres';
ALTER ROLE
#修改postgresql数据库用户密码
postgres=# select * from pg_shadow;
 usename  | usesysid | usecreatedb | usesuper | usecatupd |               passwd
                | valuntil | useconfig
----------+----------+-------------+----------+-----------+---------------------
----------------+----------+-----------
 postgres |       10 | t           | t        | t         | md53175bce1d3201d165
94cebf9d7eb3f9d |          |
(1 row)

postgres=# create database phppgadmin;
CREATE DATABASE
postgres=# l
                                  List of databases
    Name    Owner   | Encoding |  Collation    Ctype     Access privile
ges  
------------+----------+----------+-------------+-------------+-----------------
------
 phppgadmin | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 postgres   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                              : postgres=CTc/pos
tgres
 template1  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                              : postgres=CTc/pos
tgres
(4 rows)

postgres=# c phppgadmin
psql (8.4.18)
You are now connected to database "phppgadmin".
phppgadmin=# create table test (id integer,name text);
CREATE TABLE
phppgadmin=# insert into test values (1,'foo');
INSERT 0 1
phppgadmin=# select * from test;
 id | name
----+------
  1 | foo
(1 row)

phppgadmin-# q


四.启httpd服务
[root@sentinel ~]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for sentinel
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
OK  ]
[root@sentinel ~]# chkconfig httpd on
[root@sentinel ~]# chkconfig --list httpd
httpd              0:off    1:off    2:on    3:on    4:on    5:on    6:off
可以通过phpinfo()来测试php


五.安装phpPgAdmin
1.解压
[root@sentinel ~]# tar -xvf phpPgAdmin-5.1.tar.bz2 -C /usr/local/src/

2.移动动到httpd根目录
[root@sentinel ~]# mv /usr/local/src/phpPgAdmin-5.1/ /var/www/html/phpPgAdmin

3.修改配置文件
a.修改连接主机
config.inc.php和config.inc.php-dist模板文件默认是一样的,以后可以通过config.inc.php-dist来恢复。
[root@sentinel ~]# vim /var/www/html/phpPgAdmin/conf/config.inc.php
$conf['servers'][0]['host'] = 'localhost';
$conf['extra_login_security'] = false;
#false是允许super用户登录,可选项;默认为true,不允许super用户登录
'extra_login_security', which is TRUE by default.  While this option is enabled, you will be unable to log in to phpPgAdmin as the 'root', 'administrator', 'pgsql' or 'postgres' users and empty passwords will not work.
b.创建postgresql数据库super用户admin,密码admin
[root@sentinel ~]# su - postgres
-bash-4.1$ createuser -P
Enter name of role to add: admin
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) y
这样postgresql数据库中就有了两个super用户(postgresql,admin),可以通过$conf['extra_login_security'] = false;
来对比true和false的区别。

4.登录
phpPgAdmin-5.1安装配置

phpPgAdmin-5.1安装配置
phpPgAdmin-5.1安装配置






原文地址:https://www.cnblogs.com/lixuebin/p/10814432.html