XAMPP and Windows Subsystem for Linux

Problems with the Windows version of XAMPP, questions, comments, and anything related.

XAMPP and Windows Subsystem for Linux

Postby zep10 » 11. January 2022 17:54

Hi!
I am on Windows 11 with XAMPP 3.3.0, and I use Debian on Windows Subsystem for Linux. I would like to use MySQL in XAMPP from WSL: is it possible?

More in detail, I develop a Python app in Flask (https://flask.palletsprojects.com/en/2.0.x/) which uses MySQL for database. I can launch the app from windows and it works fine, but when I launch it from Debian, it cannot connect to the database. The strange thing is that a few months ago it worked effortlessly, and now it does not work anymore. I have no idea what changed.
I could install mysql in Debian, but I liked that fact that I could use the same database from Windows and Debian for testing!

Thanks in advance!
Zep10
zep10
 
Posts: 3
Joined: 11. January 2022 17:48
XAMPP version: 3.3.0
Operating System: Windows 11

Re: XAMPP and Windows Subsystem for Linux

Postby zep10 » 19. January 2022 08:59

After a lot of digging, I found a solution.
First, my Flask app running in WSL cannot use localhost to communicate with XAMMP, but it should use $(hostname).local. You can test it by typing ping $(hostname).local in the WSL terminal: the keyword will be replaced by the host name and IP.
More specifically in Flask, that means that your SQLALCHEMY_DATABASE_URI variable should look something like this:
Code: Select all
export SQLALCHEMY_DATABASE_URI="mysql+pymysql://sql_user:sql_password@$(hostname).local/YOUR_DATABASE"


Second point, the app will be connecting from a "foreign" address, not localhost. Therefore, go to your phpMyAdmin interface, select the MySQL user that Flask is using, go to "Login information" and select "Any Host: %" in the "Host" section. I found aguide here: https://www.hacking-tutorial.com/tips-and-trick/how-to-make-xampp-mysql-database-accessible-by-network/
Now this user can be accessed by your network, so maybe choose a secure password.

That's it, it worked for me.
zep10
 
Posts: 3
Joined: 11. January 2022 17:48
XAMPP version: 3.3.0
Operating System: Windows 11

Re: XAMPP and Windows Subsystem for Linux

Postby Nobbie » 19. January 2022 14:03

zep10 wrote:but it should use $(hostname).local. You can test it by typing ping $(hostname).local in the WSL terminal: the keyword will be replaced by the host name and IP.


That is a feature of a FritzBox, which applies as well hostname as hostname.local as DomainName for each member of your LAN. "hostname" is the given Name of the connected PCs (as well for Windows, as for Linux and macOS).
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: XAMPP and Windows Subsystem for Linux

Postby zep10 » 19. January 2022 15:20

I do not know what a FritzBox is, but yes: instead of $(hostname) you can directly type in the actual name of the host, but I think using $(hostname) is more robust.
zep10
 
Posts: 3
Joined: 11. January 2022 17:48
XAMPP version: 3.3.0
Operating System: Windows 11

Re: XAMPP and Windows Subsystem for Linux

Postby Nobbie » 19. January 2022 17:22

https://avm.de/produkte/fritzbox/

Probably other routers have the same feature build in. Actually its not used to be a Windows feature, but a router feature. Last not least - Microsoft may have copied it....
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 200 guests