PostgreSQL安装配置及phppgAdmin外部访问

PostgreSQL 是一款强大的高性能的对象关系型数据库管理系统(ORDBMS),采用与BSD一样的授权方式。PostgreSQL是非常适合大型数据库,有许多先进的功能。PostgreSQL支持许多操作系统,包括Linux,FreeBSD,Solaris和Microsoft Windows。

phpPgAdmin 是管理PostgreSQL数据库基于PHP的Web应用程序。使用phpPgAdmin很容易创建一个数据库,创建一个角色,并在Postgres里创建表。下面说说在Ubuntu 16.04 下安装 PostgreSQL 和 phpPgAdmin的过程。

第一步:安装 PostgreSQL, phpPgAdmin 和 Apache2

sudo apt-get -y install postgresql postgresql-contrib phppgadmin

sudo apt-get install postgis

第二步:配置Postgresql


接下来是配置postgresql

由于目前为止,只能本机登陆到数据库,但实际情况是会选择远程登录,所以需要做如下配置:

打开vim /etc/postgresql/9.1/main/postgresql.conf

1、监听任何地址访问,修改连接权限

 

#listen_addresses = ‘localhost’改为 listen_addresses = ‘*’

2、启用密码验证

 

 

#password_encryption = on 改为 password_encryption = on


打开vim /etc/postgresql/9.1/main/pg_hba.conf,并在文档末尾加上以下内容
 

 

3、可访问的用户ip段

 

 
  1. # to allow your client visiting postgresql server

  2. host all all 0.0.0.0 0.0.0.0 md5

 

 

 

 

第三步:配置 PostgreSQL 用户

PostgreSQL使用的用户认证和授权类似UNIX权限角色。默认情况下,PostgreSQL创建了一个名为“Postgres”基本身份验证新用户。要使用PostgreSQL,您需要登录到“Postgres”账户,你可以通过键入:

sudo -u postgres psql

 

然后更改Postgres角色的密码:

hy@hy-X1:/etc/postgresql$ sudo -u postgres psql
psql (9.5.14)
Type "help" for help.

postgres=# \password
Enter new password:
Enter it again:
postgres=#

 

然后输入q退出psql命令行。

 

运行命令“exit”再次离开Postgres的用户,并成为root。

exit

第三步:配置Apache2

cd /etc/apache2/conf-available/
nano phppgadmin.conf

注释掉#Require local,添加allow from all,这样才可以从你的浏览器访问。

Ubuntu 16.04 下安装 PostgreSQL 和 phpPgAdmin

第四步:配置 phpPgAdmin

编辑文件 /etc/phppgadmin/config.inc.php :

cd /etc/phppgadmin/
nano config.inc.php

找到 $conf[‘extra_login_security’] = true; 修改为false。

你就可以使用 postgres 用户登陆 phpPgAdmin。

phppgadmin_security_settings

第五步:重启 PostgreSQL 和 Apache2

systemctl restart postgresql
systemctl restart apache2

第六步:测试登录

192.168.1.xxx/phppgadmin

使用postgres用户和刚才设置的密码登陆

调试其他服务时,发现403错误,无法访问phppgadmin,经查发现端口占用,可以用:

netstat -lnp|grep 80

找到占用进程,然后杀掉,重启apache2服务

PostgreSQL安装配置及phppgAdmin外部访问_第1张图片

 

你可能感兴趣的:(IOT,数据库,web)