1. Laravel Sail requires Windows 10 systems that support WSL 2. The 2004 version released in May 2020 only supports the WSL 2 function, so our system needs to be updated to the 2004 version equal to or greater than the 2004 version. To view the system version, you can use the winver command, refer to Windows 10 Release Information, the release time of the version is greater than 1909. The system version meets the requirements. as shown in Figure 1
Figure 1
2. First upgrade to: the latest 21H1 version based on 360. as shown in Figure 2
Figure 2
3. Check the system version, it has been upgraded to: 21h1 version. as shown in Figure 3
Figure 3
4. Search to open the windows function management window to ensure that the two places in the red box in the figure below are enabled: Windows subsystem for Linux, remote differential compression API support. as shown in Figure 4
Figure 4
5. In order to better access the Windows subsystem, it is recommended to use Windows Terminal as a command line tool. Open the Microsoft store, search for the keyword Windows Terminal, and click Install in the search results. as shown in Figure 5
Figure 5
6. Download and install the subsystem: Ubuntu. Open the Microsoft store, search for ubuntu, the first and second can be, select the second one: ubuntu 20.04 LTS. as shown in Figure 6
Figure 6
7. Prompt to create a user of the Ubuntu system, enter the user name, and then enter the password to complete the installation of the Ubuntu subsystem. This Ubuntu is a subsystem of the current Windows system, and our Docker will run based on this system. as shown in Figure 7
Figure 7
8. Go to Docker official website to download Docker Desktop: https://hub.docker.com/editions/community/docker-ce-desktop-windows After the download is complete, click the installation package to install, and you can go all the way.
9. Tips: WSL 2 Installation is incomplete. WSL 2 installation is incomplete. as shown in Figure 8
8
WSL 2 installation is incomplete.
The WSL 2 Linux kernel is now installed using a separate MSI update package. Please click the link and follow the instructions to install the kernel update:https://aka.ms/wsl2kernel
Press restart after installing the Linux kernel
10. Click the link and follow the instructions to install the kernel update: https://aka.ms/wsl2kernel . Download and install the Linux kernel update package. as shown in Figure 9
Figure 9
11. Restart the computer, open Docker Desktop again, and report an error: Docker failed to initialize. Ignore it for now. As shown in Figure 10
Figure 10
12. After restarting the computer again. Open Docker Desktop, no errors are reported again. Go to the configuration page – General, Use the WSL 2 based engine is checked by default, and enable WSL2 mode. as shown in Figure 11
Figure 11
13. Configuration – Resources – WSL Integration, select the Ubuntu system we installed in the previous step, but the Ubuntu option does not exist. as shown in Figure 12
Figure 12
14. Reference URL: https://learnku.com/articles/54890. Open: Windows Terminal, convert to WSL 2. as shown in Figure 13
Figure 13
15. Click the button Refresh, the option ubuntu-20.04 has appeared, turn on. Figure 14
Figure 14
16. Create a test project, open the Windows Terminal command line, and follow the instructions below to enter the Ubuntu system. as shown in Figure 15
Figure 15
17. Ubuntu, as a Windows subsystem, can access the hard disk under the main system. In order to facilitate the management code, I have already created the wwwroot directory under the E drive. After entering this directory, I use the following command to create a test Laravel project. as shown in Figure 16
Figure 16
18. Finally create a successful interface. as shown in Figure 17
Figure 17
19. Open the E:\wwwroot\example-app directory. as shown in Figure 18
18
20. To view the Dockerfile file, Laravel 8 uses the Dockerfile under the vendor/Laravel/sail/runtimes/8.0 directory by default. as shown in Figure 19
Figure 19
21. Run the container, and in the root directory of the project, execute the following command: ./vendor/bin/sail up. The first time it runs, the container is initialized. It is recommended to turn over the wall. I generally don’t tend to use domestic mirrors. report an error. As shown in Figure 20
Figure 20
ERROR: for mysql Cannot start service mysql: Ports are not available: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
ERROR: Encountered errors while bringing up the project.
22. The reason should be that the local MySQL database has used port 3306, and it is decided to first modify the port of the local MySQL database to 3307. Open the directory C:\ProgramData\MySQL\MySQL Server 5.7, and edit the my.ini file.
[client]
# pipe
# socket=0.0
port=3307
[mysqld]
# The next three options are mutually exclusive to SERVER_PORT below.
# skip-networking
# enable-named-pipe
# shared-memory
# shared-memory-base-name=MYSQL
# The Pipe the MySQL Server will use
# socket=MYSQL
# The TCP/IP Port the MySQL Server will listen on
port=3307
23. After restarting the computer, the connection to the local MySQL database is successful based on port 3307. as shown in Figure 21
Figure 21
24. Run the command again: ./vendor/bin/sail up. It will start running from MySQL, and the total time it takes 20 minutes. After the Sail up command runs successfully, the real-time log interface of the software will always be displayed. Figure 22
Figure 22
25. At this time, you can run Ctrl+C interrupts. When running again, you can use the -d parameter to make the Sail up command run in the background. Figure 23
Figure 23
26. Open Docker Desktop, there is a container in the container list: example-app, and the status is running. Figure 24
Figure 24
27. Open the URL in the browser: http://localhost/ , and the response is 200. Laravel v8.76.2 (PHP v8.1.0). The development environment is successfully deployed. as shown in Figure 25
Figure 25
28. In response to the problem of port 3306 being occupied, there is another solution, that is, the port of modifying the container is 43306. The local MySQL database still uses port 3306. The plan is subsequently implemented based on Nginx Proxy Manager.
29. Edit the C:/Windows/System32/drivers/etc/hosts file, and specify the mapping relationship between IP and domain name.
127.0.0.1 example-app.test
30. Open the URL in the browser: http://example-app.test/ . Response 200. Figure 26
Figure 26
Leave a Reply