[DOCKER] [Laravel] Command memorandum until the start of the project

Overview

A personal note summarizing the commands to start the Laravel project.

Prerequisites

Start the project

Create with the project name tasklist using Version 6 series

$ composer create-project --prefer-dist laravel/laravel tasklist ^6.0

DB creation

Use Docker to launch the mysql container.

$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=mysql -d -p 3306:3306 mysql
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
4ded8e15debd        mysql               "docker-entrypoint.s…"   6 days ago          Up 6 days           0.0.0.0:3306->3306/tcp, 33060/tcp   mysql

Create a DB after connecting to the container using the CONTAINER ID displayed in the process. The mysql password is the value specified by the MYSQL_ROOT_PASSWORD argument.

$ docker exec -it 4ded8e15debd86c73e637b0c612bf30f0cd9de0aec04b4c09a0f53a6fa16f35d bash
root@4ded8e15debd:/# mysql -u root -p -h 127.0.0.1
Enter password: mysql
mysql> CREATE DATABASE tasklist;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| tasklist           |
+--------------------+
5 rows in set (0.03 sec)

Definition of DB connection information

Define the connection information in the .env file under the project. Change the connection information according to the individual environment.

$ cd tasklist 
$ vim .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tasklist
DB_USERNAME=root
DB_PASSWORD=mysql

Check DB connection

Check if the web application can connect to the DB normally. If the following is displayed, you are connected.

$ php artisan tinker
Psy Shell v0.10.4 (PHP 7.4.10 — cli) by Justin Hileman
>>> DB::reconnect();
=> Illuminate\Database\MySqlConnection {#3233}

Change time zone

Since the default is UTC, change it to ʻAsia / Tokyo`.

$ vim config/app.php

'timezone' => 'Asia/Tokyo',

Launch the app

Start the internal server. The default view of welcome.blade.php is displayed.

$ php artisan serve --host=127.0.0.1 --port=8080 

Remarks

To stop the container, execute the following command.

$ docker stop { CONTAINER ID }

Recommended Posts

[Laravel] Command memorandum until the start of the project
A memorandum of the FizzBuzz problem
About the official start guide of Spring Framework
[Ruby on Rails] Until the introduction of RSpec
Change the URL of the application of Eclipse project (Maven).
Memorandum docker command
nginx start command
Docker command memorandum
A memorandum because I was addicted to the setting of the Android project of IntelliJ IDEA
Check the capacity of the Linux server. (Df command, du command)
Docker the development environment of Ruby on Rails project
Until the use of Spring Data and JPA Part 2
[Java] When writing the source ... A memorandum of understanding ①
Until the use of Spring Data and JPA Part 1
Until you build a project described in scala with Maven and execute it with the scala command.