Step 1: Install PostgreSQL
First, install PostgreSQL on your system.
During installation, remember these details:
PostgreSQL Port: 5432
Username: postgres
Password: your_postgres_password
Default PostgreSQL port is:
5432
After installation, open pgAdmin and make sure PostgreSQL server is running.
Step 2: Create PostgreSQL Database
Open pgAdmin.
Then follow these steps:
Servers
→ PostgreSQL
→ Databases
→ Right click
→ Create
→ Database
Create database:
holidaylandmark_db
Or you can create database using SQL:
CREATE DATABASE holidaylandmark_db;
Step 3: Find Correct XAMPP PHP.ini File
Now we need to enable PostgreSQL extensions in XAMPP PHP.
Open CMD or PowerShell and run:
C:\xampp\php\php.exe --ini
You will see output like:
Configuration File (php.ini) Path: C:\xampp\php
Loaded Configuration File: C:\xampp\php\php.ini
This confirms the correct php.ini file location.
Your file is usually here:
C:\xampp\php\php.ini
Step 4: Open php.ini File
Open this file in Notepad or VS Code:
C:\xampp\php\php.ini
You can also open using command:
notepad C:\xampp\php\php.ini
Step 5: Enable PostgreSQL Extensions in php.ini
Inside php.ini, press:
Ctrl + F
Search:
;extension=pgsql
and:
;extension=pdo_pgsql
By default, these lines may be disabled like this:
;extension=pgsql
;extension=pdo_pgsql
The semicolon ; means the extension is disabled.
Now remove the semicolon.
Change this:
;extension=pgsql
;extension=pdo_pgsql
To this:
extension=pgsql
extension=pdo_pgsql
Step 6: Check PHP Extension Directory
In the same php.ini file, search:
extension_dir
For XAMPP, it should usually be:
extension_dir="C:\xampp\php\ext"
If it is like this:
;extension_dir="ext"
or disabled, you can set it properly:
extension_dir="C:\xampp\php\ext"
Step 7: Confirm PostgreSQL DLL Files Exist
Now go to this folder:
C:\xampp\php\ext
Check that these files are available:
php_pgsql.dll
php_pdo_pgsql.dll
If both files exist, your XAMPP PHP supports PostgreSQL.
If these files are missing, you may need to install a proper XAMPP version that includes PostgreSQL extensions.
Step 8: Restart Apache
After changing php.ini, restart Apache.
Open XAMPP Control Panel:
Stop Apache
Start Apache
This step is mandatory because PHP extensions load only after Apache restart.
Step 9: Verify PostgreSQL Extension in Browser
Create one test file:
C:\xampp\htdocs\phpinfo.php
Add this code:
<?php
phpinfo();
Now open browser:
Search on the page:
pgsql
and:
pdo_pgsql
If both are showing, PostgreSQL is successfully enabled in XAMPP PHP.
Step 10: Verify PostgreSQL Extension from Command Line
Run this command:
C:\xampp\php\php.exe -m
You should see:
pgsql
pdo_pgsql
You can also check directly:
C:\xampp\php\php.exe -m | findstr pgsql
Expected output:
pdo_pgsql
pgsql
Step 11: Configure Laravel .env for PostgreSQL
Now open your Laravel project .env file.
Example path:
C:\xampp\htdocs\holidaylandmark.env
Update database configuration:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=holidaylandmark_db
DB_USERNAME=postgres
DB_PASSWORD=your_postgres_password
For example:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=holidaylandmark_db
DB_USERNAME=postgres
DB_PASSWORD=admin123
Step 12: Configure Apache Virtual Host
Now configure Virtual Host.
Open this file:
C:\xampp\apache\conf\extra\httpd-vhosts.conf
Add this code:
<VirtualHost *:80>
ServerName holidaylandmark.local
DocumentRoot "C:/xampp/htdocs/holidaylandmark/public"
<Directory "C:/xampp/htdocs/holidaylandmark/public">
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/holidaylandmark-error.log"
CustomLog "logs/holidaylandmark-access.log" common
</VirtualHost>
For normal PHP project without Laravel, use your project folder directly:
<VirtualHost *:80>
ServerName myphpapp.local
DocumentRoot "C:/xampp/htdocs/myphpapp"
<Directory "C:/xampp/htdocs/myphpapp">
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/myphpapp-error.log"
CustomLog "logs/myphpapp-access.log" common
</VirtualHost>
For Laravel, always point DocumentRoot to the public folder:
C:/xampp/htdocs/holidaylandmark/public
Do not point Laravel Virtual Host to the project root folder.
Wrong:
DocumentRoot "C:/xampp/htdocs/holidaylandmark"
Correct:
DocumentRoot "C:/xampp/htdocs/holidaylandmark/public"
Step 13: Enable Virtual Host File in Apache
Open Apache main config file:
C:\xampp\apache\conf\httpd.conf
Search:
Include conf/extra/httpd-vhosts.conf
If it has #, remove it.
Change this:
Include conf/extra/httpd-vhosts.conf
To this:
Include conf/extra/httpd-vhosts.conf
Save the file.
Step 14: Add Local Domain in Windows Hosts File
Now open Windows hosts file as Administrator.
File path:
C:\Windows\System32\drivers\etc\hosts
Add this line:
127.0.0.1 holidaylandmark.local
If you are using another local domain, add like this:
127.0.0.1 myphpapp.local
127.0.0.1 holidaylandmark.local
Save the file.
Step 15: Restart Apache Again
Open XAMPP Control Panel:
Stop Apache
Start Apache
Now open browser:
Your Laravel project should open using the custom local domain.
Step 16: Clear Laravel Cache
Go to your Laravel project:
cd C:\xampp\htdocs\holidaylandmark
Run:
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
Then run:
php artisan migrate
If everything is correct, Laravel will create tables in PostgreSQL database.
Step 17: Test PostgreSQL Connection in Laravel
You can test database connection using Laravel Tinker:
php artisan tinker
Then run:
DB::connection()->getPdo();
If no error appears, PostgreSQL connection is working.
You can also check current database name:
DB::connection()->getDatabaseName();
Expected output:
holidaylandmark_db
Step 18: Common Error: could not find driver
Error:
could not find driver
Reason:
PostgreSQL PHP extension is not enabled.
Solution:
Check php.ini again:
extension=pgsql
extension=pdo_pgsql
Then restart Apache.
Also check:
C:\xampp\php\php.exe -m | findstr pgsql
Step 19: Common Error: password authentication failed
Error:
password authentication failed for user "postgres"
Reason:
Wrong PostgreSQL username or password in .env file.
Solution:
Update .env:
DB_USERNAME=postgres
DB_PASSWORD=correct_password
Then run:
php artisan config:clear
Step 20: Common Error: database does not exist
Error:
database "holidaylandmark_db" does not exist
Reason:
Database is not created in PostgreSQL.
Solution:
Create database in pgAdmin or run:
CREATE DATABASE holidaylandmark_db;
Step 21: Common Error: Virtual Host Not Opening
If this URL does not open:
Check these things:
- hosts file has correct domain
- httpd-vhosts.conf has correct ServerName
- DocumentRoot path is correct
- Apache was restarted
- httpd-vhosts.conf is included in httpd.conf
Correct hosts file:
127.0.0.1 holidaylandmark.local
Correct Virtual Host:
ServerName holidaylandmark.local
DocumentRoot "C:/xampp/htdocs/holidaylandmark/public"
<Directory "C:/xampp/htdocs/holidaylandmark/public">
AllowOverride All
Require all granted
</Directory>
Step 22: Complete Final Setup Flow
Your final local development flow should look like this:
Browser
↓
http://holidaylandmark.local
↓
Apache Virtual Host
↓
C:/xampp/htdocs/holidaylandmark/public
↓
Laravel Application
↓
.env file
↓
PostgreSQL database
Complete Laravel .env Example
APP_NAME=HolidayLandmark
APP_ENV=local
APP_KEY=base64:your_app_key
APP_DEBUG=true
APP_URL=http://holidaylandmark.local
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=holidaylandmark_db
DB_USERNAME=postgres
DB_PASSWORD=your_postgres_password
Complete Apache Virtual Host Example
ServerName holidaylandmark.local
ServerAlias www.holidaylandmark.local
DocumentRoot "C:/xampp/htdocs/holidaylandmark/public"
<Directory "C:/xampp/htdocs/holidaylandmark/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/holidaylandmark-error.log"
CustomLog "logs/holidaylandmark-access.log" common
Complete php.ini PostgreSQL Settings
Your php.ini should contain:
extension_dir="C:\xampp\php\ext"
extension=pgsql
extension=pdo_pgsql
Final Commands
Run these commands after setup:
cd C:\xampp\htdocs\holidaylandmark
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan migrate
php artisan serve
Top comments (0)