Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 8 & Laravel Sail for dev on Windows 10 is slow. How to speed up?

How can I recreate this?

Create install from Laravel 8 docs and Laravel Sail docs.

I use the sail up command, which works great. The command builds docker containers, connects them, and makes development as easy as we can imagine, especially for VSCode, and this works fine, but it's slow in development with WSL2. I mean commands like `sail npm run dev.' Any ideas on how to speed this up?

FYI: The same project that runs on the same machine is at least 10x faster. For more information, I ran tests on i9-10900X, 32 GB RAM on Docker Desktop for Windows 10.

docker-compose.yml

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.0
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/app
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - redis
    mysql:
        image: 'mysql:8.0'
        ports:
            - '${DB_PORT}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
        volumes:
            - 'sailmysql:/var/lib/mysql'
        networks:
            - sail
    redis:
        image: 'redis:alpine'
        ports:
            - '${REDIS_PORT}:6379'
        volumes:
            - 'sailredis:/data'
        networks:
            - sail
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - 1025:1025
            - 8025:8025
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
    sailmysql:
        driver: local
    sailredis:
        driver: local
like image 989
Bart Avatar asked Dec 10 '20 02:12

Bart


People also ask

What is Laravel 8?

8 New Features of Laravel 8. Laravel is an open source PHP platform created by Taylor Otwell that's designed to make web apps easier and faster. It follows a pattern of Model View Controller (MVC) configuration. Laravel reuses the current components of various frameworks that help to build a web application.

What is difference between Laravel 8 and Laravel 9?

Laravel 9 provides New Query Builder Interface, making it easier for developers to work with. Laravel 9 has made some major improvements required in the Laravel 8, including Symfony 6.0 support. Flysystem 3.0 has improved more in comparison to previous versions.

Does Laravel 8 require PHP 8?

Laravel 8 requires PHP 7.3+ or above so you need this version or the latest version of PHP installed on your system.

Is Laravel 9 released?

Initially scheduled to be released by September 2021, Laravel 9 was pushed to January 2022, making it the first long-term bolster (LTS) release to be introduced following the 12-month release cycle.


2 Answers

You should run docker from WSL2 if possible.

  1. Install docker and WSL2.
  2. Move your project to WSL by opening \\wsl$\ in explorer and navigating to your VM's home, in my case \\wsl$\Ubuntu-20.04\home\thomas

enter image description here

  1. Run docker-compose up -d / sail up from the VM

enter image description here

like image 93
online Thomas Avatar answered Oct 18 '22 13:10

online Thomas


I was going to explain this but just go here and read for yourself. This is what helped me. VSCode kinda yelled at me when I opened up a project in the default location and gave me this link. https://docs.microsoft.com/en-us/windows/wsl/compare-versions

Performance across OS file systems

We recommend against working across operating systems with your files, unless you have a specific reason for doing so. For the fastest performance speed, store your files in the WSL file system if you are working in a Linux command line (Ubuntu, OpenSUSE, etc). If you're working in a Windows command line (PowerShell, Command Prompt), store your files in the Windows file system.

For example, when storing your WSL project files:

  • Use the Linux file system root directory: \\wsl$\Ubuntu-18.04\home\<user name>\Project
  • Not the Windows file system root directory: C:\Users\<user name>\Project

All currently running distributions (wsl -l) are accessible via network connection. To get there run a command [WIN+R] (keyboard shortcut) or type in File Explorer address bar \\wsl$ to find respective distribution names and access their root file systems.

You can also use windows commands inside WSL's Linux Terminal. Try opening a Linux distribution (ie Ubuntu), be sure that you are in the Linux home directory by entering this command: cd ~. Then open your Linux file system in File Explorer by entering (don't forget the period at the end): powershell.exe /c start .

like image 38
charlyRoot Avatar answered Oct 18 '22 14:10

charlyRoot