3

I am using Windows 10 and have installed Apache2.4, PHP7.2 and MySQL. I am having trouble installing the driver for pdo_mysql

I have edited my php.ini file, and in the extensions section I have:

extension=pdo_mysql

I have also set the extension_dir directive to:

"C:\php72\ext"

In the command console I enter "php -m" and I can see PDO and pdo_mysql both listed.

command console screenshot showing php -m

I have restarted Apache but when I run a .php file including either print_r(PDO::getAvailableDrivers()); or phpinfo(); I can see that I do not have any drivers installed for PDO.

In my httpd.conf file I have

PHPIniDir “C:\php72\”

I have tried changing this to use forward and backslashes, and including and removing the trailing slash, restarting Apache after each change. I still cannot get the pdo_mysql driver to load.

It seems to me that the problem is with Apache not with PHP (as the pdo_mysql module appears when I run php -m in the command console), but I don't understand what I have done wrong. I searched for other people having the same problem but the solution always seemed to be the PHPIniDir, which I think I have set correctly.

The machine I am using was already running IIS so I have Apache listening to port 8090, rather than the default. I am not sure if this is relevant or not.

Any help would be appreciated!

3
  • PHPIniDir is in the file httpd-xampp.conf in your apache installation folder, perhaps C:\xampp\apache\conf\extra\httpd-xampp.conf, and the line should look something like <IfModule php7_module> PHPINIDir "C:/xampp/php" </IfModule>.
    – harrymc
    Sep 22, 2019 at 10:44
  • Thanks but I didn't use xampp to install, so I don't have a C:\xampp directory, and I don't have a httpd-xampp.conf file either.
    – Liam Bell
    Sep 22, 2019 at 16:51
  • My PHPIniDir did not appear inside the IfModule tag as you suggested. I tried wrapping it inside those tags and restarting Apache, but the driver is still not loading. <IfModule php7_module> PHPIniDir “C:/php72/” AddHandler application/x-httpd-php .php LoadModule php7_module "C:\php72\php7apache2_4.dll" </IfModule>
    – Liam Bell
    Sep 22, 2019 at 17:02

3 Answers 3

1

I uninstalled Apache service, deleted C:\Apache24 and installed from scratch, the followed the steps to install pdo_mysql as before which has worked.

1

I had this same problem, where modules were loaded when running via cli, but not when running same php config via Apache.

In my case the solution was to set the extension_dir in the php.ini file to the absolute path of modules folder (C:\php80\ext in my case).

Now both cli and Apache are loading the modules correctly.

0

For me the stupid instructions I was following to setup Fast CGI with Apache had me put the exe file where the ini file was supposed to go.

# Where is your php.ini file?
FcgidInitialEnv PHPRC "c:/Program Files/php/php.exe" // should be ini

I changed that to the ini and it worked. I'm surprised php let me set php.exe as the ini file...

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    May 27, 2022 at 21:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .