We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.


More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsCMS TutorialsDrupalDrupal Installation

How to Install Drupal with PostgreSQL

Cloud Servers 727 x 90

Drupal mostly uses MySQL database for storing various information including content, settings, etc. But it is also possible to use PostgreSQL with Drupal and it works pretty well.

Follow These Steps to Install Drupal with PostgreSQL

PostgreSQL is an advanced database management system. It is completely open source and supported by both Linux and Windows OS. Setting it up in Windows is very self-explanatory so on this tutorial we will explain how to set it up in Linux.

First, using an SSH client, check for any updates.

apt-get update

Once it is updated, download and install PostgreSQL by the following command:

apt-get install postgresql postgresql-contrib

Create a new user by first switching to the default user:

su – postgres

In order for PosgreSQL to create a user enter one of the following commands, depending on whether you wish to set up a password for the user or not:

createuser --pwprompt

Finish the setup by granting the newly created user the role of a superuser:

superuser prompt – y

Now you have PostgreSQL set up and you can move to installing Drupal.

If it is not already installed, go ahead and install it by downloading ithe package from Drupal website or use the built-in application installer like Softaculous or Installatron to install Drupal in a few clicks. Please note, by default application installers uses MySQL for creating databases. In this case, it is better just to download Drupal package from the internet and upload the files to the public_html directory. But it is also possible to adjust database settings even after installing Drupal with application installer.

After Drupal is uploaded to the public_html directory, you can start creating PostgreSQL database. For this reason, your hosting should be running PostgreSQL server. If you have direct access to PostgreSQL over SSH, we can use the following command to create the user and the database.

% createuser drupal_user --pwprompt --encrypted
Enter password for new user: 
Enter it again: 
Shall the new user be allowed to create databases? (y/n) n
Shall the new user be allowed to create more new users? (y/n) n
% createdb drupal_db --owner=drupal_user

In order to create database properly, it needs to have PostgreSQL structure. We can apply it by using “database.pgsql” file which is located in Drupal sub-folder named “database”. Simply run the following command in PostgreSQL environment.

psql -U drupal_user -f /home/username/domains/domain.com/public_html/database/database.pgsql

In case you don not have SSH access to the server, it is possible to create PostgreSQL database and user by using control panel like DirectAdmin or cPanel that provides PostgreSQL management interface.

Login to DirectAdmin control panel and click “PostgreSQL Management” under “Advanced Features”.

DirectAdmin PostgreSQL management

<>In the next page you will find options to create new user and database. New user can be created by clicking “Create Database User”.

Craate database user

It will show the form which needs to be filled with username and the password.

PostgreSQL username and password

To create new user, click “Save” button and it will be created in the server. Next step is to create the database. This can be done by clicking “Create Database”.

Create PostgreSQL database

Fill the form with database name and select the user which will be assigned to this database.

PostgreSQL database name

Finish creating new database by clicking “Save” button. That is it, you have created PostgreSQL database in DirectAdmin which is ready to be used with Drupal.

Login to cPanel account and scroll down the page to find “PostgreSQL Databases”.

cPanel PostgreSQL databases

Start creating new database by entering the database name and clicking “Create Database” button.

PostgreSQL database name

Then go to create new PostgreSQL user by entering its name and password under “Add New User”.

PostgreSQL username and password

Finally, add newly created user to the database. This can be done by clicking “Submit” button under “Add User To Database”.

Add user to database

Now that you have PostgreSQL database and username in place, it is time to set these details in Drupal configuration file. In most cases, it can be found in “sites/default/settings.php”. Open this file for editing and find a line that starts with “$db_url”. In this line we will need to specify PostgreSQL database details. In our case, it should look as follows.

$db_url = "pgsql://drupal_user:password@localhost/drupal_db";

Make sure to replace “password” with the actual password and Drupal should be working with database which is running in PostgreSQL.

Rate this Tutorial:
No Comments Leave a Comment
Leave a Comment

Cloud Servers 1 230×230

Other (195)

Popular Keywords

Cloud Servers 1 230×230