How to clone a Laravel Sail repo and make it work in your Ubuntu WSL 2

By: Roel
July 23, 2024

I've been using XAMPP for a very long time and Laravel Herd for Windows months ago. Recently, I wanted to try developing Laravel Sail. Fortunately, my experience was smooth. The only thing that puzzled me is how you would clone other Laravel Sail repo and make it work your Ubuntu local machine.

One important thing to note is that when you clone other Laravel Sail repo, you won't be having php and composer that would install application's dependencies. 

For example, after you have cloned a github repo and run "composer install" like you normally would you would get,

 /mnt/c/ProgramData/ComposerSetup/bin/composer: 14: php: not found 

To fix this, you need to run this command from the Laravel Sail documentation

docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v "$(pwd):/var/www/html" \
    -w /var/www/html \
    laravelsail/php83-composer:latest \
    composer install --ignore-platform-reqs

What it does is it uses a small Docker container containing PHP and Composer to install the application's dependencies.

Once it done, you can done generate an app key with

./vendor/bin/sail artisan key:generate

Then create a .env file by copying .env.example

Next you need to make changes to the .env file specifically with the mysql database. By default, when you spin up a container with Laravel sail its going to create by default a mysql database with  the following credentials

DB_USERNAME=sail
DB_PASSWORD=password

Then after this you could proceed with other normal procedure you do such as 

./vendor/bin/sail npm install

and running migration commands

./vendor/bin/sail artisan migrate --seed

About the Author

Roel
Roel

Hi, my name is Roel. I am a TALL stack developer. I created this site to document all web applications I created using the TALL stack. I exclusively built products using Laravel because I like the experience writing applications using the simplest framework/stack available.



Please login to comment.

© 2024 Talldevelopers.com, All rights reserved.