sam_arbid's avatar

Setup Laravel on WSL 2 windows (the right way)

How can I setup Laravel on Windows WSL2 ? (the right way)

1- I follow these steps on this link I am able to run a new Laravel project with php artisan serve

but If I open other existing project, I am able to open the welcome page, but when I click on any route, I get an error: Illuminate\Routing\Exceptions\UrlGenerationException Missing required parameters for [Route: profile] [URI: profiles/{user}]. (View: /mnt/c/laragon/www/samstwitter/resources/views/_sidebar_links.blade.php)

While it's working perfectly on Laragon windows setup.

  • is it a PHP plugin I am missing?
  • should I edit my .htaccessfile in the public folder?

2 - another problem is I am not able to migrate: ` Illuminate\Database\QueryException

SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from information_schema.tables where table_schema = samstwitter and table_name = migrations and table_type = 'BASE TABLE')`

I would love to see a full explanation on how to setup a dev environment on WSL2 on windows?

0 likes
4 replies
sam_arbid's avatar

Thanx for the fast reply, I will give this package a try now! But I still need to know how I can setup my dev environment without Docker on WSL2. if that's possible.

Sinnbeck's avatar

Well you can install it natively like in that guide. But be aware that running php artisan serve does not come with a database, so you need to get that whole thing working one http://localhost

Sadly that guide it lacking quite alot regarding installing mysql. It just tells you know to install it, but not how to create a database and a user (both of which you need)

sam_arbid's avatar

Update

following these steps to make MySQL work: inspired by this repo

1- Upgrade the Repositories

sudo apt update 
sudo apt upgrade

2- Install MySQL 5.7

sudo apt install mysql-server

3- Start service

sudo service mysql start

4- Setup new user account and grant privileges

sudo mysql

5- Check the authentication method/plugin that all your MySQL accounts are currently using

SELECT user,authentication_string,plugin,host FROM mysql.user;

6- Create a new user within the shell and grant privileges

CREATE USER 'YOUR_USER_NAME_HERE'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD'; GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost'; FLUSH PRIVILEGES;

7- Exit shell and return with passward 'password':

mysql -u yourusername -p 
your db password

mysql> CREATE DATABASE your_db_name;

  • make sure you created by running : mysql> database list; and exit mysql

8- make sure your password and user in your .env file are matching with your DB

9- Finally run php artisan migrate

should now migrate successfully.

but still, have the same error when I hit any route.. Illuminate\Routing\Exceptions\UrlGenerationException Missing required parameters for [Route: profile] [URI: profiles/{user}]. (View: /mnt/c/laragon/www/samstwitter/resources/views/_sidebar_links.blade.php)

1 like

Please or to participate in this conversation.