Laradock Setup
Install Laradock and prepare a sample Laravel project for local development.
Laradock is a Docker-based PHP development environment.
First, install Docker on your computer.
Clone Laradock to your machine.
$ git clone https://github.com/Laradock/laradock.git
Go into the cloned directory.
$ cd laradock
Copy env-example to .env.
$ cp env-example .env
Start the nginx, mysql, and workspace containers. The first run will take some time because Docker needs to download the images and create the containers.
$ docker-compose up -d nginx mysql workspace
Now you need to update the hosts file.
For Windows, open Notepad as administrator, then go to File > Open and open the hosts file under C:\Windows\System32\drivers\etc. Add the records shown below.
For macOS:
$ sudo vim /private/etc/hosts
Enter your password, open the file, and add the records shown below. For Linux:
$ sudo vim /etc/hosts
Enter your password, open the file, and add the records shown below.
127.0.0.1 localhost
127.0.0.1 mysql
You can now open http://localhost. Next, let's create a Laravel project. First, enter the workspace container.
$ docker-compose exec --user=laradock workspace bash
Then create the Laravel project.
$ composer create-project --prefer-dist laravel/laravel blog
Then go into the blog directory, configure the database connection in the environment file, and create the host record.
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=default
DB_PASSWORD=secret127.0.0.1 blog.test
Exit the container with exit. In the Laradock project, go to the mysql > docker-entrypoint-initdb.d folder and rename createdb.sql.example to createdb.sql. Before the line that contains FLUSH, add:
CREATE DATABASE IF NOT EXISTS `blog` COLLATE 'utf8_general_ci' ;
GRANT ALL ON `blog`.* TO 'default'@'%' ;
Save the file, then enter the MySQL container.
$ docker-compose exec mysql bash
$ mysql -u root -p < /docker-entrypoint-initdb.d/createdb.sql
After completing these steps, you can open http://blog.test.