Debug School

rakesh kumar
rakesh kumar

Posted on

How to Configure Apache Virtual Host with PostgreSQL in Laravel: Complete XAMPP Setup Guide

Step 1: Install PostgreSQL

First, install PostgreSQL on your system.

During installation, remember these details:


PostgreSQL Port: 5432
Username: postgres
Password: your_postgres_password
Enter fullscreen mode Exit fullscreen mode

Default PostgreSQL port is:


5432
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Search:

;extension=pgsql
Enter fullscreen mode Exit fullscreen mode

and:

;extension=pdo_pgsql
Enter fullscreen mode Exit fullscreen mode

By default, these lines may be disabled like this:

;extension=pgsql
;extension=pdo_pgsql
Enter fullscreen mode Exit fullscreen mode

The semicolon ; means the extension is disabled.

Now remove the semicolon.

Change this:

;extension=pgsql
;extension=pdo_pgsql
Enter fullscreen mode Exit fullscreen mode

To this:

extension=pgsql
extension=pdo_pgsql
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

If it is like this:

;extension_dir="ext"
Enter fullscreen mode Exit fullscreen mode

or disabled, you can set it properly:

extension_dir="C:\xampp\php\ext"
Enter fullscreen mode Exit fullscreen mode

Step 7: Confirm PostgreSQL DLL Files Exist

Now go to this folder:


C:\xampp\php\ext
Enter fullscreen mode Exit fullscreen mode

Check that these files are available:

php_pgsql.dll
php_pdo_pgsql.dll
Enter fullscreen mode Exit fullscreen mode

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();
Enter fullscreen mode Exit fullscreen mode

Now open browser:

http://localhost/phpinfo.php

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

For example:

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=holidaylandmark_db
DB_USERNAME=postgres
DB_PASSWORD=admin123
Enter fullscreen mode Exit fullscreen mode

Step 12: Configure Apache Virtual Host

Now configure Virtual Host.

Open this file:

C:\xampp\apache\conf\extra\httpd-vhosts.conf
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Correct:


DocumentRoot "C:/xampp/htdocs/holidaylandmark/public"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Save the file.

Step 15: Restart Apache Again

Open XAMPP Control Panel:

Stop Apache
Start Apache

Now open browser:

http://holidaylandmark.local

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

Enter fullscreen mode Exit fullscreen mode

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:

http://holidaylandmark.local

Check these things:

  1. hosts file has correct domain
  2. httpd-vhosts.conf has correct ServerName
  3. DocumentRoot path is correct
  4. Apache was restarted
  5. 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>
Enter fullscreen mode Exit fullscreen mode


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
Enter fullscreen mode Exit fullscreen mode


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)