Search code examples
mysqllaravelpdomariadbrhel

pdo mysql driver in RHEL 7 is not working


I'm trying to run my Laravel 5.7 app but will always get the error Could not find driver when trying to run a query in my page.

Here's portion of my .env code:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306

Anyway instead of using mysql, we use MariaDB instead. I can confirm that mariadb is running without any problem because if I run mysql -u root -p in my terminal, I can connect to my MariaDB. Here's what my welcome message will be upon successfully log into my MariaDB.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 44
Server version: 10.2.8-MariaDB MariaDB Server

Running phpinfo() will return this:

PDO support enabled
PDO drivers pgsql, sqlite

MySQL driver for PDO    George Schlossnagle, Wez Furlong, Ilia Alshanetsky, Johannes Schlueter
MySQLi  Zak Greant, Georg Richter, Andrey Hristov, Ulf Wendel
MySQLnd Andrey Hristov, Ulf Wendel, Georg Richter, Johannes Schlüter

But I can confirm my /opt/rh/rh-php71/root/usr/lib64/php/modules folder contains pdo_mysql.so, pdo.so,mysqli.so and mysqlnd.so

And also my /etc/opt/rh/rh-php71/php.d folder contains 30-pdo_mysql.ini on which it contains just one line, extension=pdo_mysql.so

So why isn't my pdo mysql running?


Solution

  • It turns out I need to restart my php-fpm. Upon googling and googling, I still can't find the exact name of my php-fpm service, so I did sudo find | grep fpm and found out that my php-fpm service name is rh-php71-php-fpm

    So I run sudo service rh-php71-php-fpm restart and sudo systemctl restart httpd and now mysql is listed under PDO drivers, and I can run my apps successfully.

    Seriously, why did different versions of Linux have different names of the same thing?