How to Install PHPPgAdmin on Ubuntu 16.04

Just like we have PHPMyAdmin for MySQL administration on the web, we have PHPPgAdmin for PostgreSQL administration on the web. Using PHPPgAdmin, you can manage roles and databases on your PostgreSQL server. In this tutorial, I will demonstrate how you can install PHPPgAdmin on Ubuntu 16.04 server.

It is very easy to set up and configure PHPPgAdmin on Ubuntu 16.04 server. However, There are some steps you have to perform on your own, Like installing PostgreSQL on your server.

If you have a Ubuntu 16.04 server ready with PostgreSQL installed, we can get started with the tutorial. So, PHPPgAdmin is on the web, which means, we have to install a web server to access the graphical user interface provided by PHPPgAdmin. In this tutorial, we will install the Apache web server for this purpose. And we also have to install PHP because PHPPgAdmin depends on PHP too!

So, let’s get started with the tutorial.

Install PHPPgAdmin on Ubuntu 16.04

The first thing we have to do is to install Apache on the server. I assume that you have PostgreSQL already installed on your server. Execute the following command to install Apache on your server.

sudo apt-get install apache2 -y

It will take few seconds to install. The -y flag in this command is used to auto-accept the installation. Once the Apache is installed, verify if it is working by accessing the Public IP address of your server in the browser.

http://SERVER_IP

You should see the default Apache page with some information about the directory structure of apache. Once done, we can move on to set up PHPPgAdmin on our server. Execute the following command to install the PHPPgAdmin package on your server.

sudo apt-get install phppgadmin -y

Yes, we also have to install PHP and the PHP extensions that PHPPgAdmin needs, but we don’t have to explicitly define the PHP and PHP extensions in the installation command because those packages will be automatically added to the list of packages to install.

It will take some time to complete the installation as it will set up PHP, Other PHP extensions required by PHPPgAdmin and also the PHPPgAdmin itself.

Once the execution is complete, you can move on to the mandatory configuration part.

Configure PHPPgAdmin on Ubuntu 16.04

Right now, you cannot access PHPPgAdmin on the browser. It is because the Apache configuration will not allow access from the remote IP addresses. To access PHPPgAdmin from non-local IP addresses, we have to edit the Apache configuration file for PHPPgAdmin.

Execute the following command to open the configuration file in edit mode.

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

Now, find a line containing Require local in the configuration file and replace it with Allow from all. You can also comment out the default configuration and add the new configuration on next line, just like this.

#Require local
Allow from all

Once done, press CTRL+X followed by Y followed by the Enter key to save the configuration file. Our configuration is saved but it is not applied right now. To apply our updated configuration, we have to restart the Apache service. Execute the following command to restart the Apache service on your server.

sudo service apache2 restart

Now, you can access PHPPgAdmin on the following URL in your browser.

http://SERVER_IP/phppgadmin

Do not forget to replace the IP address of the server in the URL. If you can see a page just like the following image, Congratulations!

Install PHPPgAdmin

If you cannot see this screen, I recommend you to follow the steps again. And if you are getting any error message, Please re-check your configuration and try again.

There is one more thing we can do to make our installation a little bit more secure. You see, right now, our PHPPgAdmin is installed on the default URL. We can actually change the URL by updating a single line in the Apache configuration file.

Change default PHPPgAdmin URL

This step is not necessary, but I highly recommend you to change the default URL so that bots and some bad people cannot execute attacks like brute force on our PHPPgAdmin installation.

To update the default URL, we have to update Alias in the same configuration file we updated in the previous step. Execute the following command to open the PHPPgAdmin Apache configuration in edit mode.

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

We have to update the first line of this configuration file which is an Alias directive. By default, it should look like this.

Alias /phppgadmin /usr/share/phppgadmin

Now, Let’s say we want to access our PHPPgAdmin installation on mypgadmin instead of the default URL. In that case, We will just replace /phppgadmin with /mypgadmin and we are good to go. The updated line should look like this.

Alias /mypgadmin /usr/share/phppgadmin

Once you have edited the file, press CTRL+X followed by Y followed by the Enter key to save the file. Again, we will restart our Apache web server to apply changes.

sudo service apache2 restart

Now you can access the PHPPgAdmin on the updated URL. So, this is how you can install and configure PHPPgAdmin on Ubuntu 16.04 server. Please let us know if you are facing any issue with the installation, we are happy to help!

Leave a Reply