Install Laravel 12 new starter packs on Laravel Sail with WSL2
First, make sure Docker is running. Open the WSL Ubuntu terminal and in the folder where you want to install Laravel paste this command:
sudo docker run -it --rm -v "$(pwd):/app" -w /app laravelsail/php84-composer:latest bash -c "composer global require laravel/installer && ~/.composer/vendor/bin/laravel new my-awesome-app"
(Replace “my-awesome-app” with your desired project name)
Follow the prompts from the Laravel installer to select your preferred starter kit. Laravel 12 offers several new starter kits, read more here: https://laravel.com/docs/12.x/starter-kits
In my case, there was permission on the last prompt of the Laravel installer to install the scripts:
I had to create the folder, set permission and install the scripts manually:
cd my-awesome-app
then create the directory and set permissions
cd my-awesome-app
sudo mkdir -p node_modules
sudo chmod -R 777 node_modules
Now, while inside the folder, install Laravel Sail
docker run --rm -v "$(pwd)":/app -w /app laravelsail/php84-composer:latest php artisan sail:install
Now, boot up Sail:
./vendor/bin/sail up
Then install the scripts and build the frontend assets:
./vendor/bin/sail npm install
./vendor/bin/sail npm run dev
That’s it, sail away!
Troubleshooting
If you’re running it for the first time on your machine, you may encounter errors with the Laravel installer during migrations. In that case, you might need to create a new database and manually run the migrations after the installer has finished.
Check if your MySQL container is running:
./vendor/bin/sail ps
Open the .env file and check if these database settings are set as such:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=sail
DB_PASSWORD=password
Create your database (password is “password” when prompted):
./vendor/bin/sail exec mysql mysql -u root -p
At the MySQL prompt, run:
CREATE DATABASE IF NOT EXISTS laravel;
GRANT ALL PRIVILEGES ON laravel.* TO 'sail'@'%';
FLUSH PRIVILEGES;
EXIT;
Restart Laravel Sail and migrate:
./vendor/bin/sail down
./vendor/bin/sail up -d
./vendor/bin/sail artisan migrate
Tip: Create Sail Aliases
It is painful to type ./vendor/bin/sail
over and over! So let’s set up an alias to save time.
Open or create your bash profile:
nano ~/.bash_profile
Add this line to source your bashrc:
if [ -r ~/.bashrc ]; then
source ~/.bashrc
fi
Then, open the bashrc file:
nano ~/.bashrc
Add this Sail alias:
# Alias for sail up
alias sail='bash vendor/bin/sail'
Save and reload the bashrc:
source ~/.bashrc
Now you can use simplified commands:
sail up
instead of./vendor/bin/sail up
sail up -d
to run in detached modesail down
to shut down containers
Enjoy and keep building…
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
For more frontend development tips and tricks, check out my personal blog: https://front-end.tips
Also, let’s catch on X: https://x.com/ifkas