HOW TO DEPLOY THE LATEST APACHE 2.4.63 WITH PHP 8.4 AND POSTGRESQL DATABASE

If we’re talking about quick deployments XAMPP
is certainly a good thing,
but if we want to have complete manual control over things happening under
the hood for a more solid and comprehensive approach custom technology bundler is a not so good thing to do.
So, in this blip note i will tell you how to glue Apache, PHP and PostgreSQL technologies together.
Assuming that PHP 8.4 is installed to:
C:\PHP
and Apache 2.4.63 is installed to:
C:\Apache24
System and user variables are set in the global PATH.
Here is a valid PHP configuration file.
PHP.INI
; Extension setup
extension_dir="C:\php\ext"
extension=pgsql
extension=pdo_pgsql
extension=curl
extension=bz2
extension=fileinfo
extension=gettext
;extension=mysqli
;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
;extension=oci8_19
;extension=odbc
;extension=openssl
;extension=pdo_firebird
;extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_sqlite
[PostgreSQL]
; Allow or prevent persistent links.
; https://php.net/pgsql.allow-persistent
pgsql.allow_persistent=On
; Detect broken persistent links always with pg_pconnect().
; Auto reset feature requires a little overheads.
; https://php.net/pgsql.auto-reset-persistent
pgsql.auto_reset_persistent=Off
; Maximum number of persistent links. -1 means no limit.
; https://php.net/pgsql.max-persistent
pgsql.max_persistent=-1
; Maximum number of links (persistent+non persistent). -1 means no limit.
; https://php.net/pgsql.max-links
pgsql.max_links=-1
; Ignore PostgreSQL backends Notice message or not.
; Notice message logging require a little overheads.
; https://php.net/pgsql.ignore-notice
pgsql.ignore_notice=0
; Log PostgreSQL backends Notice message or not.
; Unless pgsql.ignore_notice=0, module cannot log notice message.
; https://php.net/pgsql.log-notice
pgsql.log_notice=0
; Loads of various settings
; Scripts execution time
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
; Error loggin'
log_errors = On
error_log = c:/php/php_errors.log
; Junk files
upload_max_filesize = 10M
post_max_size = 20M
file_uploads = On
; Buffering
output_buffering = 4096
; Timezone
date.timezone = Europe/Oslo
Also, here is a stripped down version of the Apache config file, that makes things work.
HTTPD.CONF
Define SRVROOT "c:/Apache24"
ServerRoot "${SRVROOT}"
Listen 80
LoadModule php_module "c:/php/php8apache2_4.dll"
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
PHPIniDir "c:/php"
DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
home.php home.pl home.cgi home.asp home.shtml home.html home.htm
</IfModule>
After saving php.ini and httpd.conf do not forget to restart Apache web-server.
Assuming that your Apache service called “Apache24”.
net stop Apache2.4 && net start Apache2.4
Our global aim is to make PDO database authorization method work.
If everything is OK you should see PDO support enabled and PDO drivers have to be set to pgsql.
At last, some useful PHP snippets that could be very helpful in troubleshooting process.
You can check status of PHP environment by means of following call.
Just put “info.php” file to the root folder of Apache [“htpdocs” by default]
<?php
phpinfo();
?>
Execute it from address line like:
http://localhost/info.php
To check available PDO methods execute this.
<?php
print_r(PDO::getAvailableDrivers());
?>
After all these numerous refinements you should be able to connect to PostgreSQL databases using PHP scripts without any problems.