π 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
βοΈ 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
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;
}
ποΈ 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=
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
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
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:
β 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)