Adding phpMyAdmin service to Laravel Sail docker-compose.yml

I was exploring Laravel Sail and noticed that TablePlus was suggested to manage Database which is Free and good. But I have an alternative, phpMyAdmin. It is easy to setup and link with our Laravel Application. In this article, I am attaching a code snippet for docker-compose.yml which will spin up a phpMyAdmin along with our Laravel Application.

Add following lines inside docker-compose.yml below all other services

    myadmin:
        image: 'phpmyadmin:latest'
        ports:
          - 8080:80
        environment:
          MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
        links:
          - "mysql:db"
        depends_on:
          - mysql
        networks:
          - sail

It should look something like this:

Access http://localhost:8080 to access phpMyAdmin and enter database credentials mentioned in the .env files

Note: Feel free to change the port from 8080 to anything else that you prefer.

“links” will create an alias of “mysql” service with the name “db” which is required by phpMyAdmin.

In “networks”, “sail” network is mentioned which SHOULD BE same as “mysql” service.

“depends_on” meaning this “myadmin” service won’t start till “mysql” is up.

That’s it! Thanks for reading. Hope this was helpful.

Feel free to get in touch with me on twitter: @jigar_dhulla

5 responses to “Adding phpMyAdmin service to Laravel Sail docker-compose.yml”

  1. Thank you, this helps me to install PHPMyAdmin in my folder protect for a new installation.

    How can I install PhpMyAdmin in Laravel Project that I’ve been working on it?

    Like

  2. If I understood correctly, you want to use phpMyAdmin for the existing Laravel application(not with sail installed).

    Keep in mind that phpMyAdmin is independent of Laravel. Treat it like a stand-alone PHP Application. So I would probably create a new Virtual Host(if apache) in the web server for phpMyAdmin. Also, phpMyAdmin is capable of connecting to multiple databases in a single setup. Everything can be achieved by configuring config.inc.php the right way.

    It would be difficult to suggest one way as I am not aware of your environment. But this is the best place for you to get started. https://docs.phpmyadmin.net/en/latest/setup.html

    Like

  3. Thanks for your reply.
    I mean I want to install PHPMyAdmin in a Laravel Project installed using Laravel Sail, but when I run it the first time with the sail up command, I didn’t know that I can install PHPMyAdmin, So I just want to use it in this project that I’ve been working on it. I hope you understand.
    Thanks a lot for sharing your knowledge

    Like

  4. TablePlus isn’t free. I installed PHPMyAdmin before but I forgot to write down what I did, lol.
    I found a similar code like yours in my old project. I copied it but it gives me an error. did you forget a step? Please help, the error I get is as below:

    ERROR: In file ‘./docker-compose.yml’, service ‘image’ must be a mapping not a string.

    Like

    1. tab/spaces seems to be missing before “image”. It is being treated as service name instead of property.

      Like

Leave a comment