Install Nginx+PHP+PostgreSQL on Ubuntu 18.04


Today, We’re going to learn how to install & use Nginx+PHP with PostgreSQL.

This tutorial was requested by @iamHappy

Step 0

Read the Already existing LEMP tutorial

Step 1

Follow the Above Tutorial to install and Configure Nginx, PHP except for the following:
Instead of installing the php-mysql package, Install php-pgsql

apt install php-fpm php-pgsql 

Step 2

Install PostgreSQL and PostgreSQL-Contrib Packages:

apt install postgresql postgresql-contrib

Now Log in to Postgresql interactive psql console as postgres user

sudo -u postgres psql postgres

:bulb: In Postgresql, Postgres is the default superuser with no password set so it’s probably a good idea to set one.

Here you can set the Root (Postgres) password

    postgres=# \password postgres
    Enter new password: [Enter a Password]
    Enter it again: [Enter a Password]
    postgres=# \quit

Now you can enter psql to create a database and user for your application.

    sudo -u postgres psql postgres
    postgres=# CREATE USER "myNewUser" WITH PASSWORD 'myPassword';  
    postgres=# CREATE DATABASE appDB WITH OWNER "myNewUser";                         
    postgres=# GRANT ALL PRIVILEGES ON DATABASE ttrss to "myNewUser";                
    postgres=# \quit

As always, if You have any Questions, make sure to ask them below.