I receive this error after trying to set up LAMP by following this tutorial, and I find myself receiving the above error after trying to set up phpmyadmin.
Fatal error: Call to undefined function mb_detect_encoding() in
C:\WebServer\Apache\htdocs\phpmyadmin\libraries\php-gettext\gettext.inc
on line 177
I followed the advice over here: PHP Fatal error when trying to access phpmyadmin mb_detect_encoding, and made those changes.
When I run phpinfo(), I see that support for MySQL and mb_string are enabled as shown below:
Install the gd library also.
check this link
http://www.php.net/manual/en/mbstring.installation.php
There's a much easier way than recompiling PHP. Just yum install the required mbstring library:
Example: How to install PHP mbstring on CentOS 6.2
yum --enablerepo=remi install php-mbstring
Oh, and don't forget to restart apache afterward.
Mbstring is a non-default extension. This means it is not enabled by default. You must explicitly enable the module with the configure option.
In case your php version is 7.2:
sudo apt-get install php7.2-mbstring
sudo service apache2 restart
In case your php version is 7.0:
sudo apt-get install php7.0-mbstring
sudo service apache2 restart
In case your php version is 5.6:
sudo apt-get install php5.6-mbstring
sudo service apache2 restart
On Windows open the file php.ini and make this changes:
Remove the comment and point to the ext directory
; extension_dir = "./" -> extension_dir = "C:/Php/ext"
Remove the comment of this extensions
extension=php_mbstring.dll
extension=php_mysqli.dll
Restart apache service
httpd -k restart
When I opened my php.ini file, "extension_dir" line looked like following :
extension_dir = "C:/wamp/bin/php/php5.4.16/ext/"
which i changed to:
extension_dir = "C:\wamp\bin\php\php5.4.16\ext\"
and it worked.
Under Windows / WAMP there doesn't seem to be any php_mbstring.dll dependencies on the GD2 extension, the MySQL extensions, nor on external dlls/libs:
deplister.exe ext\php_mbstring.dll
php5ts.dll,OK
MSVCR110.dll,OK
KERNEL32.dll,OK
deplister.exe ext\php_gd2.dll
php5ts.dll,OK
USER32.dll,OK
GDI32.dll,OK
KERNEL32.dll,OK
MSVCR110.dll,OK
Whatever php_mbstring already needs, it's built-in (statically compiled right into the DLL).
Call to undefined function mb_detect_encoding()
This error is also very specific and deterministic...
The function mb_detect_encoding() didn't fail because php_gd, php_mysql, php_mysqli, or another extension was not loaded; it simply was NOT found.
I'm guessing that all the answers that are reported as valid (for Windows / WAMP), that say to load other extensions, to change php.ini extension_dir paths (if this one was wrong to begin with, NO extensions would load), etc, work more due to a) un-commenting the extension = php_mbstring.dll line, or b) restarting Apache or the computer (for changes to take effect).
On Windows, most of the time the problem is that php_mbstring.dll is either:
Blocked by Windows. Unblock it by right-clicking it, check Properties.
Or PHP can't load php_mbstring.dll due to another version getting loaded (e.g., from some improper PHP DLLs install into C:\Windows\system32), some version mismatch, missing run-time DLLs, etc. Check Apache's and PHP's error log files first for clues.
More in-depth answer here: Call to undefined function mb_detect_encoding
For fedora/centos/redhat:
yum install php-mbstring
Then restart apache
you should use only english version of phpmyadmin if you are using all languages you should enable all languages mbstring in php.in file.....just search for mbstring in php.in
The problem could also be that Apache can't find php.ini
If you set PHPIniDir incorrectly.
Mine was set to: PHPIniDir "c:/php7"
But, the folder is actually just "php"
The clue was viewing phpinfo()
Which showed:
Configuration File (php.ini) Path C:\windows
I had the same problem with Ubuntu 17, Ispconfig was not processing the operations queued of any kind and also the server.sh command was not working.
I checked and the running PHP version after the OS upgrade was 7.1 so the solution was to type:
apt-get install php7.1-mbstring
and now is everything ok
Hope this helps some ppl, I got this error when i added the path and extension to "docref_root" "docref_ext" in my php.ini file, I then commented it out and it was ok, but cant get my help to work now.
In case your php version is 7.2:
sudo apt-get install php7.2-mbstring
sudo service apache2 restart
PHP.INI XAMP5.6 > In my case, while updating max_ values, I removed
; max_input_time
Default Value: -1 (Unlimited)
After undoing everything works normally.
; max_input_time
; Default Value: -1 (Unlimited)
Related
I receive this error after trying to set up LAMP by following this tutorial, and I find myself receiving the above error after trying to set up phpmyadmin.
Fatal error: Call to undefined function mb_detect_encoding() in
C:\WebServer\Apache\htdocs\phpmyadmin\libraries\php-gettext\gettext.inc
on line 177
I followed the advice over here: PHP Fatal error when trying to access phpmyadmin mb_detect_encoding, and made those changes.
When I run phpinfo(), I see that support for MySQL and mb_string are enabled as shown below:
Install the gd library also.
check this link
http://www.php.net/manual/en/mbstring.installation.php
There's a much easier way than recompiling PHP. Just yum install the required mbstring library:
Example: How to install PHP mbstring on CentOS 6.2
yum --enablerepo=remi install php-mbstring
Oh, and don't forget to restart apache afterward.
Mbstring is a non-default extension. This means it is not enabled by default. You must explicitly enable the module with the configure option.
In case your php version is 7.2:
sudo apt-get install php7.2-mbstring
sudo service apache2 restart
In case your php version is 7.0:
sudo apt-get install php7.0-mbstring
sudo service apache2 restart
In case your php version is 5.6:
sudo apt-get install php5.6-mbstring
sudo service apache2 restart
On Windows open the file php.ini and make this changes:
Remove the comment and point to the ext directory
; extension_dir = "./" -> extension_dir = "C:/Php/ext"
Remove the comment of this extensions
extension=php_mbstring.dll
extension=php_mysqli.dll
Restart apache service
httpd -k restart
When I opened my php.ini file, "extension_dir" line looked like following :
extension_dir = "C:/wamp/bin/php/php5.4.16/ext/"
which i changed to:
extension_dir = "C:\wamp\bin\php\php5.4.16\ext\"
and it worked.
Under Windows / WAMP there doesn't seem to be any php_mbstring.dll dependencies on the GD2 extension, the MySQL extensions, nor on external dlls/libs:
deplister.exe ext\php_mbstring.dll
php5ts.dll,OK
MSVCR110.dll,OK
KERNEL32.dll,OK
deplister.exe ext\php_gd2.dll
php5ts.dll,OK
USER32.dll,OK
GDI32.dll,OK
KERNEL32.dll,OK
MSVCR110.dll,OK
Whatever php_mbstring already needs, it's built-in (statically compiled right into the DLL).
Call to undefined function mb_detect_encoding()
This error is also very specific and deterministic...
The function mb_detect_encoding() didn't fail because php_gd, php_mysql, php_mysqli, or another extension was not loaded; it simply was NOT found.
I'm guessing that all the answers that are reported as valid (for Windows / WAMP), that say to load other extensions, to change php.ini extension_dir paths (if this one was wrong to begin with, NO extensions would load), etc, work more due to a) un-commenting the extension = php_mbstring.dll line, or b) restarting Apache or the computer (for changes to take effect).
On Windows, most of the time the problem is that php_mbstring.dll is either:
Blocked by Windows. Unblock it by right-clicking it, check Properties.
Or PHP can't load php_mbstring.dll due to another version getting loaded (e.g., from some improper PHP DLLs install into C:\Windows\system32), some version mismatch, missing run-time DLLs, etc. Check Apache's and PHP's error log files first for clues.
More in-depth answer here: Call to undefined function mb_detect_encoding
For fedora/centos/redhat:
yum install php-mbstring
Then restart apache
you should use only english version of phpmyadmin if you are using all languages you should enable all languages mbstring in php.in file.....just search for mbstring in php.in
The problem could also be that Apache can't find php.ini
If you set PHPIniDir incorrectly.
Mine was set to: PHPIniDir "c:/php7"
But, the folder is actually just "php"
The clue was viewing phpinfo()
Which showed:
Configuration File (php.ini) Path C:\windows
I had the same problem with Ubuntu 17, Ispconfig was not processing the operations queued of any kind and also the server.sh command was not working.
I checked and the running PHP version after the OS upgrade was 7.1 so the solution was to type:
apt-get install php7.1-mbstring
and now is everything ok
Hope this helps some ppl, I got this error when i added the path and extension to "docref_root" "docref_ext" in my php.ini file, I then commented it out and it was ok, but cant get my help to work now.
In case your php version is 7.2:
sudo apt-get install php7.2-mbstring
sudo service apache2 restart
PHP.INI XAMP5.6 > In my case, while updating max_ values, I removed
; max_input_time
Default Value: -1 (Unlimited)
After undoing everything works normally.
; max_input_time
; Default Value: -1 (Unlimited)
pdo is working fine with mysql but with pgsql its giving error 'PDOException' with message 'could not find driver' I've installed php5-pgsql package which also includes pdo_pgsql
http://packages.debian.org/sid/php5-pgsql
This package provides a module for PostgreSQL database connections directly from PHP scripts. It also includes the pdo_pgsql module for use with the PHP Data Object extension.
my dsn is pgsql:dbname=DB;host=192.168.0.2
I am using Ubuntu 10.04
This message means you need to install and or activate postgresql extension in PHP
This solution works for me :
To install postgresql extension
[sudo] apt-get install php-pgsql
after, for activating it, uncomment pgsql and pdo-pgsql extensions in etc/php/$PHP_VERSION/apache2/php.ini file
Finally, type :
[sudo] /etc/init.d/apache2 restart
To restart apache server if you use apache such as was my case...
1) Have you enabled pgsql.so in php.ini (extension=pgsql.so)?
2) Is you Postgresql listenin on 192.168.0.2 interface? (You can check it by netstat -tpln)
3) How you authenticate your access into Postgresql?
Make sure you've uncommented the line that tells php where the Postgres driver is (usually extension=pgsql.so) in the main php.ini file.
I had the same issue. First of all - check is it enabled in php.ini. Uncomment extension=php_pdo_pgsql...
than set up extension directory!!
extension_dir = "ext" ; for your case it could be other dir.
and do not forget to restart server after changing the config.
Try to remove semicolon in front of
extension=pgsql
extension=pgsql.so
included in your php.ini file
You can do that from the XAMPP Control Panel.
Here is what I did to solve the problem.
Edit php.ini and remove ; from extension=pdo_pgsql. Also, add extension=pgsql.so to the php.ini file.
Make sure to restart the Apache server before you try to see the result.
I had the same problem with another solution. I lost my around 4 hours to solve this problem. Please check the following to solve this problem.
Check php.ini file and remove semicolon from this line
extension=pgsql
extension=pdo_pgsql
Restart your apache2 server
sudo service apache2 restart
Check if your PDO driver has updated in localhost phpinfo()
I did All the things right and still I had this problem. And you know why? Because I had several versions of php installed. So I was running php7.4 in my php cli but localhost was running on php7.2. So always check your php versions.
Check your php version on localhost and terminal cli
When you do not have postgresql installed on the same machine that is Apache and PHP; you have to install php-pgsql and don't have to add extensions in php.ini manually in Linux (in Windows yes), because redundancies are generated and this does not work (checked in error.log).
$ sudo apt install php-pgsql
Then you can check the existence of the extension enabled automatically in:
$ sudo nano /etc/php/7.0/apache2/conf.d/10-pdo.ini
Observations: In phpinfo() you will find the directory conf.d/ and the file error.log
GL
Just run php --ini and look for Loaded Configuration File in output for the location of php.ini used by your CLI
then check you have enabled the extensions correctly.
Copy libpq.dll from the PHP directory to Apache24\bin (or wherever your installation could be).
I just changed my server and experience these errors below:
Fatal error: Call to undefined function mysqli_init() in /home/blacktwitter/public_html/system/database/drivers/mysqli/mysqli_driver.php on line 126
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/blacktwitter/public_html/system/database/drivers/mysqli/mysqli_driver.php:126)
Filename: core/Common.php
Line Number: 564
Backtrace:
A PHP Error was encountered
Severity: Error
Message: Call to undefined function mysqli_init()
Filename: mysqli/mysqli_driver.php
Line Number: 126
Backtrace:
Website is in Codeigniter. It works on one server very well and on the local machine too. But when I upload that website at the new server I have that errors. Of course I changed important parameters like database connection, base_url() etc.
I was suspicious about database, but I have created a new database and user etc. and changed connection info.
Why does this happen? It will be helpful to know if it is a bug at the server or at the website. Also when I create some index.html with some test code everything is fine.
It is not a bug in your application, it is just a missing driver, so, you have couple of options...
Go to your php init and uncomment the following:
extension=php_mysqli.dll
If not, try installing it at your server, it varies depending on your distribution.
Try installing php5-mysqlnd
If you cannot do it by hosting restrictions then just move to mysql driver (wont need to change other configurations or queries in CodeIgniter or anything else...)
like this (at your config file)
$db['default']['dbdriver'] = 'mysql'; (you might have mysqli now)
I just had this issue on a ubuntu16.04, php7.1 install with Codeigniter 3.
Solution was simple (if hard to find!)
sudo apt-get install php7.0-mysql
I realised that the mysql*.ini files where missing from the etc/php/7.1/mods-available directory. Not sure how it happened, but that worked for me.
If you use 7.2, simply type sudo apt-get install php7.2-mysql
Use this:
sudo apt-get install php7.*-mysqli
or
sudo phpenmod mysqli
sudo service apache2 restart
This is actually not a CodeIgniter issue but PHP installation issue.
I have installed PHP5.6 in my Linux server and is having a hard time following the googled solutions of using the ff command in order to install the missing mysqli_extension in PHP.
What I tried is but is returning the warning message: Unable to locate package php5-mysqli
sudo apt-get install php5-mysqli
However, my php version is 5.6 so I tried
sudo apt-get install php5.6-mysqli
Then it works.
The problem is php's mysql extension might not have installed, if you are using php 7, just issue the below command and install the extension,
sudo apt-get install php-mysql
Open the folder where you have installed PHP, Edit php.ini file
uncomment this line:
extension=php_mysqli.dll
I know the difference is not that big but for the ones who are running CentOS:
sudo yum install php-mysqli
sudo systemctl status httpd
We are installing the mysqli extension using yum and then restarting our httpd server for the changes to take effect, and in case you are not using httpd just replace httpd for the name of your service.
For me this was a missing line in php.ini that solved it, as I copied another php.ini file to my XAMPP installation.
Worth checking if the line: "extension=php_mysqli.dll" exist (if running Windows, but this isn't applicable for OP, as it's a Linux system), or if the "extension_dir" exists and is correct.
1、apt-get install (yum, compile install whatever) php5-mysqlnd extension.
2、if not work, make sure mysqli is loaded
root#x19-ws07-1:/etc/php5/apache2# cat /proc/31682/maps | grep mysql
if is loaded, you can see:
7f2cd3266000-7f2cd3285000 r-xp 00000000 fd:00 864561 /usr/lib/php5/20131226/mysqli.so
7f2cd69ef000-7f2cd6a2e000 r-xp 00000000 fd:00 864559 /usr/lib/php5/20131226/mysqlnd.so
3、if not loaded use php --ini to find config file
xxxx#xxxx:~$ php --ini
Configuration File (php.ini) Path: /etc/php5/apache2
Loaded Configuration File: /etc/php5/apache2/php.ini
Scan for additional .ini files in: /etc/php5/apache2/conf.d
Additional .ini files parsed: /etc/php5/apache2/conf.d/05-opcache.ini,
/etc/php5/apache2/conf.d/20-mysqli.ini
4、if not config extension, config like this and remember restart your web server
xxxx#xxxxx:~$ cat /etc/php5/apache2/conf.d/20-mysqli.ini
; configuration for php MySQL module
; priority=20
extension=mysqli.so
In Linux, you can install MySQL driver extension.
sudo apt-get install php-mysql
In Windows with XAMPP, the driver has already saved in ext directory, but you need to enable it in php.ini. You need to uncomment this line:
extension=php_mysqli.dll
You also need to check the extension directory location in php.ini. I use absolute path (not relative path) declaration to make it works.
extension_dir="your\absolute\path\to\xampp\php\ext"
For example,
extension_dir="C:\xampp\php\ext"
I tried, comment out below line in /etc/php/cli/php.ini file.
extension=php_mysqli.dll
I am using Ubuntu 16.04 on AWS-EC2 instances and PHP 7.0. This solved my problem.
In my case using Windows I had all the necessary extensions uncommented, but it wasn't loading them. Then, I checked the extension directory variable in php.ini and it was as "ext", but then I remembered I'd had a similar problem previously. So what I did was basically put the explicit directory. Something like this:
extension_dir = "C:\php\ext"
Of course the specific ext directory depends entirely on your own setup and locations.
After updating the php.ini file you just have to restart Apache to apply the changes.
If you installed your Apache manually (not using pre-packaged solutions like XAMPP or WAMPP) you just have to use these commands in either a Command Prompt or a Powershell with administrator rights.
net stop Apache2.4
net start Apache2.4
If your webserver is running with a lower version of MySQL, then you will get this error as MySQLi is not supported in MySQL < 4.1.3
It is highly recommended to go with MySQLi instead of going back to MySQL extension.
More info on php.net
I suggest you do the following:
change:
'dbdriver' => 'mysqli',
'dbprefix' => '',
to:
'dbdriver' => 'mysql',
'dbprefix' => '',
in database.php file.
Not sure what happened, but below is what the log is giving me when trying to access phpmyadmin, please help. Trying to debug a different problem and ran into this. Not really possible to revert back to when it was working.
PHP Fatal error: Call to undefined function mb_detect_encoding() in
/usr/share/php/gettext/gettext.inc on line 177
When trying to go the the site, I get this error, I think it's likely the two errors are related:
Database connection error (1): The MySQL adapter 'mysqli' is not available.
First error is caused by php because the extension mbstring is either not installed or not active.
The second error is output of phpMyAdmin/your site asking you to install / enable the mysqli extension.
To enable mbstring and mysqli edit your php.ini and add/uncomment the two lines with mbstring.so and mysqli.so on unix or mbstring.dll and mysqli.dll on windows
Unix /etc/(phpX/)php.ini
extension=mysqli.so
extension=mbstring.so
Windows PHP installation folder\etc\php.ini
extension=mysqli.dll
extension=mbstring.dll
Don't forget to restart your webserver after this.
EDIT:
User added he was using redhat in the comments so here's how you install extensions on all CentOS/Fedora/RedHat/Yum based linux distros
sudo yum install php-mysqli
sudo yum install php-mbstring
restart your werbserver
sudo /etc/init.d/httpd restart
you can verify your installation with a little php script in your document root.
This lists all settings, versions and active extensions you've installed for php
test.php
<?php
phpinfo();
After reading about the extension_dir = "ext" i added the line to php.ini but didnt work, then started to look apache error log and saw the PHP was in fact unable to find the dll's in the specified directory "ext". I commented the extension_dir line, restarted Apache and looked the error log again, saw that PHP was now looking the dll's in C:/PHP/ext (by default i guess), but since im using other folders, that's not the correct path, so i uncommented the extension_dir line and wrote this:
extension_dir = "C:/Apache24/PHP/ext"
In my configuration that is the correct path to dll's.
and of course, uncommented:
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
Restarted the Apache server and internet browser and now phpMyAdmin works with my mySQL login.
So, dll's incorrect path and dll's needed commented in php.ini were the problem.
Remember to restart Apache and internet browser after editing config files.
System spec:
Windows 7 HB 64bit
httpd-2.4.4-win32-ssl_0.9.8.zip
php-5.4.16-Win32-VC9-x86.zip
phpMyAdmin-4.0.4.1-all-languages.zip
mysql-installer-community-5.6.11.0.msi
Hope this help. Thx for your comments too.
in ubuntu 16.04 when i tried to connect to phpmyadmin a white blank paged appeared so i ran the above command and phpmyadmin works
sudo apt-get install php-mbstring php7.0-mbstring php-gettext
for mysql support install
sudo apt-get install php7.0-mysql
tested in ubuntu 16.04 with php 7 version
It looks like your PHP installation does not have the mbstring extension and the mysqli adapter extension installed.
Please check your phpinfo(); or run php -i | grep 'mbstring\|mysqli' in a terminal.
I had the same problem on my windows7- 32 bit:
1."PHP Fatal error: Call to undefined function mb_detect_encoding() in /usr/share/php/gettext/gettext.inc on line 177"
when i opened my php.ini file , "extension_dir" line looked like following :
extension_dir = "C:/wamp/bin/php/php5.4.16/ext/"
which i changed to :
extension_dir = "C:\wamp\bin\php\php5.4.16\ext\"
and it worked.
In php.ini, I had to change
extension_dir = "ext"
to
extension_dir = "C:/PHP/ext"
as my PHP was installed in C:\PHP. I had to use / instead of \, and then it worked.
Also uncomment mbstrings, mysqli and mysql extensions.
What helped me (using XAMPP on Windows) was to:
make sure that my path included the correct path for PHP (I had two PHP
installations, one under c:\php and the XAMPP installation in
c:\xampp\php which was the one I wanted to use)
check that the lines
extension_dir="C:\xampp\php\ext" extension=php_mbstring.dll extension=php_exif.dll ; Must be after mbstring as it depends on it were uncommented in the php.ini file (i.e. no ; at the beginning)
restart the Apache server
last but not least, clear the cache when reloading the page http://localhost/phpmyadmin/ (for instance with Ctrl-F5 in Chrome)
Recompile PHP with mbstring.
./configure --enable-http --with-apxs2 --with-mysql --with-gd
--with-curl --with-mbstring
make
make install
My guess would be to check that the mysqli extension is enabled in your PHP configuration. More info would be great (eg. OS, AMP stack, etc.).
Check in your php.ini configuration for mysqli and make sure there is no ';' in front of the extension. The one enabled on my setup is php_mysqli_libmysql.dll.
Try to install mysqli and pdo.
Put it in terminal:
./configure --with-mysql=/usr/bin/mysql_config \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd
I tried on Windows and I was getting same issue after enabling this in PHP installation folder\etc\php.ini:
extension=mysqli.dll
extension=mbstring.dl
You should also enable the following in the ini file:
extension_dir = "ext"
phpMyadmin is working now!
In windows 2008 Server.
i removed ";" in front of extension=php_mbstring.dll in php.ini file and it worked... i followed below link...
https://bugs.php.net/bug.php?id=64965
Some versions of windows do not come with libmysql.dll which is necessary to load the mysql and mysqli extensions. Check if it is available in C:/Windows/System32 (windows 7, 32 bits). If not, you can download it DLL-files.com and install it under C:/Windows/System32.
If this persists, check your apache log files and resort to a solution above which responds to the error logged by your server.
One options is:
disabled this extension_dir = "ext"
and the other is:
go to wamp icon and see php and the click on php error logs then from error log u can find exact error.
this error occurs only if paths are not properly set.
I had the same trouble, this is what worked for me.
You can click at the wampserver icon, then at the PHP error log.
Check if it says this:
Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_ldap.dll'
If yes, then you can reload your version of PHP, by clicking at the wampserver icon, then PHP, then version, and then you click at your version.
Wait for everything to be online again, then try to access phpmyadmin.
pdo is working fine with mysql but with pgsql its giving error 'PDOException' with message 'could not find driver' I've installed php5-pgsql package which also includes pdo_pgsql
http://packages.debian.org/sid/php5-pgsql
This package provides a module for PostgreSQL database connections directly from PHP scripts. It also includes the pdo_pgsql module for use with the PHP Data Object extension.
my dsn is pgsql:dbname=DB;host=192.168.0.2
I am using Ubuntu 10.04
This message means you need to install and or activate postgresql extension in PHP
This solution works for me :
To install postgresql extension
[sudo] apt-get install php-pgsql
after, for activating it, uncomment pgsql and pdo-pgsql extensions in etc/php/$PHP_VERSION/apache2/php.ini file
Finally, type :
[sudo] /etc/init.d/apache2 restart
To restart apache server if you use apache such as was my case...
1) Have you enabled pgsql.so in php.ini (extension=pgsql.so)?
2) Is you Postgresql listenin on 192.168.0.2 interface? (You can check it by netstat -tpln)
3) How you authenticate your access into Postgresql?
Make sure you've uncommented the line that tells php where the Postgres driver is (usually extension=pgsql.so) in the main php.ini file.
I had the same issue. First of all - check is it enabled in php.ini. Uncomment extension=php_pdo_pgsql...
than set up extension directory!!
extension_dir = "ext" ; for your case it could be other dir.
and do not forget to restart server after changing the config.
Try to remove semicolon in front of
extension=pgsql
extension=pgsql.so
included in your php.ini file
You can do that from the XAMPP Control Panel.
Here is what I did to solve the problem.
Edit php.ini and remove ; from extension=pdo_pgsql. Also, add extension=pgsql.so to the php.ini file.
Make sure to restart the Apache server before you try to see the result.
I had the same problem with another solution. I lost my around 4 hours to solve this problem. Please check the following to solve this problem.
Check php.ini file and remove semicolon from this line
extension=pgsql
extension=pdo_pgsql
Restart your apache2 server
sudo service apache2 restart
Check if your PDO driver has updated in localhost phpinfo()
I did All the things right and still I had this problem. And you know why? Because I had several versions of php installed. So I was running php7.4 in my php cli but localhost was running on php7.2. So always check your php versions.
Check your php version on localhost and terminal cli
When you do not have postgresql installed on the same machine that is Apache and PHP; you have to install php-pgsql and don't have to add extensions in php.ini manually in Linux (in Windows yes), because redundancies are generated and this does not work (checked in error.log).
$ sudo apt install php-pgsql
Then you can check the existence of the extension enabled automatically in:
$ sudo nano /etc/php/7.0/apache2/conf.d/10-pdo.ini
Observations: In phpinfo() you will find the directory conf.d/ and the file error.log
GL
Just run php --ini and look for Loaded Configuration File in output for the location of php.ini used by your CLI
then check you have enabled the extensions correctly.
Copy libpq.dll from the PHP directory to Apache24\bin (or wherever your installation could be).