skip to Main Content
Laradock Setup Snags – Dealing With Typical Setup Issues To Run Laravel On Laradock

Laradock Setup Snags – Dealing with Typical Setup Issues to run Laravel on Laradock

Setting up Laradock is pretty straightforward …. once you have done it all. As it the same for most things in life. Allow me to share the major snags I ran into setting it all up.

Installing Docker

Setting up Docker on your box is not hard. Not anymore with Docker native. It now runs with ease on my MBP and so should it be on your Windows box. So I will not get into that. Neither into installing git which you will be needing to clone Laravel and Laradock. But I assume you got that down already.

Port Conflicts

However if you were already running MAMP, XAMP or Laravel Valet with MariaDB you will have issues running the containers as ports will be occupied. Allow me to share a great command to see what is running on port 3306 and 443 for you to quickly figure this out:

lsof -n -i4TCP:3306 | grep LISTEN
lsof -n -i4TCP:443 | grep LISTEN

Using this command for these two ports I realized Laravel Valet was up and running so I did a:

valet stop

and to stop Homebrew’s MariaDB I did a:

brew services stop mariadb

Afterwards the ports 443 and 3306 were available.

Laradock running?

You will have Laradock running now. And the command:

docker-compose up -d mysql nginx

should work with port conflicts out of the way. And on localhost or with /etc/hosts tweaked you should be able to load something like this:

laradock on localhost

But you will see soon enough you are not out of the woods yet.

MySQL Connection Refused

So all happy with port conflicts dealt with and with all containers up and running you enter your Docker workspace box and run php artisan migrate:

docker-compose exec workspace bash
php artisan migrate

thinking it will just run…. Then you will get something like:

[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where 
table_schema = homestead and table_name = migrations)
[PDOException] 
SQLSTATE[HY000] [2002] Connection refused

This is because your Laravel .env is not grabbing the proper database host.

Laravel .env tweak

To deal with this issue make sure you use mysql for the host inside the laravel .env file:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=default
DB_USERNAME=default
DB_PASSWORD=secret

Once you have all that done you can access the database from your Docker workspace:

root@fa3ff8144e8e:/var/www# php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table

And when you access the database using Sequel Pro and 127.0.0.1 as host with the earlier mentioned user and database credentials you will see the new tables inside the database:

Sequel Pro Laradock Database

Jasper

Jasper has been working with web applications such as Joomla!, Magento and his favorite WordPress for more than a decade. He helps customers with webdesign and online marketing. Services provided are webdesign, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.

Leave a Reply

Back To Top