Installing Doctrine

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Friends! Welcome back to the third episode in our starting in Symfony 4 series! We've done some really cool stuff already, but it's time to explore deeper in an epic search for intelligent life... and also.. and database! Yea - what good is our cool interstellar space news site... without being able to insert and query for data?

But... actually... Symfony does not have a database layer. Nope, for this challenge, we're going to rely one of Symfony's BFF's: an external library called Doctrine. Doctrine has great integration with Symfony and is crazy powerful. It also has a reputation for being a little bit hard to learn. But, a lot has improved over the last few years.

Code with Me!

If you also want to be best-friends-forever with Doctrine, you should totally code along with me. Download the course code from this page. When you unzip it, you'll find a start/ directory that has the same code that you see here. Open the file for details on how to get the project setup... and of course, a space poem.

The last step will be to open a terminal, move into the project and run:

php bin/console server:run

to start the built in web server. Then, float over to your browser, and open http://localhost:8000 to discover... The Space Bar! Our inter-planetary, and extraterrestrial news site that spreads light on dark matters everywhere.

In the first two episodes, we already added some pretty cool stuff! But, these articles are still just hard-coded. Time to change that.

Installing Doctrine

Because Doctrine is an external library, before we do anything else, we need to install it! Thanks to Symfony flex, this is super easy. Open a new terminal tab and just run:

composer require doctrine

This will download a "pack" that contains a few libraries, including doctrine itself and also a migrations library to help manage database changes on production. More on that soon.

And... done! Hey! That's a nice message. Because we're going to be talking to a database, obviously, we will need to configure our database details somewhere. The message tells us that - no surprise - this is done in the .env file.

Configuring the Database Connection

Move over to your code and open the .env file. Nice! The DoctrineBundle recipe added a new DATABASE_URL environment variable:

22 lines .env.dist
... lines 1 - 15
###> doctrine/doctrine-bundle ###
# Format described at
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml

Let's set this up: I use a root user with no password locally. Call the database the_spacebar:

22 lines .env.dist
... lines 1 - 15
###> doctrine/doctrine-bundle ###
# Format described at
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml

Of course, this sets a DATABASE_URL environment variable. And it is used in a new config/packages/doctrine.yaml file that was installed by the recipe. If you scroll down a bit... you can see the environment variable being used:

# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
... lines 10 - 17
# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(resolve:DATABASE_URL)%'
... lines 20 - 31

There are actually a lot of options in here, but you probably won't need to change any of them. These give you nice defaults, like using UTF8 tables:

... lines 1 - 7
... lines 10 - 12
charset: utf8mb4
... lines 14 - 31

Or, consistently using underscores for table and column names:

... lines 1 - 7
... lines 9 - 19
... line 21
naming_strategy: doctrine.orm.naming_strategy.underscore
... lines 23 - 31

If you want to use something other than MySQL, you can easily change that. Oh, and you should set your server_version to the server version of MySQL that you're using on production:

... lines 1 - 7
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
... lines 13 - 31

This helps Doctrine with a few subtle, version-specific changes.

Creating the Database

And... yea! With one composer require command and one line of config, we're setup! Doctrine can even create the database for you. Go back to your terminal and run

php bin/console doctrine:database:create

Say hello to your new database! Well, it's not that interesting: it's completely empty.

So let's add a table, by creating an entity class.

Leave a comment!

  • 2020-06-22 Victor Bocharsky

    Hey Jelle,

    Thank you for sharing your solution with others! Glad it helped you :)


  • 2020-06-20 Jelle Schouwstra

    Thank you Ryan, I was having this problem too :)
    I have PHP 7.4 atm and running sudo apt-get install php7.4-mysql did the trick for me!

  • 2020-06-08 weaverryan

    Hi Dominik!

    I wanted to apologize for never replying to this! Your comment somehow got stuck as "pending" and we missed it :/. If you're still having issues, let me know. It definitely looks weird as symfony/orm-pack requires doctrine/orm so that package absolutely *should* already be installed.


  • 2020-06-08 weaverryan

    Hey Andre Van Veen!

    Sorry for the SUPER slow reply - your comment got stuck in a "pending" state for some reason and we missed it!

    Also, sorry about the problem - you're 100% correct! While this isn't a tutorial about getting MySql installed, I don't even mention it - which I *absolutely* should. My apologies for your making you lose time on this - but it's really good feedback. We'll be recording the Symfony 5 Doctrine tutorial soon and I'll make sure to do a better job there.


  • 2020-05-21 Andre Van Veen

    C'mon Ryan!?$%@# This webcast is suppose to be for noobs like me. A very important detail was left out of the first chapter which is that MYSQL has to already be installed and running. I spent 2 days trying to figure this out. If it's not installed you will get 2002 - connection refused error. And since this was such a basic and fundamental misstep there is no advice on the web to help fix it.

  • 2020-05-14 Dominik

    Hi. I try to install orm-bundle in symfony 5 but all the time I have this error:

    !! In Configuration.php line 304:
    !! The doctrine/orm package is required when the doctrine.orm config is set.

    My composer pack:

    "name": "symfony/skeleton",
    "type": "project",
    "license": "MIT",
    "description": "A minimal Symfony project recommended to create bare bones applications",
    "require": {
    "php": "^7.2.5",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "sensio/framework-extra-bundle": "^5.1",
    "symfony/asset": "5.0.*",
    "symfony/console": "5.0.*",
    "symfony/dotenv": "5.0.*",
    "symfony/expression-language": "5.0.*",
    "symfony/flex": "^1.3.1",
    "symfony/form": "5.0.*",
    "symfony/framework-bundle": "5.0.*",
    "symfony/http-client": "5.0.*",
    "symfony/intl": "5.0.*",
    "symfony/mailer": "5.0.*",
    "symfony/monolog-bundle": "^3.1",
    "symfony/notifier": "5.0.*",
    "symfony/orm-pack": "*",
    "symfony/process": "5.0.*",
    "symfony/security-bundle": "5.0.*",
    "symfony/serializer-pack": "*",
    "symfony/string": "5.0.*",
    "symfony/translation": "5.0.*",
    "symfony/twig-pack": "*",
    "symfony/validator": "5.0.*",
    "symfony/web-link": "5.0.*",
    "symfony/webpack-encore-bundle": "^1.7",
    "symfony/yaml": "5.0.*"
    "require-dev": {
    "symfony/debug-pack": "*",
    "symfony/maker-bundle": "^1.0",
    "symfony/profiler-pack": "*",
    "symfony/test-pack": "*"
    "config": {
    "preferred-install": {
    "*": "dist"
    "sort-packages": true
    "autoload": {
    "psr-4": {
    "App\\": "src/"
    "autoload-dev": {
    "psr-4": {
    "App\\Tests\\": "tests/"
    "replace": {
    "paragonie/random_compat": "2.*",
    "symfony/polyfill-ctype": "*",
    "symfony/polyfill-iconv": "*",
    "symfony/polyfill-php72": "*",
    "symfony/polyfill-php71": "*",
    "symfony/polyfill-php70": "*",
    "symfony/polyfill-php56": "*"
    "scripts": {
    "auto-scripts": {
    "cache:clear": "symfony-cmd",
    "assets:install %PUBLIC_DIR%": "symfony-cmd"
    "post-install-cmd": [
    "post-update-cmd": [
    "conflict": {
    "symfony/symfony": "*"
    "extra": {
    "symfony": {
    "allow-contrib": false,
    "require": "5.0.*"

    What is wrong what else shall I add?
    Thank you.

  • 2020-03-09 weaverryan

    Hey @Lars!

    I think I know this error. This usually that your database connection information is wrong. It could be that you don't have a database running at all - or that the host name / IP address in the DATABASE_DSN is incorrect? Because you're using Docker, my guess is that either:

    A) You don't have the php container networked correctly to the database container
    B) You DO have it linked correctly, but you need to update DATABASE_DSN to point to whatever host name the database container is exposed on.

    Let me know if this helps!


  • 2020-03-06 Lars

    I'm using symfony 5 and docker and seem to keep getting this error:
    SQLSTATE[HY000] [2002] Connection refused
    What might be causing this?

  • 2019-12-18 Victor Bocharsky

    Hey Celli,

    No problem! Let's try to figure and solve your problem out ;) First of all, you you need to install MySQL not on the local web server but on your laptop! "apt-get" is Ubuntu package manager, on Mac you can use "brew", here's the link to the docs how to install it: . After you installed it, you can type "brew install mysql" in your terminal to install the MySQL server on your computer. Then, you would need to start the MySQL server (see the command output how to do this) and also specify correct credentials to the just installed and run MySQL server in .env file and that's it. Both built-in web server (bin/console server:run) and MySQL server are separate servers.

    Does it make sense for you? If you still have any questions - please, ask!


  • 2019-12-17 Celli

    Hi. I get the same error. Apologies if this is obvious but I am a newbie. The thing I don't understand from your answer is:
    if I use the built-in server using the command "bin/console server:run", how do I log in to it in order to run the commands like "apt-get" to install mysql on this local server?! I am on Mac.

  • 2019-10-22 Dung Le

    Thank you!

  • 2019-10-14 weaverryan

    Hey Jan Kowal!

    I did some research on this and found out the problem. The issue is with nexylan/slack-bundle 2.2. They... did something a little silly... which broke things slightly :) () However, you should not see the issue if you're using the same version of the bundle that ships with the code-download (which is 2.0). So basically, there are two ways to solve this :)

    1) Just download the starting code from this tutorial and run composer install. This will download version 2.0 of the bundle, which works just fine.

    2) Or, if you did run a composer update then (as you mentioned), you can comment-out this line in config/services.yaml:

    # ...

    # you can commnent this line out with NexySlackBundle 2.2, as this alias is already added by the bundle
    # Nexy\Slack\Client: '@nexy_slack.client'

    Let me know if this helps!


  • 2019-10-11 Victor Bocharsky

    Hey Rafael,

    Hm, interesting... Could you do "rm -rf vendor/" and then "composer install"? Does it helps? If not, probably try to upgrade the library with "composer update doctrine/dbal".

    If you still have this error, could you tell us your doctrine/dbal version installed? You can do it with "composer info doctrine/dbal". And did you download the course code from SymfonyCasts? In what directory are you: start/ or finish/ ?


  • 2019-10-10 Jan Kowal

    Same here, with

    composer install


    composer update

    .Tried to remove vendor dir. I was doing courses one by one, reached "Symfony Security: Beautiful Authentication, Powerful Authorization", paused for 3-4 weeks, then tried to run `composer update`. Works when I commented `Nexy\Slack\Client: '@nexy_slack.client'` in services.yaml

  • 2019-10-08 Rafael Ferreira


    I got this error after php bin/console doctrine:database:create

    In MariaDb1027Platform.php line 12:

    Attempted to load class "MySqlPlatform" from namespace "Doctrine\DBAL\Platforms".
    Did you forget a "use" statement for another namespace?

    Can someone help me?

  • 2019-10-07 Victor Bocharsky

    Hey Dung,

    Good question! Definitely you need to create an entity first, and then let Doctrine to do the low level set up for you. The reverse is useful for legacy projects only, when you have a DB already and want to migrate your project to Doctrine base on your table.


  • 2019-10-06 Dung Le

    Hello there,

    When building a project from scratch, what is a preferred way - to design and create database first then generate entity classes ( or create entity first then migrate it into database?

    Thank you!

  • 2019-10-04 Victor Bocharsky

    Hey Muslax,

    In what directory of downloaded code you are: start/ or finish/? Btw, did you run "composer install" or "composer update" to bootstrap the project locally?


  • 2019-10-03 muslax

    Please advise, same problem with me. I use the downloaded course code.

  • 2019-09-23 weaverryan

    Hey @jp!

    Hmm. Are you downloading the course code and getting this error? Or installing the Slack library from the previous tutorial ( Let me know!


  • 2019-09-18 jp

    Can you Actually update the code so it matches Symfony 4, The Slack bundle is not useable with S4 and LTS is abondoned. Keep getting errors like

    Executing script cache:clear [KO]


    Script cache:clear returned with error code 1


    !! In ContainerBuilder.php line 1055:

    !! Circular reference detected for service "nexy_slack.client", path: "nexy_sl

    !! ack.client -> Nexy\Slack\Client -> nexy_slack.client".


    Circular reference detected for service "nexy_slack.client", path: "nexy_slack.client -> Nexy\Slack\Client -> nexy_slack.client".

  • 2019-06-24 Victor Bocharsky

    Hey Su,

    To download the course code - you need to be a paid subscriber (subscribe to our monthly or yearly subscription plan) or course owner (buy access to the exact this course only). Unfortunately, we do not provide partial access to separate videos only, you need to buy access to the entire course at least.

    For your information, you can see "Buy Access to Course" above this video. Also, we always make a few first videos free, so you just need to go to further chapters to see the link how to buy the course instead of the video, e.g: . Or, just go to the course overview page: :)

    To recap, if you want to get access to this course - here's the direct link to possible options:


  • 2019-06-21 Su Chunyu

    HI Im just being curious about how can i subscribe this video to download the course code..

  • 2019-05-22 Victor Bocharsky

    Yo Kenan!

    Well, I'm not sure about *your* fix, but I can explain what happened :) The problem is that with composer you should require packages in format: "vendor-name/package-name", i.e. separate vendor name and package name with "/". So, if you want to install Doctrine ORM pack for Symfony - you should execute *this* command:
    $ composer require symfony/orm-pack

    But! Symfony has a special package called Flex that is Composer plugin which has such feature as package aliases, you can check them here: - where you can see that "symfony/orm-pack" has a few aliases like "doctrine", "orm", etc. It means, that if you have that Flex installed in your project, you can require packages by aliases instead of typing the full package name.

    The error you see means that you don't have Flex installed in your project. So, if you do the next first:
    $ composer require symfony/flex

    Then you would be able to execute this:
    $ composer require doctrine

    without that error.


  • 2019-05-20 Kenan

    Hello Kenan here again, I want to share what happens in both Windows 10 x64 and Fedora 30
    When I tried to run:

    composer require doctrine

    I got the following:

    Installation failed, reverting ./composer.json to its original content.

    The ' URL could not be accessed: HTTP/1.1 400 Bad URI

    After tons of searching entire web I found the solution by adding this to composer.json:

    "repositories": [
    "type": "composer",
    "url": ""
    "packagist": false

    I need to do that just once in any project.
    So why that happened ?

  • 2019-05-20 Victor Bocharsky

    Hey Carlos,

    I like your initial idea with connecting to it dynamically on KernelRequest, you should try it. Unfortunately, don't know if there is any better solution. Good luck with it!


  • 2019-05-20 Victor Bocharsky

    Hey Ali,

    > if i creates the DB schema myself and drop it using d:d:d --force and recreate it again with the create command it does work

    So, does it work for you now? It looks like you were able to recreate the DB schema after dropping it with "d:d:d --force" command, right?


  • 2019-05-16 Carlos Eduardo

    Hi Victor, yes, that's the idea. Each user will have his own database. But then I need to make every one to connect dynamically. I think that with a KernelRequest subscriber is the best option.

    If anyone finds out a better solution, please, tell me. Thanks!!

  • 2019-05-16 Ali Mhanna

    Hey Victor,
    thanks you for you answer i am using bin/console d:d:c but its not working at all in my app but i tried to install a clean symfony 3.4 on my pc and the cmmand worked so i guess somthing is wrong wth my setting.
    if i creates the DB schema myself and drop it using d:d:d --force and recreate it again with the create command it does work so do you have any hint what is causing the problem ?

    Thanks in advance

  • 2019-05-16 Victor Bocharsky

    Hey Carlos,

    Hm, I see, that's a tough question.

    > And will each user really be totally isolated from others?

    I don't think it's possible, though I'm not exactly sure, have never tried something similar before. You probably could look into direction of Symfony Voters or ACL where you will check if the current user is allowed to perform the action. But anyway, it might be tricky to check the actual query. I think to make every user really isolated - you need to create a separate DB for each user along with MySQL user with it's own credentials, and assign the MySQL user to a Symfony user so you could check if user is allowed to connect to the DB he intends to connect.


  • 2019-05-16 Victor Bocharsky

    Hey Ali

    What command do you run? :) Have you tried:
    $ bin/console doctrine:database:create

    If so, what's the output of this command for you?

    Please, don't confuse this command with another one that creates DB schema:
    $ bin/console doctrine:schema:create


  • 2019-05-15 Ali Mhanna

    i am using mysql v.5.7 with dbal v.2.5 even if the is server_version: '5.7' but i am still unable to create the database with the command

    An exception occurred in driver: SQLSTATE[HY000] [1049] Unknown database 'symfony'

  • 2019-05-13 Carlos Eduardo

    Hi Victor. Thank you, but in this case I would have only a fixed number of connections. What I'm intending to do is to have a completely dynamic structure, where clients could sign up and have I fresh new database. I don't know how much databases I would have at first. Thanks.

  • 2019-05-13 Victor Bocharsky

    Hey Carlos,

    Hm, I think you need to configure a few database connections and Entity Managers in your case, see this article in the docs for more information: . Then you'll just need to implement a custom logic that will decide what entity manager to use and that's it.

    I hope this helps!


  • 2019-05-10 Carlos Eduardo

    What if I wanted to change the database connection after the application has started?

    I have a project here where I will have several databases (or schemas), and I need to switch between each one taking into consideration the user that was logged in (in another symfony application with a static database connection to this "central" database).

    I thought about using a subscriber for KernelRequest. But how would I make the connection of doctrine dynamically? And will each user really be totally isolated from others? Thanks!!

  • 2019-04-04 Victor Bocharsky

    Hey Mike,

    Thank you for this hint! Yes, it appears if you use Symfony Flex that may do routine things for you from the recipe for some bundles, you can check what will be done with the official repo for contrib bundles: or just press y and validate the diff with "git diff" command. That's why it's recommended to commit changes before installing new bundles, it will help you to validate changes easier.


  • 2019-04-02 Mike

    Just an info, this dialog seems to be new when installing doctrine via composer:

    Symfony operations: 3 recipes (d1677be98e0980609549e3b67c08b1cb)
    - WARNING doctrine/doctrine-cache-bundle (>=1.3): From
    The recipe for this package comes from the "contrib" repository, which is open to community contributions.
    Review the recipe at

    Do you want to execute this recipe?

    [y] Yes
    [n] No
    [a] Yes for all packages, only for the current installation session
    [p] Yes permanently, never ask again for this project
    (defaults to n):

    If you get this, just hit y to confirm this dialog.

  • 2019-03-20 Victor Bocharsky

    Hey Jorge!

    We're sorry to see you disappointed! Sometimes we do not explain simple things, like things that should be obvious at some point. In some cases we suppose that most of users should know these things already. But that's exactly why we have comments below *every* video and we track all the comments with our team and provide support for any screencast related questions that are not clear to users.

    We would be happy to assist you with your problem, but could you clarify what problem exactly do you have? Do you see any errors? What exactly the errors? If you have an error with "doctrine:database:create" command - most probably it's due to credentials problem, but it's difficult to say more without knowing the error message you have.


  • 2019-03-19 Jorge Toledo

    i am very dissapointed in this chapter the create database command do not work in all cases and for noobs like me you do not give options, very bad because i pay for a product that works and an advice is not so hard to make by experts like you at SymfonyCasts

  • 2019-03-12 Victor Bocharsky

    Hey Mike,

    Thank you for sharing it for our MariaDB users!


  • 2019-03-09 Mike

    Hint for MariaDB Users, change server_version from this:
    server_version: '5.7'
    to your corresponding server version (By example 10.3.13):
    server_version: 'mariadb-10.3.13'

  • 2019-02-27 Andy Ndubuisi

    No problem, just an extra solution.

  • 2019-02-25 Diego Aguiar

    Hey Andy Ndubuisi

    Thanks for sharing it! But I believe this should not happen if you don't change the default install configuration of MySql


  • 2019-02-25 weaverryan

    Hey Maarten!

    Ah, excellent! I'm pretty sure I know what the issue is now. When you executed the site via a browser (you're using Apache for this, right? Not the built-in PHP web server?), you ARE correctly using the PHP that was installed with MAMP and this version of PHP *does* have PDO & MySQL all set up. But, when you execute PHP from the command line, I believe it is using some *other* PHP on your system - and that PHP install does *not* have the same PDO extensions setup.

    If I'm correct, the fix is to make your command line using the correct version of PHP. This can be tricky, you need to:

    A) First, find the path to the correct PHP binary from MAMP
    B) Update some "paths" stuff in Windows so that it uses that PHP executable from MAMP, instead of whatever other one it's using.

    This stuff can be annoying - it's really some of the most annoying setup stuff :/. Here's some reference info -

    Let me know what you find out!


  • 2019-02-24 Andy Ndubuisi

    For everyone that has the connection refused error:
    Add the following parameter to doctrines.yaml: "unix_socket: /path/to/mysql.sock"
    For MAMP is this: /Applications/MAMP/tmp/mysql/mysql.sock

    Symfony doctrine docs:

    It took me hours to figure this out, hope this helps someone.

  • 2019-02-20 Maarten

    Hi weaverryan

    Maybe because i'm from Belgium ;-).

    1) I'm using Microsoft Windows 10.

    2) Now I do find some info about PDO and MySQL.

    a) PDO:

    Mysqlnd : API Extensions mysqli,pdo_mysql (enabled)
    PDO: PDO drivers sqlite, mysql (enabled)
    pdo_mysql: Client API version mysqlnd 5.0.12-dev - 20150407 - $Id: ... $
    pdo_sqlite: SQLite Library 3.20.1

    b) MySQL

    mysqli.allow_local_infile On On
    mysqli.allow_persistent On On
    mysqli.default_host no value no value
    mysqli.default_port 3306 3306
    mysqli.default_pw no value no value
    mysqli.default_socket no value no value
    mysqli.default_user no value no value
    mysqli.max_links Unlimited Unlimited
    mysqli.max_persistent Unlimited Unlimited
    mysqli.reconnect Off Off
    mysqli.rollback_on_cached_plink Off Off

    PDO Driver for MySQL enabled
    Client API version mysqlnd 5.0.12-dev - 20150407 - $Id: .... $

  • 2019-02-20 weaverryan

    Hey Maarten!

    Sorry for the slow reply again - Disqus is not letting your comments through initially... for some reason (only you!) - :/

    > At first I was using php bin/console server:run
    Now I'm just using my MAMP server and installed "composer require symfony/apache-pack" since it wouldn't the links via route.

    This may not be related, but this is a bit strange. The bin/console server:run sorta "guarantees" that everything will be set up correctly so that you can link, etc. I'm not saying there is a problem here... but something "smells" strange, if you know what I mean :).

    I'm still not sure what's going on, as I believe MAMP should come with PDO extension installed. Two more questions:

    1) What operating system are you using?

    2) If you open the public/index.php file, and put phpinfo();die; right at the top (right after the opening PHP tag), does that page mention anything about PDO or MySQL?


  • 2019-02-20 Maarten

    Hi weaverryan

    It is not showing anything about PDO or MySQL when I run php -i..


  • 2019-02-18 Maarten

    Hi weaverryan

    php -v
    Gives the same as I use in MAMP( 7.2.10 )

    php -i
    Gives a lot of details, but I don't seem to find anything about PDO or MySQL.

    At first I was using php bin/console server:run
    Now I'm just using my MAMP server and installed "composer require symfony/apache-pack" since it wouldn't the links via route.

    Thank you,

  • 2019-02-18 weaverryan

    Hey Maarten!

    Sorry for the slow reply - Disqus marked your comment as pending for some reason :/.

    So yes, you can totally use MAMP - MAMP is great :). And MAMP should come with the PDO/MYSQL extensions. Question: are you following the tutorial exactly and using the built-in php web server? I mean, running php bin/console server:run to serve the site? If so, it's possible that, at the command line, you're using a different php binary - not the one from MAMP (it's just a guess). Even if you are using Apache or Nginx, when you run the "php bin/console doctrine:database:create", that could be using the wrong PHP binary. Try this (from the command line):

    php -v
    php -i

    The first will print the version of PHP - double-check that it's the version you expected to get from MAMP. The second will print the "phpinfo()" information to the terminal. Do you see anything about PDO or MySQL in there?


  • 2019-02-18 Maarten

    Hey weaverryan

    I'm working via MAMP.
    Can't I create a Symfony project on that?

    Thought MAMP would have every extension.

    I'm not using Ubuntu, just working on Windows 10 with MAMP.

    Could you help ?

    Thank you,

  • 2019-02-14 Maarten

    Hi weaverryan

    Thank you for your response!

    I'm working on Windows 10 and have no subsystems installed.
    Don't really remember how that I installed PHP :').
    Maybe I did it wrong since i'm no expert on the technical side of installing all those things.
    Normally i'm working with MAMP (for Drupal, etc..) and this is the first time using Git as well..

    It would probably be best to uninstall PHP and start all over?

    BTW, really like how you make your tutorials!

  • 2019-02-14 weaverryan

    Hey Maarten!

    Ah! I know this pesky error! The issue is that you're missing a PHP extension - probably the pdo and/or pdo_mysql extensions. *How* you install these varies on every operating system, unfortunately. For example, if you're using Ubuntu, then it'll be something like sudo apt-get install php7.2-mysql (depending on PHP version).

    Let me know if that helps! And if you're having trouble finding how to install the extension, tell us your operating system and how you installed PHP and we'll do our best to help :).


  • 2019-02-13 Maarten


    I followed the course from step 1.

    But when creating the database I get the next error:
    $ php bin/console doctrine:database:create

    In AbstractMySQLDriver.php line 106:

    An exception occurred in driver: could not find driver

    In PDOConnection.php line 31:

    Could not find driver

    In PDOConnection.php line 27:

    Could not find driver

    I've haven't got any clue what's going wrong..

  • 2019-01-07 weaverryan

    Hey Emin@

    For this specific tutorial, it should be fine to continue using the code from the last course. I try to avoid it, but sometimes I DO update code between courses. However, in this case, there weren't any changes between them :).


  • 2019-01-07 Emin


    Do i need to download the course code or can i keep working with the code from the last course?


  • 2018-12-31 Victor Bocharsky

    Hey Olivier,

    Thank you for your feedback!


  • 2018-12-29 Olivier Roche


    Thanks a lot Victor, I will investigate on those, and again congratulations for your tutorials that are awesome,



  • 2018-12-28 Victor Bocharsky

    Hey Olivier,

    Oh, probably you need to upgrade PhpMyAdmin, but if it comes with MAMP - it probably difficult to do. Or maybe you need to tweak something in its configuration, not sure. I'd recommend you to try another MySQL client, you can take a look at my favorite or at official .


  • 2018-12-27 Olivier Roche

    Hi Victor,

    Thanks for your reply, that worked, my only concern is that through phpmyadmin I don't see the database created and neither informations that were registered through Doctrine. Would I be able to access those infos through phpmyamdin or is it normal that I dont see them ?


  • 2018-12-27 Victor Bocharsky

    Hey Olivier,

    Hm, what PHP and MySQL versions do you use? I think you just need to upgrade PHP or downgrade MySQL. Most probably you're on MySQL 8 - if so, take a look at this suggestion:


  • 2018-12-21 Olivier Roche


    When trying to create the database, I have this error :
    In AbstractMySQLDriver.php line 125:

    An exception occurred in driver: SQLSTATE[HY000] [2054] The server requeste
    d authentication method unknown to the client

    In PDOConnection.php line 50:

    SQLSTATE[HY000] [2054] The server requested authentication method unknown t
    o the client

    In PDOConnection.php line 46:

    SQLSTATE[HY000] [2054] The server requested authentication method unknown t
    o the client

    In PDOConnection.php line 46:

    PDO::__construct(): The server requested authentication method unknown to t
    he client [caching_sha2_password]

    In my .env : DATABASE_URL=mysql://root:@

    I have MAMP PRO pointing to the folder with MySQL 'Allow network access to MySQL', but still not working ...

    Any idea where the problem can come from ?



  • 2018-10-26 Diego Aguiar

    Thanks for sharing your solution!

  • 2018-10-26 Teolan

    For me is work only if I do this 3 steps:

    1. I add this two lines to my.cnf

    2. restart mysql server

    3. Create a new user/password and change it in .env file

    Without the step 3, the root user is keeping the Authentication Type: "caching_sha2_password"
    After create a new user, then this user will use Authentication Type: "mysql_native_password"

    This all is because of new Authentication Type in MySql 8.0.13 Server
    but will be supported in a future PHP release by default.

  • 2018-10-01 Diego Aguiar

    Hey Quang nguyen

    I can see that you request a password for login in, can you double check that you provided your DB's password? Since you are using Symfony4, your DB connection parameter lives in ".env" file at the root of your project


  • 2018-09-28 Quang nguyen


    I have some trouble when using "php bin/console doctrine:database:create". My error do not like anyone below. It is "An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)".

    I am not sure what is happening now. I am using "root" user in Mysql server 8.0.12, and I allow it to performs all tasks. Currently, I am running symfony 4 on Homestead with vagrant on VirtualBox. Do you have any ideas about this error?

  • 2018-09-28 Victor Bocharsky

    Hey Thao,

    Great catch! And thanks for sharing it we others!


  • 2018-09-28 Thao Truong

    Figured it out. I had to run this query:
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

  • 2018-09-28 Thao Truong

    I use mysql 8.0 and I keep getting this error:
    "php bin/console doctrine:database:create
    2018-09-28T01:27:27+00:00 [error] Error thrown while running command "doctrine:database:create". Message: "An exception occurred in driver: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client""

  • 2018-09-06 shing

    This is brilliant. Full respect to the symfony team for being so patient.

    You made alot of great points which sent me down the road of looking at bundle vs bundleless and ways people organise code. Its not a trivial subject. It is alot to think about and have something that can make sense to me and others but also not overcomplicate and overwhelm.

    But i think overall, maybe there is a middle ground, where things r organised in transportable domains.

    👍Thank u and keep up the good stuff!

  • 2018-09-06 weaverryan

    Hey Mylan!

    Oh no! That's not a fun error to have! Here's what's going on:

    1) In your .env file, that DATABASE_URL config you posted is your connection parameters to your database. The current value - which is the config I use for my computer - says that you have a database running on your local machine (ip address and you connect to it with the user "root" and no password.

    2) The error -"Connection refused" is usually because you do not have a MySQL server running locally. Have you installed MySQL? If you did, make sure it's running :).


  • 2018-09-06 Mylan


    I've a error that say's " An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused " after i run the comment ./bin/console doctrine:database:create . And in PHPstorm if have the comment "DATABASE_URL=mysql://root:@
    " to connect the DB.

    Please help me out

  • 2018-09-06 Victor Bocharsky

    Hey Shing,

    Yeah, probably no glob patters accepted in this part of config, so you would need to define all the mappings manually. Well, if you can see a pattern of where your entities live - you probably can create a compiler pass and write a custom PHP code that will iterate over all the folders in src/ and look for Entity/ folder. And if it found - add it as mapping. I *think* it should work, but it sounds like a hacky way to dynamically do what you want. See for more info.

    Another question, why do you need to separate your entities? It's not a good practice because most probably your entities are tied with each other, i.e. have relations. For example, are you sure that all your "post" entities do not relate to "profile" entities and "comment" entities? Probably no. I bet your Post entity has OneToMany relation to Comment entity, etc. so they have hard relations. That's why the best practice is to have one folder for all your entities in simple projects, just do not overcomplicate things. But of course, if those entities in different folders are not related to each other - it makes sense then, but it's really a rare case for big and complex applications.


  • 2018-09-05 shing

    Hi Diego,

    Cool. Should have tested it. I see now, if the mappings pointing in the right way getDoctrine()->getRepository() doesnt work.

    So if i have multiple folders like
    src/UserProfile/Entity ,

    What is a good way of defining all the mappings? It does not seem to accept glob patterns

    Thanks so much

  • 2018-09-04 Diego Aguiar

    He @shing

    You are correct, if you are not using the default folder for your entities, then you will have to specify where they live so Doctrine can find them and do its job :)


  • 2018-09-04 shing


    I'm wondering what this config means.

    # config/packages/doctrine.yaml

    under it says
    'Explicit definition of all the mapped entities is the only necessary configuration for the ORM and there are several configuration options that you can control. The following configuration options exist for a mapping:'

    I know that this mapping affects bin/console make:entities --regenerate
    And also if u have multiple entity_managers.
    Does it have an effect if u have entities outside of dir: '%kernel.project_dir%/src/Entity'
    Do i have to map all folders that contains entity?

    thanks in advance

  • 2018-06-12 Diego Aguiar

    Hey Leora Wenger

    Using another port for your DB connection is not considered an error, it's just a detail of the server, but now that you know how to solve this problem, you shouldn't be too afraid of configuring a DB in another computer :)

    Have a nice day.

  • 2018-06-11 Leora Wenger

    Diego, yes, at least I am speeding along with the Doctrine series now! But I think the original database connection issue is related to MAMP. I am afraid that even if I uninstalled it, there might something remaining in my system that might make the problem worse. So for now, I will run it whenever I do database connections on this mac (the password for the mysql on the command line and the mysql in MAMP are different - not changing anything now - the MAMP one is the one working in the .env file).

  • 2018-06-11 Diego Aguiar

    Hmm, interesting, so it uses a different port. Sorry I can't offer you a tutorial about it, I'm not a Mac user :p
    but, look's like you already nailed it.
    By the way, I believe you can set up any user/password you like now


  • 2018-06-11 Leora Wenger

    Finally figured something out - if I run MAMP, and I use the password that MAMP suggests, and I set the port to 8889 (because that showed up for mysqld when I ran 'sudo lsof -i -n -P | grep TCP' ). And for the first time it said created the database 'the_spacebar' - can someone offer a course on how to configure all these different ports?

  • 2018-06-11 Leora Wenger

    I got rid of the password all together for now, but that did not seem to help. Just makes it easier to login at the command line.

  • 2018-06-11 Leora Wenger

    It *is* password. Don't worry, I don't use that in real life cases. Just for learning.

    "If that's not the case, is there a chance that your mysql is listening to other port than default (3306)?" - how do I test this? I can get MAMP to work. I also tried a PDO Sqlite tutorial, and that one worked as well. What else can I try?

  • 2018-06-11 Diego Aguiar

    Hey Leora Wenger

    You need to change the "password" part for your real password (unless the word password is actually your password). If that's not the case, is there a chance that your mysql is listening to other port than default (3306)?

  • 2018-06-11 Leora Wenger

    Hi, Victor. So now I can get into mysql on the command line using:
    mysql -u root -p
    But this still gives the same error (this is what is in the .env file)

  • 2018-06-11 Victor Bocharsky

    Hey Leora,

    Hm, interesting.. do you have "resolve" filter in url: "'%env(resolve:DATABASE_URL)%'"? I suppose you have in your .env the next, right?


    Btw, could you show the command how you connect to the database in your command line? Did you enter any password?


  • 2018-06-08 Leora Wenger

    I am trying to connect to the database, but I get the same error each time I try: An exception occurred in driver: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
    I was able to log into mysql with my password on the command line, but it won't let me connect with the code in the tutorial.

  • 2018-06-07 Diego Aguiar

    Hmm, interesting. Double check that "mysql.dll" exists inside the "ext" folder.
    Do you have this problem only for that dependency? Maybe you don't have MySql installed

  • 2018-06-07 Daniel

    Hi, Diego! Thanks for your answer. In fact I'm using windows.

    I've done some progress: I've installed wamp server and added inside php.ini:

    However I get this message on running bin/console server:run:

    PHP Warning: PHP Startup: Unable to load dynamic library 'mysql' (tried: ext\mysql (The specified module could not be found.), ext\php_mysql.dll

  • 2018-06-06 Diego Aguiar

    Hey Daniel

    It depends on your OS, if you use Linux like me, you can take advantage of the "apt-get" package for installing your libraries.
    Check this post:
    I haven't followed it, but I believe it can help you in getting started.


  • 2018-06-06 Daniel

    Hi, I don't have the driver for MySQL. I'm new to databases. Which is your preferred way of installing drivers?