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.

This particular one occurred after an easyapache upgrade of Apache and PHP. Below are the things you should check in order to correct the issue.

Check the PHP Modules List to See if It Is Enabled

The first thing we should check is to see if the server has the PDO extensions enabled.

  1. Log into your server via SSH.
  2. Run the command below.
    php -m
  3. You will then be presented with a list of modules currently installed in php, listed alphabetically. Look for PDO in the list. If it exists, then the module is installed.
    mysqlnd
     openssl
     pcre
     PDO
     pdo_mysql
     pdo_sqlite
     Phar
     posix

Ensure They Are Being Called in the php.ini File

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:

extension=pdo.so
extension=pdo_sqlite.so
extension=pdo_mysql.so
extension=sqlite.so

If they are not present, simply add the lines above to the bottom of the php.ini file and save it.

Ensure the php.ini File Is Recursive

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.

Check the Extension Directory for PHP

It is also possible that the php.ini 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 php.ini file:

  1. Log into your account via SSH.
  2. Navigate to the /usr/local/lib/php/extensions directory.
  3. Run the following command on the directory:
    ls -lah
    You will then see all the extension directories inside.
    root@vps#### [/usr/local/lib/php/extensions]# ls -lah drwxr-xr-x 5 root root 4.0K May 10  11:13 ./
     drwxr-xr-x 15 root root 4.0K Aug 28 2021 ../
     drwxr-xr-x 2 root root 4.0K Sep 2 2010 no-debug-non-zts-20060613/
     drwxr-xr-x 2 root root 4.0K May 10 11:48 no-debug-non-zts-20090626/
     drwxr-xr-x 2 root root 4.0K Oct 10 10:56 no-debug-non-zts-20100525/
  4. Check the dates to find the most recent one. Notate the full name of that directory. In our example it is no-debug-non-zts-20100525.
  5. Now you will need to open your php.ini file. Navigate to the home directory and open the file using nano.
    cd /home/public_html

    nano php.ini
  6. Once the file is opened, find the extension_dir setting and ensure that the path is the same as the latest one in your /usr/local/lib/php/extensions directory.
    ; Directory in which the loadable extensions (modules) reside.
     extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20100525"

Comment Out the extension_dir in php.ini

One additional option to the above fix is to simply comment the line for the extension_dir 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 php.ini, 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.

; Directory in which the loadable extensions (modules) reside.
 extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20100525"

Once you correct one or more of the above steps, you shoud no longer have any issues with the PDO error.

13 thoughts on “Fatal Error: Class ‘PDO’ Not Found

  1. 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 

    1. 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.

  2. 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

    1. 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.

      Regards,
      Arnel C.

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

  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? Join the conversation!