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/<username>/public_html/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php on line 72.
This particular one occurred after an easyapache upgrade to 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
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.

How can I make my php.ini file recursive ?

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 ls -lah command on the directory so you can see all the exension directories inside.
  4. 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 2012 ../
    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/
  5. 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.
  6. Now you will need to open your php.ini file. Navigate to the home directory and open the file using nano.
    cd /home/<username>/public_html
    nano php.ini
  7. 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.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question
n/a Points
2014-09-05 10:36 am

That was really great and informative.

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

1 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!