Laradock is a PHP development environment running on Docker.

First, install Docker on your computer.

Clone Laradock to your computer.

$ git clone https://github.com/Laradock/laradock.git

Enter the folder you cloned.

$ cd laradock

Copy the env-example file as .env.

$ cp env-example .env

Start the nginx, mysql, workspace containers. It will take a while since you're creating them for the first time to download files and create the container.

$ docker-compose up -d nginx mysql workspace

Now you need to set up the hosts file. For Windows: Open notepad as administrator, then File > Open and open the hosts file in C:\Windows\System32\drivers\etc and add the following records. For MacOS:

$ sudo vim /private/etc/hosts

Enter your password, open the file, and add the following records. For Linux:

$ sudo vim /etc/hosts

Enter your password, open the file, and add the following records.

127.0.0.1       localhost
127.0.0.1       mysql

You can access it by typing http://localhost. Now let's create a Laravel project. First, enter the workspace.

$ docker-compose exec --user=laradock workspace bash

Then create the Laravel project.

$ composer create-project --prefer-dist laravel/laravel blog

Then enter the blog directory, set up the database connection in env, and create the host record.

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=default
DB_PASSWORD=secret
127.0.0.1       blog.test

Exit from the container with exit. In the Laradock project, go to the mysql > docker-entrypoint-initdb.d folder and rename the createdb.sql.example file to createdb.sql. In this file, before the line that says FLUSH, add:

CREATE DATABASE IF NOT EXISTS `blog` COLLATE 'utf8_general_ci' ;
GRANT ALL ON `blog`.* TO 'default'@'%' ;

Save the file. Enter the MySQL container.

$ docker-compose exec mysql bash
$ mysql -u root -p < /docker-entrypoint-initdb.d/createdb.sql

After performing these operations, you can open http://blog.test.