{"id":45065,"date":"2017-02-23T15:27:37","date_gmt":"2017-02-23T09:57:37","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=45065"},"modified":"2017-02-23T15:27:37","modified_gmt":"2017-02-23T09:57:37","slug":"how-to-set-up-phppgadmin-for-postgresql","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-set-up-phppgadmin-for-postgresql\/","title":{"rendered":"How to Set up PhpPgAdmin for PostgreSQL?"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter  wp-image-46258\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/posgresql-and-phppgadmin-in-ubuntu-server-13.10.png\" alt=\"posgresql-and-phppgadmin-in-ubuntu-server-13.10\" width=\"454\" height=\"341\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/posgresql-and-phppgadmin-in-ubuntu-server-13.10.png 800w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/posgresql-and-phppgadmin-in-ubuntu-server-13.10-300x225.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/posgresql-and-phppgadmin-in-ubuntu-server-13.10-624x468.png 624w\" sizes=\"(max-width: 454px) 100vw, 454px\" \/><\/p>\n<p><span class=\"st\">PostgreSQL is a powerful, open source object-relational database system (ORDBMS). The version 8.0 and above also comes with the native Windows compatibility.<br \/>\nCompared to other RDBMSs, <a title=\"Connect to PostgreSQL using JavaScript\" href=\"http:\/\/www.tothenew.com\/blog\/connect-to-postgresql-using-javascript\/\">PostgreSQL<\/a>\u00a0differs itself with its object-oriented and\/or relational database functionality, such as the complete support for reliable transactions, i.e. Atomicity, Consistency, Isolation, Durability (ACID).<br \/>\n<\/span><\/p>\n<p>What happens if we want to manage the PostgreSQL databases from a graphical interface and not the command line?<br \/>\nWe can use phpPgAdmin which is a is a web-based administration tool for PostgreSQL. PhpPgAdmin is an administration interface for PostgreSQL written in PHP. With PhpPgAdmin, we can administer a remote PostgreSQL Server.<\/p>\n<p>Now let&#8217;s go step by step<strong>\u00a0<\/strong>with PostgreSQL + phpPgAdmin running with Nginx on an Ubuntu 14.04 server. PhpPgAdmin can use Apache2 and Php5.<\/p>\n<p>Steps to follow:<\/p>\n<p><strong>Step 1: Installing PhpPgAdmin <\/strong><br \/>\nInstall PhpPgAdmin using the below commands:<\/p>\n<p>[js]<br \/>\nsudo apt-get update<br \/>\nsudo apt-get install postgresql postgresql-contrib phppgadmin php5-fpm<br \/>\n[\/js]<\/p>\n<p>By default, the installation process configures the Apache2 server.<\/p>\n<p><strong>Step 2: Setting up PostgreSQL-9.6.1<\/strong><br \/>\nInstalling PostgreSQL on our Ubuntu 14.04 machine<\/p>\n<p>[js]<br \/>\nsudo sh -c &#8216;echo &quot;deb http:\/\/apt.postgresql.org\/pub\/repos\/apt\/ $(lsb_release -cs)-pgdg main&quot; &gt; \/etc\/apt\/sources.list.d\/pgdg.list&#8217;<br \/>\nwget &#8211;quiet -O &#8211; https:\/\/www.postgresql.org\/media\/keys\/ACCC4CF8.asc | sudo apt-key add &#8211;<br \/>\nsudo apt-get update<br \/>\nsudo apt-get install postgresql-9.6<br \/>\n[\/js]<\/p>\n<p><strong>Step 3: Configuring a Read Only user\/role for PostgreSQL<\/strong><br \/>\nCreating a read only user\/role on PostgreSQL for a particular database<\/p>\n<p>[js]<br \/>\nCREATE ROLE &lt;postgres_user&gt; WITH LOGIN PASSWORD &#8216;&lt;password&gt;&#8217; NOSUPERUSER INHERIT NOCREATEDB NOREPLICATION NOCREATEROLE  VALID UNTIL &#8216;infinity&#8217;;<br \/>\nGRANT CONNECT ON DATABASE &lt;database_name&gt; TO &lt;postgres_user&gt;;<br \/>\nGRANT USAGE ON SCHEMA public TO &lt;postgres_user&gt;;<br \/>\nGRANT SELECT ON ALL TABLES IN SCHEMA public TO &lt;postgres_user&gt;;<br \/>\nGRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO &lt;postgres_user&gt;;<br \/>\nALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO &lt;postgres_user&gt;;<br \/>\n[\/js]<\/p>\n<p><strong>Step 4: Configuring Apache<\/strong><br \/>\nNow, editing the following lines in the file <em>\/etc\/apache2\/sites-enabled\/000-default.conf<\/em><\/p>\n<p>[js]<br \/>\nServerAdmin localhost<br \/>\nDocumentRoot \/usr\/share\/phppgadmin\/index.php<br \/>\nServerName localhost<br \/>\n[\/js]<\/p>\n<p>Adding the below line in the file <em> \/etc\/apache2\/apache2.conf :<\/em><br \/>\n<em>Include \/etc\/apache2\/conf.d\/phppgadmin<\/em><\/p>\n<p>Inside<strong> \/etc\/apache2\/conf.d\/phppgadmin<\/strong> file, it must contain<\/p>\n<p>[js]<br \/>\norder deny,allow<br \/>\ndeny from all<br \/>\nallow from 127.0.0.0\/255.0.0.0 ::1\/128<br \/>\nallow from all<br \/>\n[\/js]<\/p>\n<p>Now, Restarting our Apache Web Server<\/p>\n<p>[js]sudo service apache2 restart[\/js]<\/p>\n<p><strong>Step 5: Tweaking some parameters for PhpPgAdmin <\/strong><\/p>\n<p>Editing the below line in the file\/etc\/apache2\/sites-enabled\/000-default.conf :<br \/>\n<em>conf[\u2018extra_login_security\u2019] = true;<br \/>\n<\/em><em>to<br \/>\n<\/em><em><strong>$conf[\u2018extra_login_security\u2019] = false;<\/strong><\/em><\/p>\n<p><strong>Step6: Getting started with our PhpPgAdmin GUI for PostgreSQL<\/strong><br \/>\nBrowse on web browser <strong>http:\/\/localhost:8080\/phppgadmin<\/strong> <img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-46255\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/Screenshot-from-2017-02-20-001848.png\" alt=\"Screenshot from 2017-02-20 00:18:48\" width=\"454\" height=\"344\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/Screenshot-from-2017-02-20-001848.png 734w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/Screenshot-from-2017-02-20-001848-300x227.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/Screenshot-from-2017-02-20-001848-624x473.png 624w\" sizes=\"(max-width: 454px) 100vw, 454px\" \/><\/p>\n<p><strong>Step7: Adding New Remote PostgreSQL Server (Optional)<\/strong><br \/>\nNow, If we want to add a new server to our PhpPgAdmin then it can be done by adding the below line to the file <em>\/etc\/phppgadmin\/<\/em><span class=\"skimlinks-unlinked\"><span class=\"skimlinks-unlinked\"><em>config.inc. file:<\/em><\/span><\/span><\/p>\n<p>[js]<br \/>\n$conf[&#8216;servers&#8217;][1][&#8216;desc&#8217;] = &#8216;New_Postgres_Server&#8217;;<br \/>\n$conf[&#8216;servers&#8217;][1][&#8216;host&#8217;] = &#8216;&lt;ip-address\/hostname&gt;&#8217;;<br \/>\n$conf[&#8216;servers&#8217;][1][&#8216;port&#8217;] = 5432;<br \/>\n\/\/$conf[&#8216;servers&#8217;][1][&#8216;sslmode&#8217;] = &#8216;allow&#8217;;<br \/>\n$conf[&#8216;servers&#8217;][1][&#8216;pg_dump_path&#8217;] = &#8216;\/usr\/bin\/pg_dump&#8217;;<br \/>\n$conf[&#8216;servers&#8217;][1][&#8216;defaultdb&#8217;] = &#8216;template1&#8217;;<br \/>\n$conf[&#8216;servers&#8217;][1][&#8216;pg_dumpall_path&#8217;] = &#8216;\/usr\/bin\/pg_dumpall&#8217;;<br \/>\n[\/js]<\/p>\n<p>Now, we can log in using the PostgreSQL user we created in Step 3 into the PhpPgAdmin.<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-46257\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/phppgadmin-login.png\" alt=\"phppgadmin-login\" width=\"572\" height=\"260\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/02\/phppgadmin-login.png 572w, \/blog\/wp-ttn-blog\/uploads\/2017\/02\/phppgadmin-login-300x136.png 300w\" sizes=\"(max-width: 572px) 100vw, 572px\" \/><\/p>\n<p>You can now easily set up PhpPgAdmin for PostgreSQL.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL is a powerful, open source object-relational database system (ORDBMS). The version 8.0 and above also comes with the native Windows compatibility. Compared to other RDBMSs, PostgreSQL\u00a0differs itself with its object-oriented and\/or relational database functionality, such as the complete support for reliable transactions, i.e. Atomicity, Consistency, Isolation, Durability (ACID). What happens if we want to [&hellip;]<\/p>\n","protected":false},"author":919,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":49},"categories":[2348,1],"tags":[4843,1892,4436,942],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/45065"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/919"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=45065"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/45065\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=45065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=45065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=45065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}