Bobcares

Install pgadmin4 ubuntu digitalocean | Guide

by | Aug 12, 2022

Install pgadmin4 ubuntu digitalocean and configure OS Ubuntu 18.04 server with this simple step-by-step article. We Bobcares, as a part of our Digital Ocean Services, respond to all inquiries in detail.

An introduction to Install pgadmin4 ubuntu digitalocean

pgAdmin4 is the most popular and feature-rich Open Source administration development platform for PostgreSQL and its related database management systems. The languages written for this application are Python and jQuery, it also supports all the features found in PostgreSQL.

You can use this application for basic SQL queries, Database monitoring, and as well to configure advanced database architectures. Further, we will have a deeper look into the process of pgAdmin 4 ubuntu Installation work.

Requirements:

To complete this pgAdmin4 configuration setup

  • You will need a server with OS Ubuntu 18.04.
  • Apache web server.
  • Installed Python 3 and venv.

Install the PostgreSQL application on your server and create a new role and Database, as you will need to connect pgAdmin to the PostgreSQL instance.

Step1: Installing pgAdmin4

In this step, we will go through the installation within the virtual environment and its dependencies.

To begin with, update your server’s package index with the “sudo apt update” command, you can install the dependencies that mainly support libgmp3-dev, libpq-dev, and libapache2-mod-wsgi-py3. along with the Apache service hosting the Python-based web applications, you can update this with the following command:

sudo apt install libgmp3-dev libpq-dev libapache2-mod-wsgi-py3

Additionally create a few directories where pgAdmin will store its sessions, storage details, and logs:

mkdir -p /var/lib/pgadmin4/sessions
mkdir /var/lib/pgadmin4/storage
 mkdir /var/log/pgadmin4

Further, change the ownership of the created directories to your user and group so they can be accessed on the web:

sudo chown -R user:user /var/lib/pgadmin4
sudo chown -R user:user /var/log/pgadmin4

Next, Access the virtual environment then Navigate to the directory to activate the” my_env ” environment:

cd environments/
source my_env/bin/activate

Make sure to upgrade pip to the latest version, you can run the following command to update:

python -m pip install -U pip

Once the virtual environment is activated, download the pgAdmin4 source code onto your machine. You can simply run the given wget command in your terminal:

wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v5.1/pip/pgadmin4-5.1-py3-none-any.whl

Install the wheel package, this package is used as an extension tool for working with .whl files:

python -m pip install wheel

Finally, install the pgAdmin4 package with the following command:

python -m pip install pgadmin4-5.1-py3-none-any.whl

The installation and its dependencies part have been completed now.

Step 2 —  pgAdmin 4 Configuration

We will have a look at the configuration part now. The pgAdmin has been installed on the server. However, we need to ensure that permissions and configurations correctly serve the web interface.

pgAdmin’s main configuration file is config.py and is been read before any other configuration file. We will add a few configuration changes to a new file, named config_local.py

You will have to create a new file config_local.py

vi my_env/lib/python3.6/site-packages/pgadmin4/config_local.py

now, add the below content and save the file.

LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
STORAGE_DIR = '/var/lib/pgadmin4/storage'
SERVER_MODE = True

Each of these file paths points to the directories that were created in the first step.With the help of these configurations run the pgAdmin setup script to set your login credentials:

python my_env/lib/python3.6/site-packages/pgadmin4/setup.py

After successfully executing the command, you will get a prompt asking for your logins i.e “email address” and “password”. These will be your login credentials for the pgAdmin Application.
Enter your credentials to use for the initial pgAdmin user account.

The final step in the configuration part is to update the permissions on the following directories to give www-data ownership over both of them:

sudo chown -R www-data:www-data /var/lib/pgadmin4/
sudo chown -R www-data:www-data /var/log/pgadmin4/

Now the pgAdmin is configured. However, the program isn’t yet being accessed from the server, so it still remains unusable. To further resolve this, we need to configure Apache to serve pgAdmin so that you can have access to the user interface via a web browser.

Step 3 — Configuring Apache

To begin with Apache configuration you need to access the root directory ” cd / ” and then create a new file in your /sites-available/ with a new directory that will be the virtual host file.

sudo nano /etc/apache2/sites-available/pgadmin4.conf

Add the following content to pgadmin4.conf and save the virtual host file.

/etc/apache2/sites-ava bgilable/pgadmin4.conf
<VirtualHost *>
ServerName your_server_ip
WSGIDaemonProcess pgadmin processes=1 threads=25 python-home=/home/sammy/environments/my_env
WSGIScriptAlias / /home/user/environments/my_env/lib/python3.6/site-packages/pgadmin4/pgAdmin4.wsgi
<Directory "/home/user/environments/my_env/lib/python3.6/site-packages/pgadmin4/">
WSGIProcessGroup pgadmin
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
</VirtualHost>

Later use the a2ensite script to enable pgadmin4.conf virtual host file. This helps to create a symbolic link between the virtual host file /sites-available/ directory and /sites-enabled/ directory:

sudo a2ensite pgadmin4.conf

Now run an apache configuration checks

apache2ctl -t

If your configuration check is good to go, then you will get an output as Syntax OK. Now restart the Apache service

sudo systemctl restart apache2

pgAdmin is now successfully installed and configured. Next, we will move on to the pgAdmin accessing part.

Step 4 —  pgAdmin Access

To access the application from any web browser, just navigate to your server’s IP address:

http://your_server_ip

The Login screen will be displayed as shown in the image:

pgAdmin 4 ubuntu digitalocean installation

Enter the login credentials that were created earlier in the pgAdmin Configuration section and you’ll be taken to the pgAdmin Welcome Screen:

pgAdmin 4 ubuntu digitalocean installation

Once you logged into the application all that’s left to do is to connect pgAdmin to your PostgreSQL database.

Step 5 — Configuring PostgreSQL User

Locate the Browser menu from the pgAdmin application dashboard. Menu >> create >>click on Server…

Now, you need to update your server info, role, and database details.

In the General tab, enter the Server name and Server group as Servers.

Next, click on to Connection tab.

  • Host name/address: localhost.
  • Port: 5432

In the Maintenance field, click on the created database to connect and then enter the PostgreSQL Logins you configured earlier, once the credentials are authenticated the database will be shown under Servers in the Browser menu.

Therefore the PostgreSQL database is successfully connected.

Step 6 — Table creation in the pgAdmin Dashboard

The final step is to create a Table for the Database, you need to locate the Browser menu on the left-hand side of the window.

Click on the plus sign to expand the servers option and then. Next, click the plus sign to expand the server/hostname that you have given earlier.

Now go to Databases >> Right-click the Tables list item>> Create and click Table….

This will pop up a Create-Table window. Enter a new name for the table.

Navigate to the Columns tab to add some columns. While updating a column, add a Name and Data type. Save the created table.

Adding a primary key to a table is usually a best practice. The primary key is a constraint that indicates a specific column or set of columns in the table.

At this stage, you have created a table with a couple of columns. However, the created table does not contain any data. We can now add data to the table by clicking on the Browser menu >> Scripts >> INSERT Script.

To get an idea for INSERT statement data, can follow the below script as an example:

INSERT INTO public."tablename"(
col1, col2, col3)
VALUES ('ABC', 73, 947), ('XYZ', 20, 4820), ('PQR', 31, 142);

To execute the INSERT statement click on the triangle icon (▶)

If you want to view the table and all the data that have been added, simply just right-click the name of your table in the Browser menu once again >> View/Edit Data, and select All Rows.

You can view all the data held within that table in the lower panel’s Data Output tab

By this, you have successfully created a table and filled it with some data through the pgAdmin web interface.

Conclusion

To conclude this is one of the simple methods to Install pgadmin4 ubuntu digitalocean from a Python virtual environment, serving to the web with Apache and connecting it to a PostgreSQL database.

PREVENT YOUR SERVER FROM CRASHING!

Never again
lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server
24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.