<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: soufyane</title>
    <description>The latest articles on DEV Community by soufyane (@soufyaneyassin).</description>
    <link>https://dev.to/soufyaneyassin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F771554%2F8f419e81-9611-4b77-b86d-361b67d1f9b8.jpeg</url>
      <title>DEV Community: soufyane</title>
      <link>https://dev.to/soufyaneyassin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/soufyaneyassin"/>
    <language>en</language>
    <item>
      <title>Install PostgreSQL &amp; PhpPgAdmin on Centos 7</title>
      <dc:creator>soufyane</dc:creator>
      <pubDate>Thu, 09 Dec 2021 16:20:00 +0000</pubDate>
      <link>https://dev.to/soufyaneyassin/install-postgresql-phppgadmin-on-centos-7-2bkb</link>
      <guid>https://dev.to/soufyaneyassin/install-postgresql-phppgadmin-on-centos-7-2bkb</guid>
      <description>&lt;p&gt;In this article we are going to install Postgresql-12 with PhpPgAdmin on Centos 7:&lt;/p&gt;

&lt;p&gt;After connect to your server follow these Steps:&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Install apache and Configure Firewall
&lt;/h2&gt;

&lt;p&gt;run the following commands:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo yum install httpd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;now run these commands to enable and start the apache service:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo systemctl start httpd.service&lt;br&gt;
 $ sudo systemctl enable httpd.service&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;now lets configure our firewall, first you need to start your firewalld service by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ systemctl start firewalld&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then run the following commands and reload the firewalld service:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo firewall-cmd --zone=public --permanent --add-service=http&lt;br&gt;
$ sudo firewall-cmd --zone=public --permanent --add-port=5432/tcp&lt;br&gt;
$ sudo firewall-cmd --reload&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Install php
&lt;/h2&gt;

&lt;p&gt;before moving to next steps, we need first to setup php in our machine, in my case i'am using php 7.4&lt;br&gt;
just run the following commands and you'll have php installed &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ sudo yum -y install yum-utils&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ sudo yum-config-manager --enable remi-php74&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ sudo yum update&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo yum install php php-mbstring&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;now you can check from the terminal your php version by running:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ php -v&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo40uuchletggk7lren8l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo40uuchletggk7lren8l.png" alt="check php version"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: PostgreSQL installation
&lt;/h2&gt;

&lt;p&gt;in this tutorial we are using PostgreSQL version 12, if you would like to install any other version you can visit this &lt;a href="https://www.postgresql.org/download/linux/redhat/" rel="noopener noreferrer"&gt;website&lt;/a&gt; and they will provide you with necessary commands to use.&lt;/p&gt;
&lt;h3&gt;
  
  
  Note !: on the following commands i'am using PostgreSQL 12 so dont forget to replace the number 12 with your own version.
&lt;/h3&gt;

&lt;p&gt;so lets start the installation by running:&lt;br&gt;
&lt;code&gt;$ sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm&lt;/code&gt;&lt;br&gt;
then run:&lt;br&gt;
&lt;code&gt;$ sudo yum install -y postgresql12-server&lt;/code&gt;&lt;br&gt;
the following commands are Optional to initialize the database and enable automatic start:&lt;br&gt;
&lt;code&gt;$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb&lt;br&gt;
$ sudo systemctl enable postgresql-12&lt;br&gt;
$ sudo systemctl start postgresql-12&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;now we need to configure the Postgresql files:&lt;/p&gt;

&lt;p&gt;run the follwing command (i'am using nano editor ,if you are using vim just replace nano with vi):&lt;br&gt;
&lt;code&gt;$ sudo nano /var/lib/pgsql/12/data/pg_hba.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;find the section below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# IPv4 local connections:
host    all             all             127.0.0.1/32          ident
# IPv6 local connections:
host    all             all             ::1/128               ident
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then modify the authentication method of local connections as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now save and exit:&lt;br&gt;
using nano: hit ctrl+o+enter then ctrl+x&lt;br&gt;
using vim:   hit :wq&lt;/p&gt;

&lt;p&gt;now we will move to the next configuration file:&lt;br&gt;
&lt;code&gt;$ sudo nano /var/lib/pgsql/12/data/postgresql.conf&lt;/code&gt;&lt;br&gt;
find the line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#listen_addresses = 'localhost'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;replace it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;listen_addresses = '*'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then find:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#port = 5432
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;replace it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;port = 5432
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now save and exit as we did before.&lt;br&gt;
finally for this step run these two commands:&lt;br&gt;
&lt;code&gt;$ sudo systemctl start postgresql-12.service&lt;br&gt;
$ sudo systemctl enable postgresql-12.service&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Bonus: Configure database informations:
&lt;/h4&gt;

&lt;p&gt;this part is for  creating a user and database from the terminal.&lt;br&gt;
first run:&lt;br&gt;
&lt;code&gt;$ sudo -u postgres psql&lt;/code&gt;&lt;br&gt;
then:&lt;br&gt;
&lt;code&gt;CREATE USER jhon ENCRYPTED PASSWORD '1234';&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;replace 'jhon' and '1234' with your own credentials!! &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;CREATE DATABASE dbname OWNER jhon;&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;additional info: if your database name contain "-" like for example "db-name" use the following command instead:&lt;br&gt;
&lt;code&gt;CREATE DATABASE "db-name" OWNER jhon;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;finally run this command:&lt;br&gt;
&lt;code&gt;GRANT ALL PRIVILEGES ON DATABASE dbname TO jhon;&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: Install and use PhpPgAdmin
&lt;/h2&gt;

&lt;p&gt;to install phpPg admin run the following command:&lt;br&gt;
&lt;code&gt;$ sudo yum install phpPgAdmin&lt;/code&gt;&lt;br&gt;
next pass direclty to the configuration by running:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo nano /etc/httpd/conf.d/phpPgAdmin.conf&lt;/code&gt;&lt;br&gt;
Replace the line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Require local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Require all granted
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Deny from all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Allow from all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now save and exit.&lt;br&gt;
next move to the other config file:&lt;br&gt;
&lt;code&gt;$ sudo nano /etc/phpPgAdmin/config.inc.php&lt;/code&gt;&lt;br&gt;
find the line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$conf['servers'][0]['host'] = '';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;replace it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$conf['servers'][0]['host'] = 'localhost';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then find:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$conf['owned_only'] = false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;replace it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$conf['owned_only'] = true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;save and exit.&lt;br&gt;
that's it! now run these commands and you are ready to go!&lt;br&gt;
&lt;code&gt;$ sudo systemctl restart postgresql-12.service&lt;br&gt;
$ sudo systemctl reload httpd.service&lt;br&gt;
$ sudo systemctl restart httpd.service&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;by following all the steps above, you'll be able to run PostgreSQL on centos 7, and see your databases with PhpPgAdmin by visiting the following link: http://[your server ip]/phpPgAdmin/&lt;br&gt;
 good luck !&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>centos</category>
      <category>phppgadmin</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
