How to install PostgreSQL9.3 and phpPgAdmin in centos 7/6.5/6.4

Source: Internet
Author: User
Tags psql unix domain socket
PostgreSQL is a powerful open-source object relational database system that runs on almost all major operating systems, including Linux, Unix (AIX, BSD, HP-UX, SGI

PostgreSQL is a powerful open-source object relational database system that runs on almost all major operating systems, including Linux, Unix (AIX, BSD, HP-UX, SGI

PostgreSQL is a powerful open-source object relational database system that runs on almost all major operating systems, including Linux, Unix (AIX, BSD, HP-UX, sgi irix, Mac OS, Solaris, Tru64), and Windows OS. In this tutorial, we will learn how to create PostgreSQL in CentOS7/6.5/6.4 server.

1. Install PostgreSQL

First, add the PostgreSQL library based on your server architecture:

For CentOS 6.x 32bit:

Rpm-Uvh 1. noarch. rpm

For CentOS 6.x 64bit:

Rpm-Uvh

For CentOS 7 64bit:

Rpm-Uvh

For other releases, you can view the following links and create a Library:

Run the following command to update the database:

Yum update

Run the following command to install PostgreSQL:

Yum install postgresql93-server postgresql93-contrib

Run the following command to initialize the PostgreSQL database:

In CentOS 6.x:

Service postgresql-9.3 initdb

In CentOS 7:

/Usr/pgsql-9.3/bin/postgresql93-setup initdb

Then start the PostgreSQL service and enable it:

In CentOS 6.x:

Service postgresql-9.3 start

Chkconfig postgresql-9.3 on

In CentOS 7:

Systemctl enable postgresql-9.3

Systemctl start postgresql-9.3

2. Adjust Iptables/Firewall

Next, adjust the firewall outbound rules:

In CentOS 6. x:

Vi/etc/sysconfig/iptables

And add the following lines

-A input-m state -- state NEW-m tcp-p tcp -- dport 5432-j ACCEPT

-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT

Exit and save the file. Restart the iptables service:

Service iptables restart

In CentOS:

Firewall-cmd -- permanent-add-port = 5432/tcp

Firewall-cmd -- permanent-add-port = 80/tcp

Firewall-cmd -- reload

3. Access common PostgreSQL Command Prompt

By default, both the Database Name and user name are ipvs. Switch to the user for related operations:

Su-postgres

Enter the following command to log on:

Psql

The following is an example output:

Psql (9.3.5)

Type "help" for help.

Postgres = #

You can enter \ q to exit the postgresql return command terminal:

4. Set the User Password

Log on to the postgres command prompt Interface

Su-postgres

Psql

Then use the command to set the password

Postgres = # \ password postgres

Enter new password:

Enter it again:

Postgres = # \ q

Enter the command to create a PostgreSQL system management tool

S = # create extension adminpack;

CREATE EXTENSION

5. Create users and databases

Example: Username: senthil password: centos Database Name: mydb

To postgres user

Su-postgres

Create user senthil

$ Createuser senthil

Create a database

$ Createdb mydb

Log on to the psql prompt page and set a password for senthil and authorize access to mydb:

$ Psql

Psql (9.3.5)

Type "help" for help.

Postgres = # alter user senthil with encrypted password 'centos ';

ALTER ROLE

Postgres = # grant all privileges on database mydb to senthil;

GRANT

Postgres = #

6. delete users and databases

First go to postgres Interface

Su-postgres

Enter the command

$ Dropdb

You can enter the delete user name.

$ Dropuser

7. Configure PostgreSQL-MD5 Authentication

MD5 authentication requires the client to provide a MD5-encrypted password for authentication. You need to edit the/var/lib/pgsql/9.3/data/pg_hba.conf file:

Vi/var/lib/pgsql/9.3/data/pg_assist.conf

The added or modified rows are as follows:

[...]

# TYPE DATABASE USER ADDRESS METHOD

# "Local" is for Unix domain socket connections only

Local all md5

# IPv4 local connections:

Host all 127.0.0.1/32 md5

Host all 192.168.1.0/24 md5

# IPv6 local connections:

Host all: 1/128 md5

[...]

Restart the postgresql service to change the application

In CentOS 6. x System

Service postgresql-9.3 restart

In CentOS 7

Systemctl restart postgresql-9.3

8. Configure PostgreSQL-Configure TCP/IP

By default, TCP/IP connections are not feasible, so other computer users cannot connect to postgresql. You can edit the file/var/lib/pgsql/9.3/data/postgresql. conf to allow connections:

Vi/var/lib/pgsql/9.3/data/postgresql. conf

Find the following line:

[...]

# Listen_addresses = 'localhost'

[...]

# Port = 5432

[...]

Cancel the two lines and set them to your postgresql Server IP address or set it to "*" to listen to all clients. As follows:

Listen_addresses = '*'

Port = 5432

Restart to apply changes

In CentOS6.x:

/Etc/init. d/postgresql-9.3 restart

In CentOS7:

Systemctl restart postgresql-9.3

9. Use phpPgAdmin to manage PostgreSQL

PhpPgAdmin is a web-based management tool written in PHP to manage PostgreSQL. It is only applicable to PostgreSQL RPM databases.

If you have not added a PostgreSQL database, you can add an EPEL database.

You can create an EPEL library in CentOS 6. x based on the following links.

For CentOS 7, refer to the following link.

Use commands to update Libraries

Yum update

Run the following command to install phpPgAdmin:

Yum install phpPgAdmin httpd

Note that phpPgAdmin is case sensitive. Make sure that the above case is correct!

By default, you can access phpPgAdmin. To continue remote access:

Edit the/etc/httpd/conf. d/phpPgAdmin. conf file.

Vi/etc/httpd/conf. d/phpPgAdmin. conf

Modify the following bold parts:

[...]

Alias/phpPgAdmin/usr/share/phpPgAdmin

# Apache 2.4

Require all granted

# Require host example.com

# Apache 2.2

Order deny, allow

Allow from all

# Allow from .example.com

Start or restart the Apache service

In CentOS 6. x System

Service httpd start

Chkconfig httpd on

In CentOS 7

Systemctl enable httpd

Systemctl start httpd

Now open the browser and go. Finally, we can see the following interface!

Log On with the user you created earlier. My account is the senthil password CentOS.

You may encounter: Login failed.

This is because SELLinux may restrict users from connecting to PostgreSQL. Just enter the following command to change it:

Setsebool-P httpd_can_network_connect_db 1

Now you should be able to log on normally.

My phpPgAdimn is as follows:

OK! Now you can use phpPgAdmin on the graphic interface to create, delete, and manage databases.

How To Install PostgreSQL 9.3 And phpPgAdmin In CentOS 7/6. 5/6. 4

To learn more about the author, visit the Linux community.

This article was launched by the Linux community translation group's original translation Linux community

------------------------------------ Lili split line ------------------------------------

Install PostgreSQL 6.3 on yum in CentOS 9.3

PostgreSQL cache details

Compiling PostgreSQL on Windows

Configuration and installation of LAPP (Linux + Apache + PostgreSQL + PHP) Environment in Ubuntu

Install and configure phppgAdmin on Ubuntu

Install PostgreSQL9.3 on CentOS

Configure a Streaming Replication cluster in PostgreSQL

------------------------------------ Lili split line ------------------------------------

PostgreSQL details: click here
PostgreSQL: click here

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.