Build Linux on a Windows environment. Steps to install Laradock and migrate

Development environment

Laravel 7.20.0 PHP 7.4 MYSQL 8.0.21 Windows version 2004

The general flow of the whole

--Introduction of Ubuntu --Updated / introduced to WSL2 --docker installation --Laradock introduced

Goal of this article

The goal of this article is to build a Linux environment using WSL2 on a Windows environment, install Laradock, and display the screen + Migration.

First of all, from the preparation for Ubuntu introduction

Update Windows to the latest state (download at the URL below)

https://support.microsoft.com/ja-jp/help/4028685/windows-10-get-the-update

Change from PC settings to developer mode

• Select "Settings (start button gear icon)"-"Update and Security"-"For Developers" • Select "Developer Mode" in the "Use Developer Features" column to enable it

Enable Subsystem for Linux with additional features

• Select "Control Panel"-"Programs"-"Turn Windows features on or off" • Check "Windows Subsystem for Linux (Beta)" from the list.

For windows version 2004, the notation has been changed to "Windows subsystem for Linux", so please enable it.

PC restart

Ubuntu installation

Ubuntu is one of the Linux distributions and is provided as free software

Install ubunntu at Microsoft store.

Type bash at the command prompt. (Successful if you can log in to Ubuntu)

Next, update the state of Ubuntu.

$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo apt-get autoremove

Get Git and PHP

If you install normally, an old version of Git will be installed, so add a repository to get the latest version.

Execute the following command.

$ sudo apt-get install build-essential
$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt-get update
$ sudo apt-get install git
 $ git --version // OK if it's up to date
git version 2.28.0

PHP

$sudo apt-get install php7.4 php7.4-fpm php7.4-mysql php7.4-mbstring php7.4-gd
 $ php -v // Check if the specified version is installed
PHP 7.4.3 (cli) (built: May 26 2020 12:24:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Preparation for WSL2

WSL2 is a "real Linux environment" where the Linux kernel runs

Execute the following command by "Run as administrator" in "Windows PowerShell" in "Windows PowerShell"
PS C:\>dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

PS C:\>dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Restart your PC

Check version

C:¥> ver
Microsoft Windows [Version 10.0.19041.84]

Make sure the version is 10.0.18917 or higher

Execute the following command to set the default to WSL2.

C:¥> wsl --set-version ubuntu 2

Check if it has switched to WSL2.

C:¥> wsl -l -v
  NAME    STATE    VERSION
* Ubuntu   Stopped    2

Since WSL2 has been introduced, preparations for building Docker are complete.

Docker installation

What is Docker? An open source containerization technology that enables you to create and use Linux containers.

Install Docker Desktop Edge from the URL below

https://docs.docker.com/docker-for-windows/wsl-tech-preview/

PC restart

After restarting, select "setting" from the docker icon on the taskbar Check "Enable the experimental WSL2 based engine" and click "Appli & Restart"

OK when notification is displayed after restarting

Then click "Enable WSL Integration" in WSL Integration of Resources

Select "Ubuntu" and click "Appli & Restart"

Docker operation check

C:\Users\magic>wsl -d ubuntu
$ docker -v
Docker version 19.03.5, build 633a0ea838

Success if Hello World is displayed

$ docker run hello-world
To run a command as administrator (user "root"), use "sudo ".
See "man sudo_root" for details.

Hello from Docker!

Introducing Laradock

Provides the packages you need for your production environment. It's like a finer division of Homestead

Premise

I want to manage it in 1 project and 1 repository including Laradock, so it has the following configuration.

 ──project_dir
 ├ app // laravel directory
 │  ├  app
 │  │ bootstrap
 │ └ .env
 │   
 └ Laradock

Git clone Laradock

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

Copy the configuration file (env-exampl) to generate .env

$ cd laradock
$ cp env-example .env

Edit the copied env (Laradock.env) file

Specify the project you want to specify

APP_CODE_PATH_HOST=../
 APP_CODE_PATH_HOST = ../project name /  
#### Specify the data storage directory
DATA_PATH_HOST=~/.laradock/data
+ DATA_PATH_HOST=.laradock/data

Project name setting

When creating multiple projects using laradock, if the project name is the same, the container image with the same name created in the past will be overwritten, so set a name that does not cover

COMPOSE_PROJECT_NAME=laradock
+ COMPOSE_PROJECT_NAME=

MYSQL settings

MySQL seems to have changed the password generation method in 8 series and can not be operated from Laravel, so add the following description.

Add the following to <project_dir> /lardock/mysqmy.cnf

 // Add to the [mysqld] area (at the bottom by default)
default_authentication_plugin=mysql_native_password

Laravel.env settings

Change the DB settings according to

  • DB_HOST specifies the name inside the container written in docker-compose.yml.
DB_CONNECTION=mysql
 DB_HOST = mysql (I think it is 127.001 if it already exists, so modify it to mysql)
DB_PORT=3306
DB_DATABASE=default
DB_USERNAME=default
DB_PASSWORD=secret

Launch Laradock

Start laradock with the following command. Specify the middleware you want to start in the argument

If the project does not exist, it will be created with root privileges, so be sure to start it in the created state.

$ docker-compose up -d nginx mysql workspace

Start confirmation

$ docker-compose ps

Install Laravel from inside Docker container

How to install laravel from inside docker container and settings.

Enter the Workspace container with the following command.

  • Specify the user with the user option.
$ docker-compose exec --user=laradock workspace /bin/bash

Install Laravel by doing the following in the container.

/var/www$ composer create-project --prefer-dist laravel/laravel .

Check the operation when the installation is completed. (* 3306 If you are using port elsewhere, port conflicts, so please terminate the port with task manager etc.)

Access http: // localhost with a browser on the Windows side.

Installation is complete when the screen is displayed

Confirm migration Let's check with migration whether the MySQL settings are complete.

Success if the table is created in the DB as shown below

/var/www$ php artisan migrate

Migration table created successfully.
Migrating: 2014_10_19_000000_create_users_table
Migrated:  2014_10_19_000000_create_users_table (0.36 seconds)
Migrating: 2014_10_19_100000_create_password_resets_table
Migrated:  2014_10_19_100000_create_password_resets_table (0.35 seconds)
Migrating: 2019_10_19_000000_create_failed_jobs_table
Migrated:  2019_10_19_000000_create_failed_jobs_table (0.1 seconds)

At the end

This time I posted an article about the flow of introducing Laradock in a Windows environment.

Also, it's been a year since I started programming next month, and my knowledge has deepened from the beginning, so I'll publish technical articles little by little from now on. Thank you m (._.) M

Recommended Posts

Build Linux on a Windows environment. Steps to install Laradock and migrate
Install LAMP on Amazon Linux 2 and build a WordPress environment.
How to build a Python environment on amazon linux 2
(Windows10) Install Linux environment and gnuplot.
Build and install OpenCV on Windows
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
[UE4] Build DedicatedServer on Windows and Linux
Install wsl2 and master linux on windows
Steps to install Python environment on Ubuntu
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
Simply build a Python 3 execution environment on Windows
Steps to create a Python virtual environment with VS Code on Windows
Steps to build PyTorch 1.5 for CUDA 10.2 on Windows
Build a PYNQ environment on Ultra96 V2 and log in to Jupyter Notebook
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Install Python3 on Mac and build environment [Definitive Edition]
How to install Linux on a 32bit UEFI PC
Build a GVim-based Python development environment on Windows 10 (1) Installation
How to build a Django (python) environment on docker
Create a decent shell and python environment on Windows
Build a machine learning environment natively on Windows 10 (x64)
Build Python environment on Windows
Build python environment on windows
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
Steps to quickly create a deep learning environment on Mac with TensorFlow and OpenCV
Memo A beginner tried to build a Java environment and Japaneseize it on Ubuntu 18.04.2 LTS.
A memo on how to easily prepare a Linux exercise environment
How to build a new python virtual environment on Ubuntu
Introducing Kaggle's Docker Image on Windows to build an environment
Build a GVim-based Python development environment on Windows 10 (2) Basic settings
Build a Python environment and transfer data to the server
Steps to install MySQL 8.0 on CentOS 8.1
[Linux] How to install a package on a server that does not have a network environment (standalone)
Python 3.6 on Windows ... and to Xamarin.
Install python2.7 on windows 32bit environment
Steps to install matplotlib on Mac
When I tried to build a Rails environment on WSL2 (Ubuntu 20.04LTS), I stumbled and fell.
Install Arch Linux on DeskMini A300
Steps to install VirtualBox on CentOS
How to install VMware-Tools on Linux
Steps to install python3 on mac
Build a python3 environment on CentOS7
How to install music 21 on windows
Install easy_install and pip on windows
I tried to create a server environment that runs on Windows 10
Build a Chainer environment using CUDA and cuDNN on a p2 instance
Build a Selenium environment on Amazon Linux 2 in the shortest time
Build a Python environment on your Mac with Anaconda and PyCharm
The simplest way to build a Spleeter usage environment using Windows
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
Everything from building a Python environment to running it on Windows
Building a Python development environment on Windows -From installing Anaconda to linking Atom and Jupyter Notebook-
Python 2.7, 3.4, 3.5 extension module build environment on Windows
How to build a sphinx translation environment
Build Python3 and OpenCV environment on Ubuntu 18.04
[Kivy] How to install Kivy on Windows [Python]
Build a python environment on MacOS (Catallina)
Build a simple WebDAV server on Linux
I want to build a Python environment
Install and launch k3s on Manjaro Linux