DEV Community

shifas05
shifas05

Posted on

Dockerizing Laravel with Laradock: A Complete Local Development Setup Guide

πŸš€ Level Up Your Laravel Development with Laradock (Part 2)
In my last post, we explored why Dockerizing your Laravel app makes your life easier, cleaner, and production-ready. Now, let’s get our hands dirty and set it up using Laradock! πŸ”§

🧰 Step 1: Install Docker & Docker Compose
First, install Docker Desktop from the official site:
πŸ‘‰ https://www.docker.com/products/docker-desktop

πŸ“¦ Step 2: Clone Laradock
Clone the Laradock project to your machine:
git clone https://github.com/Laradock/laradock.git

Navigate to the laradock folder and create your .env file:

cd laradock
cp .env.example .env
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Step 3: Set Up Services and Laravel App

Let's say you want to run:

A Laravel app (installed via Laravel Docs)

  • PHP 8.2
  • Nginx
  • MySQL
  • phpMyAdmin
  • Redis

Update the following in your Laradock .env:

PHP_VERSION=8.2
NGINX_HOST_HTTP_PORT=8099
Enter fullscreen mode Exit fullscreen mode

Start your containers:
docker-compose up -d nginx mysql phpmyadmin redis workspace

🌐 Step 4: Configure Nginx for Your Laravel App

Create a new Nginx site config file:
laradock/nginx/sites/laravel-test-app.local.conf

Paste this config (and make sure the root path matches your app name and location):

server {
    listen 80;
    server_name laravel-test-app.local;
    root /var/www/laravel-test-app/public;
    index index.php;

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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass php-upstream;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    }

    error_log /var/www/laravel-test-app/storage/logs/laravel_error.log;
    access_log /var/www/laravel-test-app/storage/logs/laravel_access.log;
}
Enter fullscreen mode Exit fullscreen mode

πŸ—‚οΈ Step 5: Add a Virtual Host

Update your OS hosts file:

  • Linux/Mac:
    Edit /etc/hosts and add:
    127.0.0.1 laravel-test-app.local

  • Windows:
    Edit C:\Windows\System32\drivers\etc\hosts with admin rights.

Then restart the Nginx container:
docker-compose restart nginx

Visit in browser:
πŸ‘‰ http://laravel-test-app.local:8099
You'll see an SQL error until we configure the database.

πŸ›’οΈ Step 6: Configure Laravel Database

Update your Laravel .env:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel_test_app
DB_USERNAME=root
DB_PASSWORD=
Enter fullscreen mode Exit fullscreen mode

Create the database manually via phpMyAdmin or CLI.

πŸ’‘ Step 7: Run Migrations

Enter the workspace container (this gives you access to PHP, Composer, Artisan, etc.):
docker compose exec --user=laradock workspace bash

This runs a bash shell inside the container as the laradock user. It's best practice not to run things as root.

Navigate to your Laravel project:

cd laravel-test-app
php artisan migrate --seed
Enter fullscreen mode Exit fullscreen mode

And voilΓ  β€” your Laravel app is ready! πŸŽ‰

🧭 Step 8: Access phpMyAdmin (Optional)

Edit .env in Laradock to enable phpMyAdmin:

PMA_DB_ENGINE=mysql
PMA_PORT=8081
Enter fullscreen mode Exit fullscreen mode

Visit:
πŸ‘‰ http://localhost:8081
Log in with MySQL root credentials (root / empty password unless changed).

πŸ“Œ Bonus: You can enable almost any service (Redis, MongoDB, Mailhog, ElasticSearch, etc.) β€” all pre-configured in Laradock. Just spin up the relevant container.

πŸ–ΌοΈ Here’s what you should see when it works:

Laravel_welcome

βœ… Coming up next:

"How to use multiple PHP versions in Laradock at the same time."

πŸ‘‰ Follow me so you don’t miss it!

Top comments (0)