ItSolutionStuff.com

Laravel Docker #14 - Install phpMyAdmin with MySQL Database

By Hardik Savani October 29, 2025
Laravel

Laravel is a powerful PHP framework that works great with MySQL databases. When you build web applications, you need a simple way to manage your database tables and data. phpMyAdmin is a popular web-based tool that lets you manage MySQL databases easily through your web browser. It has a nice interface where you can create tables, add data, and run SQL queries.

Docker makes it very easy to set up Laravel with MySQL and phpMyAdmin all together in one place. You don't need to install these tools separately on your computer. With Docker, everything works together smoothly. This tutorial will show you how to add phpMyAdmin to your Laravel Docker setup so you can manage your database with ease.

Step 1: Create Laravel Project

First, we need to create a new Laravel project. Run this command in your terminal:

laravel new my-app

This command will create a new Laravel project called "my-app" with all the files you need.

Step 2: Create Dockerfile

Dockerfile

FROM php:8.3-fpm

WORKDIR /var/www/html

RUN apt-get update & apt-get install -y \
    libzip-dev unzip curl supervisor nginx \
    & docker-php-ext-install zip pdo pdo_mysql

RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    & apt-get install -y nodejs \
    & npm install -g npm@latest

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

COPY . /var/www/html

# Remove default nginx configs
RUN rm -f /etc/nginx/conf.d/default.conf /etc/nginx/sites-enabled/default

# Copy our custom nginx config
COPY ./.docker/nginx/default.conf /etc/nginx/conf.d/default.conf

RUN sed -i 's|pid /run/nginx.pid;|pid /tmp/nginx.pid;|' /etc/nginx/nginx.conf
RUN sed -i 's|^user .*;|# user www-data;|' /etc/nginx/nginx.conf

COPY ./.docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Make nginx temp dirs writable for www-data
RUN mkdir -p /var/lib/nginx /var/lib/nginx/body /var/lib/nginx/fastcgi \
    & chown -R www-data:www-data /var/lib/nginx

RUN composer install
RUN npm install & npm run build

# Force PHP-FPM to listen on TCP so nginx can talk to it
RUN echo "listen = 9000" >> /usr/local/etc/php-fpm.d/zz-docker.conf

RUN chown -R www-data:www-data /var/www/html
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
RUN chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache

# Nginx listens on port 80
EXPOSE 80

CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

Step 3: Create NGINX Config File

.docker/apache/default.conf

server {
    listen 80;
    index index.php index.html;
    root /var/www/html/public;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass web:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
    }

    location ~ /\.ht {
        deny all;
    }
}

Step 4: Create docker-compose.yml

docker-compose.yml

services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    image: my-laravel-app
    volumes:
      - .:/var/www/html
      - /var/www/html/storage
      - /var/www/html/bootstrap/cache
    working_dir: /var/www/html
    user: "www-data"
    ports:
      - "8080:80"
    environment:
      - APP_ENV=production
      - APP_DEBUG=false
      - APP_KEY=base64:PdNRbeFR9Y/zbPdA9cbRRcSX/9PPbIIkErAOoYiI9pg=
      - DB_CONNECTION=mysql
      - DB_HOST=db
      - DB_PORT=3306
      - DB_DATABASE=laravel
      - DB_USERNAME=laravel
      - DB_PASSWORD=secret
    depends_on:
      - db

  db:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: laravel
      MYSQL_USER: laravel
      MYSQL_PASSWORD: secret
    ports:
      - "3307:3306"
    volumes:
      - dbdata:/var/lib/mysql


  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    container_name: laravel-phpmyadmin
    restart: always
    ports:
      - "8081:80"
    environment:
      PMA_HOST: db
      PMA_USER: root
      PMA_PASSWORD: root
    platform: linux/amd64
    depends_on:
      - db


volumes:
  dbdata:

Step 4: Create supervisord.conf

.docker/supervisord.conf

[supervisord]
nodaemon=true

[program:php-fpm]
command=php-fpm
autostart=true
autorestart=true
priority=5

[program:nginx]
command=nginx -g "daemon off;"
autostart=true
autorestart=true
priority=10

Run Laravel App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:

php artisan serve

Now, Go to your web browser, type the given URL and view the app output:

http://localhost:8080

You can access phpMyAdmin by visiting:

http://localhost:8081

Use these login details for phpMyAdmin:

Username: root

Password: root

Now you can use your Laravel app with phpMyAdmin to manage your MySQL database easily.

Output:

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube