Magento Tutorials

How to Solve “pdo_mysql extension is not installed”

What is “pdo_mysql extension is not installed”?

There are two possible scenarios when this error happens:

Scenario 1: When you install Magento 2, after Readiness Check, you will come to the step Add a Database. The message “pdo_mysql extension is not installed” appears on a red line.

pdo_mysql extension is not installed

Scenario 2: When you run the command php bin/magento setup:static-content:deploy from command line. The message shows:

pdo_mysql extension is not installed - command line

Why does this happen?

In PHP, there’s a module named php-mysql, which is very important to any PHP servers using mysql to be its database.

PHP needs this file to connect with mysql database. When this error occurs, it is likely that this module have not been installed or have been disabled.

How to solve it?

The module may be disabled. Run this command to enable it:

sudo phpenmod pdo_mysql

If the above method doesn’t work, then this module have not been installed.

In this case, install the module from your server’s command line (with sudo) (*):

sudo apt-get install php7.0-mysql

Note: In this guide we use PHP version 7.0. If you are using a different PHP version, please adjust the command line accordingly.


Update: There’s been a recent feedback about the following error when following our tutorial:

Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend) 

We’d like to note that this is most commonly an issue with running process(es) in the background. In order to list any process that is accessing the file, run:

sudo lsof /var/lib/dpkg/lock-frontend

and use sudo kill to kill process_id:

sudo kill -9 process_id

After which, remove and reconfigure the dpkg frontend lock:

sudo rm /var/lib/dpkg/lock-frontend
sudo dpkg --configure -a

And lastly, run the update command and see if the issue is resolved for you:

sudo apt update