PHP, Software Development

PHP 7.4 – Enable PostgreSQL Driver

PHP

This post shows how to configure PHP 7.4 (or PHP 7.x, in general) php.ini to enable the PostgreSQL driver, which comes in handy when I need to work on a new version of PHP after a very long break (like months).

Why The Need To New PHP Version?

I am developing this application on Windows using PHP 7.2, Laravel 7, Angular 8, and PostgreSQL in my spare time. Recently, I have not spent much time on the project because of work. As a result, the codes and settings have become outdated due to Angular 10 and with the upcoming Laravel 8. I need to upgrade the codes, at least to the latest framework versions. Also, I keep on forgetting how to configure PHP to enable the PostgreSQL driver.

Download Latest PHP 7.x zip Distribution

I am not using a LAMP or XAMP. Instead, I use a zip distribution of PHP 7.x. To download the zip distribution, head to https://windows.php.net/download/ and click the zip link either for Non-Thread Safe or Thread Safe (recommended) distribution. See PHP FAQs.

Then, extract the zip file to some local folder. Next, create a copy of php.ini-development  and rename it to php.ini.

Modify PHP 7.4 php.ini To Enable PostgreSQL Driver

One we have the php.ini file, we need to modify it. Uncomment the following lines.

At this point, we have enabled the PostgreSQL driver in PHP 7.4. We can now test the database connectivity with Laravel, e.g., running artisan migrate. Assuming we have a PostgreSQL database running locally, we will get the following error without those changes in php.ini.

Before Running PHP 7.4, Configure PATH

Before we can run any PHP codes from the command-line window, we have to configure the environment variable PATH. We can set it up in the command-line window before running any PHP codes. Consider the following sample command.

I am using C:\Users\karldev\Desktop\dev\apps\php-7.4.10-Win32-vc15-x64 for this post.

You Might Also Like