Fatal error: Class ‘PDO’ not found

When working with Content Management Systems such as Drupal or other programs in your hosting account, you may run across certain errors during either the initial setup or even after a php or Apache upgrade on your server. One common error you may run across when trying to enter your site is the PDO error. It looks like the one below.

Fatal error: Class ‘PDO’ not found in /home//public_html/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php on line 72.
This particular one occurred after an easyapache upgrade to <a href="/support/edu/easyapache/upgrade-apache-using-easyapache/">Apache</a> and <a href="/support/">php</a>. Below are the things you should check in order to correct the issue. </p> <h2>Check the php modules list to see if it is enabled</h2> <p>The first thing we should check is to see if the server has the PDO extensions enabled. <ol class="article_list"> <li><a href="/support/server/ssh/how-to-login-ssh/">Log into your server via SSH</a>.<div style="clear:both;"></div></li> <li>Run the command below. <div class="cli">php -m</div><div style="clear:both;"></div></li> </ol> You will then be presented with a list of modules currently installed in php, listed alphabetically. Look for <b>PDO</b> in the list. If it exists, then the module is installed. <div class="code_block">   mysqlnd<br/> openssl<br/> pcre<br/> <span style="color:red">PDO</span><br/> pdo_mysql<br/> pdo_sqlite<br/> Phar<br/> posix<br/> </div> </p> <h2>Ensure they are being called in the php.ini file</h2> <p>If the PDO is displayed in the list of currently installed php modules, you will want to check the php.ini file in the relevant folder to ensure they are being called. Somewhere in the php.ini file you should see the following:  <div class="code_block"> extension=pdo.so<br/> extension=pdo_sqlite.so<br/> extension=pdo_mysql.so<br/> extension=sqlite.so<br/> </div> If they are not present, simply add the lines above to the bottom of the php.ini file and save it. </p> <h2>Ensure the php.ini file is recursive</h2> <p> You will next want to ensure that the php.ini file is being used by all the folders and files underneath the main folder. This is known as being recursive. Below is a link to our article on doing just that.   <br/><br/> <a href="/support/website/recursive-php-ini/">How can I make my php.ini file recursive ?</a> </p> <h2>Check the extension directory for php</h2> <p>   It is also possible that the <em>php.ini</em> file is looking into an incorrect extension directory, especially if you just performed an update. Below are the instructions for adjusting the extensions directory in the <em>php.ini</em> file:  <ol class="article_list"> <li><a href="/support/server/ssh/how-to-login-ssh/">Log into your account via SSH</a>.<div style="clear:both;"></div></li> <li>Navigate to the <em>/usr/local/lib/php/extensions</em> directory.<div style="clear:both;"></div></li> <li>Run the <b>ls -lah</b> command on the directory so you can see all the exension directories inside.<div style="clear:both;"></div></li> <div class="cli"> [email protected]#### [/usr/local/lib/php/extensions]# ls -lah drwxr-xr-x  5 root root 4.0K May 10 11:13 ./<br/> drwxr-xr-x 15 root root 4.0K Aug 28  2012 ../<br/> drwxr-xr-x  2 root root 4.0K Sep  2  2010 no-debug-non-zts-20060613/<br/> drwxr-xr-x  2 root root 4.0K May 10 11:48 no-debug-non-zts-20090626/<br/> drwxr-xr-x  2 root root 4.0K Oct 10 10:56 no-debug-non-zts-20100525/<br/> </div> <li>Check the dates to find the most recent one. Notate the full name of that directory. In our example it is <em>no-debug-non-zts-20100525</em>.<div style="clear:both;"></div></li> <li>Now you will need to open your <em>php.ini</em> file. Navigate to the home directory and open the file using <em>nano</em>. <div class="cli"> cd /home/<username>/public_html<br/> nano php.ini<br/> </username></div> <div style="clear:both;"></div></li> <li>Once the file is opened find the <em>extension_dir</em> setting and ensure that the path is the same as the latest one in your <em>/usr/local/lib/php/extensions</em> directory. <div class="cli"> ; Directory in which the loadable extensions (modules) reside.<br/> extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20100525"<br/> </div><div style="clear:both;"></div></li> </ol> <h2>Comment out the extension_dir in php.ini</h2> <p>One additional option to the above fix is to simply comment the line for the <em>extension_dir</em> setting out in the php.ini. Doing this does no harm as it simply makes the php use the extension directory from the main server <em>php.ini</em>, which is most probably the one you want. To do so, simply place a semicolon (;) at the very beginning of the line as demonstrated below.     <div class="code_block">; Directory in which the loadable extensions (modules) reside.<br/> ;extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20100525"<br/></div> </p> Once you correct one or more of the above steps, you shoud no longer have any issues with the PDO error. 

Thoughts on “Fatal error: Class ‘PDO’ not found

  • Hi
    i have error in pdo connection in laravel 5.6 with php v 7.1 
    and also follow all steps but the error also appear 

    • Hello,

      Sorry for the problems with Laravel and PHP 7.1. We would need to know what specific error you’re seeing. Please provide more information about the error and the steps you’re taking so that we can attempt to duplicate the error if necessary. You may also want to look at other forums that have discussed a similar issue. Check out this post regarding an issue with Laravel 5.6 on a MAMP server and using PHP 7.1.

  • Fatal error: Uncaught Error: Class ‘PDO’ not found in /var/www/localhost/appliance/cacti/lib/database.php:52 Stack trace: #0 /var/www/localhost/appliance/cacti/include/global.php(215): db_connect_real(‘localhost’, ‘cacti’, ‘secreto’, ‘cacti’, ‘mysql’, ‘3306’, false) #1 /var/www/localhost/appliance/cacti/include/auth.php(27): include(‘/var/www/localh…’) #2 /var/www/localhost/appliance/cacti/index.php(25): include(‘/var/www/localh…’) #3 {main} thrown in /var/www/localhost/appliance/cacti/lib/database.php on line 52

    • Did you follow the article above? It tells you how to solve this issue. If the article is not providing the help you need, then you will need to speak with support a developer who can review your website.

      If you have any further questions or comments, please let us know.

      Arnel C.

  • Thank you! Commenting out the line worked perfectly (on an existing site after we upgraded the server to PHP 5.4).

  • I just moved over to VPS1000 hosting from shared hosting.  I called tech support, and they moved my php.ini file to the public_html directory.  Then I added the extension lines as noted above, but it still didn’t work.  However, once I commented out the extension_dir line as noted in the last step, it worked!!!!  Thanks for the help!  –Rob P.

Was this article helpful? Let us know!