Page 1 of 1

XAMPP and Windows Subsystem for Linux

PostPosted: 11. January 2022 17:54
by zep10
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

Re: XAMPP and Windows Subsystem for Linux

PostPosted: 19. January 2022 08:59
by zep10
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.

Re: XAMPP and Windows Subsystem for Linux

PostPosted: 19. January 2022 14:03
by Nobbie
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).

Re: XAMPP and Windows Subsystem for Linux

PostPosted: 19. January 2022 15:20
by zep10
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.

Re: XAMPP and Windows Subsystem for Linux

PostPosted: 19. January 2022 17:22
by Nobbie
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....