Skip to main content

Connecting Laravel 12 to PostgreSQL in Arch Linux

· One min read
Fa'iz Maulana Habibi
College Student of Dian Nuswantoro University

Installing PostgreSQL

Install postgresql in your arch using

sudo pacman -S postgresql php-pgsql apache

# activate postgresql and apache systemd services
sudo systemctl enable {postgresql,httpd}
sudo systemctl start {postgresql,httpd}

# verify
sudo systemctl status {postgresql,httpd}

It will look like this

Systemd Services

Create User & Database in postgresql

Create User

sudo -iu postgres

Login PostgreSQL

After login to posgresql database, then create user

# create new user
createuser --bypassrls -s -l -d laravel

Create User

Create Database

createdb -O laravel laravel_db

Create DB

Set .env in Laravel

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432 # port postgresql
DB_DATABASE=laravel_db # database
DB_USERNAME=laravel # user
DB_PASSWORD=

then php artisan migrate:fresh. Done!