13

I installed Apache, PHP 5.6 and MySQL 5.7 on a Windows server.

In php.ini, I enabled the following:

extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_oci8_12c.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll

(And restarted Apache)

But when I try to use PDO in my php page, it still throws the error:

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'

What do I have to do to get PDO installed?

Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
  • _"try to use PDO"_ How? – AbraCadaver Dec 10 '15 at 22:07
  • @AbraCadaver In a php page. I simply call `new PDO(...)` – Don Rhummy Dec 10 '15 at 22:09
  • Some extensions require other previous extensions preinstalled, and some changes made to the PHP configuration, check the PHP site and MySQL for requirements, and configuration, for the PDO extension, and the MySQL extension – umlcat Dec 10 '15 at 22:12
  • @umlcat I did here: http://php.net/manual/en/pdo.installation.php And I've done everything it says to do! – Don Rhummy Dec 10 '15 at 22:15
  • @Don Rhummy And for MySQL ? You must check Apache MySQL access and later PHP MySQL Configuration. Is not enough to have MySQL in your machine, you have to setup in Apache Web Server, and later, setup into the PHP server !!! – umlcat Dec 10 '15 at 22:23
  • @umlcat Can you tell me what more I need to do in Apache to set it up? Every installation guide I've seen has no additional steps after installing MySQL. – Don Rhummy Dec 10 '15 at 22:25
  • Skip Apache, and check PHP site for MySQL setup – umlcat Dec 10 '15 at 22:29
  • @umlcat Looking at the docs, there's *nothing* to do. "The MySQL Native Driver is enabled by default." There's no other steps. – Don Rhummy Dec 10 '15 at 22:31
  • Before the changes took effect I had to Stop and restart Apache after making the changes to php.ini. Then refresh the phpinfo() file. – Anthony Sep 18 '17 at 15:44

2 Answers2

20

The problem was the extension_dir directive did not work as a relative path. Changing from extension_dir="ext" to extension_dir="c:/phpinstall_path/ext" fixed the problem.

Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
  • 1
    It is advisable to show the people that get you to your answers the common decency of voting up their Answers. As opposed to making a trivial one and not acknowledging it. Voting reinforces the drive in people who expend effort to solve your problems ... with the desire to keep doing that for others. – Drew Dec 10 '15 at 23:22
  • @Drew I'm happy to give you an upvote for your effort (it was a lot, so I did), but your answer did not help me discover the issue. As I mentioned, you had the exact same settings as me and it worked for you but not on my server. – Don Rhummy Dec 10 '15 at 23:25
  • 1
    Because in looking at my answer, you learned about the direction the slash should go? Anyway, we both have PDO to do, good luck :P – Drew Dec 10 '15 at 23:26
  • 1
    @Drew No, I already knew which way the slash went. It was using the absolute path vs relative path and for a setting you didn't include in your answer. But thanks for all the effort - it *is* appreciated! – Don Rhummy Dec 10 '15 at 23:32
5

In my apache httpd.conf I have (note I have # as remmed out because it took me 1 hour at least). So I left it to show me how not to do it.

#PHPIniDir 'c:\apps\php\'
#PHPIniDir "C:\Apache24\~PHP_download\php-5.6.11-Win32-VC11-x64\"
PHPIniDir "C:/Apache24/~PHP_download/php-5.6.11-Win32-VC11-x64"

#LoadModule php5_module "c:/apps/php/php5apache2_2.dll"
LoadModule php5_module "C:/Apache24/~PHP_download/php-5.6.11-Win32-VC11-x64/php5apache2_4.dll"

AddHandler application/x-httpd-php .php

In the above folder (and seen below) I have these files:

 Directory of C:\Apache24\~PHP_download\php-5.6.11-Win32-VC11-x64

07/24/2015  12:33 PM    <DIR>          .
07/24/2015  12:33 PM    <DIR>          ..
07/24/2015  12:32 PM            69,632 deplister.exe
07/24/2015  12:32 PM    <DIR>          dev
07/24/2015  12:32 PM    <DIR>          ext
07/24/2015  12:32 PM    <DIR>          extras
07/24/2015  12:32 PM         1,290,752 glib-2.dll
07/24/2015  12:32 PM            16,384 gmodule-2.dll
07/24/2015  12:32 PM        25,337,856 icudt54.dll
07/24/2015  12:32 PM         1,907,712 icuin54.dll
07/24/2015  12:32 PM            51,200 icuio54.dll
07/24/2015  12:32 PM           256,000 icule54.dll
07/24/2015  12:32 PM            50,176 iculx54.dll
07/24/2015  12:32 PM            63,488 icutest54.dll
07/24/2015  12:32 PM           195,072 icutu54.dll
07/24/2015  12:32 PM         1,369,088 icuuc54.dll
07/24/2015  12:32 PM            79,826 install.txt
07/24/2015  12:32 PM    <DIR>          lib
07/24/2015  12:32 PM         1,823,232 libeay32.dll
07/24/2015  12:32 PM            46,592 libenchant.dll
07/24/2015  12:32 PM           160,256 libpq.dll
07/24/2015  12:32 PM           237,056 libsasl.dll
07/24/2015  12:32 PM           201,728 libssh2.dll
07/24/2015  12:32 PM             3,286 license.txt
07/24/2015  12:32 PM           518,643 news.txt
07/24/2015  12:32 PM                43 phar.phar.bat
07/24/2015  12:32 PM            53,242 pharcommand.phar
07/24/2015  12:32 PM            58,368 php-cgi.exe
07/24/2015  12:32 PM            30,720 php-win.exe
07/24/2015  12:32 PM            77,824 php.exe
07/24/2015  12:32 PM             2,523 php.gif
08/29/2015  02:28 PM            74,572 php.ini
07/24/2015  12:32 PM            74,334 php.ini-development
07/24/2015  12:32 PM            74,365 php.ini-production
07/24/2015  12:32 PM            31,744 php5apache2_4.dll
07/24/2015  12:32 PM           845,830 php5embed.lib
07/24/2015  12:32 PM           167,936 php5phpdbg.dll
07/24/2015  12:32 PM         8,269,312 php5ts.dll
07/24/2015  12:32 PM           180,224 phpdbg.exe
07/24/2015  12:32 PM            21,360 readme-redist-bins.txt
07/24/2015  12:32 PM             3,634 snapshot.txt
07/24/2015  12:32 PM           353,280 ssleay32.dll

And in that same folder, in the php.ini file I have the following block that are pdo-related, with the ones in force not remmed out with a ;

;extension=php_pdo_firebird.dll extension=php_pdo_mysql.dll ;extension=php_pdo_oci.dll extension=php_pdo_odbc.dll ;extension=php_pdo_pgsql.dll ;extension=php_pdo_sqlite.dll

then I have a phpinfo_xyz.php file for testing purposes only (read: delete it when you are done) that contains

<?php phpinfo(); ?>

Restart apache, point to that file from a browser and notice the following blocks similar to the following three.

enter image description here

...

enter image description here

...

enter image description here

In the first PHP picture above from phpinfo(), it was the getting the path right in httpd.conf that took the longest. That is why I left in the wrong path attempts seen in this Answer.

So it wasn't until Loaded Configuration File showed up decent that it had a chance.

Good luck. It was not fun. Half the problem was there were like 2 or 4 options of which original download to perform. Sadly I think it took me 2 or 3 hours all together. But I am not as smart as the rest of you.

Drew
  • 24,851
  • 10
  • 43
  • 78
  • I have all the same settings (but diff. paths) and it's still giving the error – Don Rhummy Dec 10 '15 at 22:38
  • well I am not there :P ... and there are only some debugging attempts that are well suited for little comment boxes. – Drew Dec 10 '15 at 22:44
  • Could it be that I'm using 32bit Apache/PHP on a 64bit machine? – Don Rhummy Dec 10 '15 at 22:45
  • 1
    I know for a fact that the 32 vs 64 issue took a while for me. – Drew Dec 10 '15 at 22:47
  • What do you mean? Did you use 32bit? Or 64bit? What did you do to fix it? – Don Rhummy Dec 10 '15 at 22:47
  • 1
    It would, because I left the directory names as I did with versioning info, that I chose that which you are presented with on a download page, and I got one to work and not explode when I started up apache. – Drew Dec 10 '15 at 22:51
  • And that is all the time I can give this – Drew Dec 10 '15 at 22:51
  • Thanks for your help. I finally discovered the problem. You can see my answer above. – Don Rhummy Dec 10 '15 at 23:13
  • I am glad my Answer helped you with paths. What do we do with helpful answers :P We vote them up, and in your case mark them as Answered (as opposed to making trivial Answers like yours) – Drew Dec 10 '15 at 23:15