Search code examples
phpmysqlsymfonyfosuserbundle

Symfony fos:user:create through error "could not find driver", (Xampp with multiple verison of PHP)


  • INTRODUCTION:

I am in a Symfony Project with PHPStorm. I'm trying to create a fos user on DB (xampp MySQL).

Symfony CLI version v4.21.6 Composer version 1.10.19

C:\Program Files\Symfony\name_projectFolder>php -v
PHP 8.0.0 (cli)

C:\Program Files\Symfony\name_projectFolder>symfony php -v
PHP 7.4.14 (cli)

With the first command we see the actual php version (8.0.0) that is used by default, but my project doesn't support it, so i installed another one (on xampp folder with the correct procedure) and told to the project to use this new version (7.4.14) instead of the default one.

TO SET which php version the project should use:

C:\Program Files\Symfony\name_projectFolder>echo 7.4 > .php-version

TO SEE the list of PHP versions that we have:

C:\Program Files\Symfony\name_projectFolder>symfony local:php:list

screenshot - result of the command "symfony local:php:list"

The highlighted number on the left is the actual version that the project is using. The asterisk on the right indicates the default system PHP version.

(INFO: If you want to use a normal command you need to specify which PHP version it should refer to, in order to run it. To do so just add before the normal command the "symfony" word because it will use the project settings and not the system ones.)

  • START with the procedure to CREATE the fos user:

(as we said before, we use the word "symfony" to "tell" to the command to use the 7.4 PHP version, keep in mind that normally you don't to this)

C:\Program Files\Symfony\name_projectFolder>symfony php bin\console fos:user:create

you'll get this error: screenshot - error showed

in a few words "An exception occurred in driver: could not find driver"


Solution

  • SOLUTION

    Because you have two PHP versions, in the new one you need to enable the pdo_mysql extension that normaly is not.

    STOP the Apache Server in the XAMPP controller.

    just go in the folder C:\xampp\php7_4 and open the file php.ini

    search (CTRL+F) for pdo_mysql and uncomment/remove the ";"

    BEFORE ;extension=pdo_mysql

    AFTER extension=pdo_mysql

    SAVE the changes

    START the Apache Server and re-run the symfony php bin\console fos:user:create command and it will work !!