preface
Share the methods and steps of successfully building Laravel Sail environment. Although the official document is more detailed, there will always be problems that do not appear in the official document after operation, and it is also a supplement for the documents of beginners who have not built Laravel Sail.
PS: Follow my documentation from the beginning, the success rate may reach 99.999%.
# 1 Window system
Laravel Sail requires Windows 10 support for WSL 2.
WSL 2 was only supported in the 2004 release in May 2020, so our system needs to be updated to equal or greater than the 2004 release.
For Windows 10, ignore……
After the system upgrade is complete, search to open the Windows Function Management window and make sure that the two places of the arrow below are open:
Set WSL 2 as the default
Open PowerShell, and then set WSL 2 as the default when you install a new Linux distribution by running the following command:
wsl --set-default-version 2
Copy the code
If the following information is displayed after you run the preceding command, you need to update the kernel package. The download link is docs.microsoft.com/zh-cn/windo…
WSL 2 needs to update its kernel components. About the information, please visit https://aka.ms/wsl2kernelCopy the code
#2 Install software
Install Windows Terminal
To better access Windows subsystems, it is recommended to use Windows Terminal as the command-line tool.
Open the Microsoft Store, search for the keyword Windows Terminal, and click Install in the search results:
Okay, and I’ll talk about how to use it later.
Download VSCode
Open the code.visualstudio.com/download, choose Windows VSCode to download and install, here is no longer here.
Install it, and I’ll show you how to use it later.
Install Ubuntu
Next download and install the subsystem, Ubuntu.
Go to the Microsoft Store and search for Ubuntu, either first or second:
During the installation process, enter the password to complete the installation of Ubuntu subsystem, which is the subsystem of the current Windows system, and then our Docker will run on this system.
Open Windows Terminal and you’ll see the system we installed
In the system, / MNT/maps disk C and D of Windows
Install the Docker Desktop
1. Download and install it
Go to Docker official website to download Docker Desktop, click the Installation package to install, and proceed to the next step.
2. Enable WSL2 mode
After installation, run the program, enter the configuration page, and enable WSL2 mode:
This also needs to be set up. Select the Ubuntu system we installed in the previous step and click the button in the lower right to apply the changes:
3.Docker Hub image acceleration
Sometimes it is difficult to pull the image from Docker Hub in China, so you can configure the image accelerator. Many domestic cloud service providers provide domestic accelerator services, such as:
- Ali Cloud accelerator
- Netease Cloud Accelerator
- Baidu Cloud Accelerator
You are advised to configure multiple mirrors at the same time because the image service may break down. Check the test results of each mirror station in docker-practice/docker-registry-cn-mirror-test.
We take the netease cloud image service https://hub-mirror.c.163.com as an example.
Go to Docker Engine and paste the above code as follows:
Finally, click Apply & Restart to Restart, which usually takes a minute or two.
#3 Create a test project
Ubuntu, as a Windows subsystem, can access hard disks on the main system.
To facilitate Code management, I created the Code directory under drive E:
$ cd /mnt/e
$ mkdir Code
$ cd Code
Copy the code
Once in this directory, use the following command to create a test Laravel project:
$ curl -s https://laravel.build/example-app | bash
Copy the code
During the installation, there may be delays.
Finally create a successful interface:
The Windows Terminal tool is well integrated with VSCode, so we can open the editor directly from the command line:
$ cd example-app/
$ code .
Copy the code
VSCode will open in the current directory and modify the Dockerfile file
Laravel 8 default with vendor/Laravel/sail/runtimes / 8.0 directory Dockerfile, this article to explain. 7.4 or other versions are similar.
1. Accelerate Linux updates
Create a new file with the following content:
Vendor/laravel/sail/runtimes / 8.0 / sources. The list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
Copy the code
ADD command before RUN apt-get update:
Vendor/laravel/sail/runtimes / 8.0 / Dockerfile
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD sources.list /etc/apt/
Copy the code
2. Ubuntu PPA acceleration
In the vendor/laravel/sail/runtimes / 8.0 / Dockerfile file, search and will:
http://ppa.launchpad.net
Copy the code
Replace with:
https://launchpad.proxy.ustclug.org
Copy the code
This is the image provided by the open source software of the University of Science and Technology of China.
3. Download the Composer executable file
In the vendor/laravel/sail/runtimes / 8.0 / Dockerfile file, search the following this line:
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
Copy the code
Replace with:
&& curl -so /usr/bin/composer https://mirrors.aliyun.com/composer/composer.phar \
&& chmod a+x /usr/bin/composer \
&& composer --version \
Copy the code
This is a download from Ali Cloud image.
4. Download the Node binary file#
The Node binary download is the following line of code:
&& curl -sL https://deb.nodesource.com/setup_15.x | bash - \
Copy the code
There is no good acceleration channel at present, it may get stuck here when installing, try more times.
5. Run the container
In the root directory of the project, run the following command:
$ ./vendor/bin/sail up
Copy the code
The first time you run it, it initializes the container, and with our Dockerfile customizations above, it should go smoothly.
Notice that after the sail Up command runs successfully, the real-time log interface of the software will always be displayed:
You can break the run with CTRL + C and run it again with the -d parameter sail Up in the background:
./vendor/bin/sail up -d
Copy the code
D is short for Deamon. Daemons, also known as daemons, usually run in the background of a system for a long time.
Final Fruits of labor:
#4 Problem handling
Question 1:
> failed to fetch http://......
>
> ERROR: Service 'laravel.test' failed to build
Copy the code
Cause: The mirror source is faulty and needs to be replaced.
When building the environment, the mirror source of the Laravel Sail was already customized, so it was easy to replace. File is defined before the mirror source address: vendor/laravel/sail/runtimes / 8.0 / sources. The list
Solutions:
Replace it with the uSTC mirror source
deb http://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
Copy the code
Question 2:
> Ports are not available: listen tcp 0.0.0.0:80:bind: An attempt was made to access a socket in a way forbidden by its access permissions.
Copy the code
Cause: Port 80 on Window 10 is occupied, usually by IIS
Solutions:
-
Win +R, enter services. MSC,
-
Double-click The World Wide Web Publishing Service, change the startup type to ** Manual, and change the Service status to “Stop”.
References:
Windows Subsystem Installation guide for Linux
Build Laravel Sail development environment – Windows
Docker error port occupied Sqlserver occupied port 80