PHP is Missing mysql pdo Driver

14,390

.so implies you are on Linux - did you install PHP as a package. You probably need to install the pdo/mysql package - PHP libraries may be "core", but not necessarily in the main package (confusing, but it just means it's not PEAR delivered, really).

sudo apt-get install php5-mysql

Or, if you're running PHP7:

sudo apt-get install php-mysql

This should restart the apache automatically, but to be sure you could do:

sudo service apache2 restart

The package installer for php-mysql should have put the .so libraries in /usr/lib/php/yyyymmdd/ - if you had installed PHP as a package, it would be looking here.

However, since you installed from source, it seems that PHP is looking elsewhere for the libraries. You can create symlinks from /usr/local/lib/php/extensions/no-debug-non-zts-20151012/ to the package installed libraries.

Share:
14,390
Allen More
Author by

Allen More

Updated on June 04, 2022

Comments

  • Allen More
    Allen More almost 2 years

    I'm trying to run a Symfony 3 app with php 7 installed from source and I'm getting a Missing PDO driver exception. According to http://pecl.php.net/package/PDO_MYSQL the PDO_MYSQL extension is now part of PHP core.

    Q1.a) If I have the PDO_MYSQL extension (which I must, since its core) does that mean that I also have the mysql pdo driver?

    Q2.b) Is there further runtime configuration I have to do to make sure that the driver gets used?

    I've tried adding

    extension=php_pdo.so

    extension=php_pdo_mysql.so

    to my loaded php.ini file.

    Q2.a) Are these the correct extension names? How could I find out?
    Q2.b)Do I even have to provide extension references for core php elements?

    Finally:

    Q3. How can I check whether my PHP install included the mysql pdo driver and how do I make sure that it is being loaded at runtime?

    Thanks for your input.

    Edit 1: I'm running on Linux Mint.
    Edit 2: Here are a couple more details on what I'm seeing on my end:

    "On starting up the built in php server I get the following message: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20151012/php_pdo.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20151012/php_pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20151012/php_pdo_mysql.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20151012/php_pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0"

    This message suggests to me that either the extension references are incorrect or the extension does not exist. I used "dpkg -L php-mysql" and found that the package was installed in "/usr/share/doc/php-mysql" however, when I check in the php-mysql directory, all I see is a changelog and a copyright file (with hiddens shown). Is this the true install location of the package and, if so, should there be more in this directory?

    • Charlotte Dunois
      Charlotte Dunois over 7 years
      Depending on the packager pdo_mysql might be an extra package. Like it's the case of dotdeb's jessie packages.
    • Charlotte Dunois
      Charlotte Dunois over 7 years
      Look into phpinfo and look for PDO MySQL. <?php phpinfo();
    • Ekin
      Ekin over 7 years
      What does php -m or php -i | grep PDO say?
    • Allen More
      Allen More over 7 years
      I forgot to mention, phpinfo() only shows the sqlite pdo driver as being enabled. I suspect this is because either a) the driver isn't enabled correctly in php.ini or b) it is not installed. How can I tell which of these is the case?
    • Allen More
      Allen More over 7 years
      php -m: [PHP Modules] Core ctype date dom fileinfo filter hash iconv json libxml pcre PDO pdo_sqlite Phar posix Reflection session SimpleXML SPL sqlite3 standard tokenizer xml xmlreader xmlwriter php -i | grep PDO: PDO PDO support => enabled PDO drivers => sqlite PDO Driver for SQLite 3.x => enabled
    • HorusKol
      HorusKol over 7 years
      dpkg should be listing a lot more directories than just the documentation... for example, when I run that command I get /usr/lib/php5/20121212/mysqli.so among others... /usr/share/doc/php5-mysql is just the last one in the list
  • Allen More
    Allen More over 7 years
    This is one of the solutions I tried before posting this question. I've tried it again to no effect. Is there something I need to do after installing this package to get it to work? dpkg command says that its successfully installed.
  • Jeff Puckett
    Jeff Puckett over 7 years
    @allen You'll need to restart the webserver. If apache 2.4 on ubuntu, sudo service apache2 restart
  • Allen More
    Allen More over 7 years
    Hi @JeffPuckettII. Good thought, but I've already done this. I'll be posting some more info on the main post shortly that will hopefully narrow down the list of possible causes.
  • HorusKol
    HorusKol over 7 years
    hmm - sorry, I missed where you said you'd installed PHP7 from source... I can only assume that this means PHP is installed with different paths to what the normal package system does... is there a reason you haven't installed PHP7 as a package?
  • Allen More
    Allen More over 7 years
    There wasn't much package support for php7 when I installed it, I know there are some now. How would I go about switching from my install from source to a package based install? Thanks for your help.
  • HorusKol
    HorusKol over 7 years
    If possible, I'd take a snapshot of the server, then remove the source installed PHP and then follow digitalocean.com/community/tutorials/…
  • Allen More
    Allen More over 7 years
    You were right, the issue was fixed by wiping php7 from my machine and reinstalling via package. Thanks again for your help.