1084

A guide for setting up on WSL

Comments for “A guide for setting up on WSL”
 

Posted by Mac on Saturday 27th January 2024 at 17:40 GMT

I've switched all my WAMP, XAMP, Docker, and VMware development environments over to WSL2, and I'm as happy as a cut cat. So my PHP and MySQL are running in WSL.

So far I've tried the Windows version of the Trongate Desktop app, and it just hung trying to create a new app. I presume this is because it's looking in Windows for PHP/Apache. I have run into this before with dev tools using WSL, and a common solution is to run the Linux version of the software within WSL.

So I ran the Trongate AppImage, and got a little bit further, but after I enter the DB credentials, I get the error "TYPEERROR: CONN.QUERY IS NOT A FUNCTION".

Does the Trongate desktop app output an error log that might give me more information? Is there some way to set the paths for the Trongate desktop app to use?

Any help would be great!
Mac
Level One Member

Mac

User Level: Level One Member

Date Joined: 7/01/2024

Posted by DaFa on Monday 29th January 2024 at 08:36 GMT

Hi Mac,
It has been a while since I have played around with WSL2. My gut is telling me, all your issues are because of permissions.

I had it all running a while back, having Apache, MariaDB and PHP all running on WSL2 with Ubuntu and it all worked from Windows for me.

The desktop app will throw that error if it can't connect to your database. Be it not running, permission issues with the root or current user you have setup with MariaDB or MySQL, directory permissions, etc.. Linux is fussy about all that stuff.

I'll have a bit of play for you and return to share what I discover.

Cheers for now,
Si
Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by Mac on Monday 29th January 2024 at 14:02 GMT

Si you're very kind; I really appreciate your help with this!

Once we figure out the process, I'm very happy to add to the documentation how to set up Trongate with WSL2. I'm going to try to get just the framework working on WSL, and that might help me understand why the Desktop app is having an issue connecting.

If I discover anything helpful, I'll share it here. Please let me know if you figure things out.
Level One Member

Mac

User Level: Level One Member

Date Joined: 7/01/2024

Posted by Mac on Monday 29th January 2024 at 15:09 GMT

Si I just want to confirm that I was able to get the framework running manually in WSL. This confirms that I'm using the DB credentials in the Desktop app and the issue must be as you said, related to permissions or something like that. I've tried running the app as root with --no-sandbox, but I still got the same error.

While doing the manual setup of the framework, I noticed a few tiny gotchas that experts like yourself and David probably don't notice.

1. I could not find any guide on how to set up the framework manually. Perhaps David has created a video for this, and if so, that's great, but it might be a nice idea to add a few lines to the documentation on the manual installation process.
2. I got a 500 error because I was using PHP 7.4. If you don't want to bloat the framework with code that checks for minimum requirements, something like a requirements.php file would be nice.
3. The 'BASE_URL' needs a trailing slash. This could be included in idea 1 above and also a one-line comment in config.php

I'd like to contribute, so I'm happy to do all of the above if you or David think they're good ideas.

Many thanks,
Mac
Level One Member

Mac

User Level: Level One Member

Date Joined: 7/01/2024

Posted by DaFa on Tuesday 30th January 2024 at 04:48 GMT

Hi Mac,

This might be a bit of a long post but worth it if you want to run your web stack from WSL2 on Windows. After a bit of playing about, I managed to get Apache2, PHP8.3 and MariaDB working with the Desktop App and a Trongate app from localhost. I won’t go into how to install WSL2 on your Windows box, as you have already done that.

Before we start, let’s answer your latest questions:
1. DC has many videos on how to install Trongate via the Desktop app and does touch on the way to install it manually via GitHub. The way I would do a manual install is as follows: On the Trongate GitHub page (STAR it!), click the green ‘Code’ button and a dropdown will present a few options on the HTTPS tab – ‘Clone using the web URL’, ‘Open with GitHub Desktop’, and ‘Download ZIP’. Download Zip is the most common and is the option DC shows you in the video – ‘Automatic Installer’ card on trongate.io The other two ways are via the GitHub Desktop app, which I use too, and the Jedi way via the terminal using git from a terminal. Click the copy link button, open a terminal and paste this in:
git clone https://github.com/trongate/trongate-framework.git www/tg_app
This will clone Trongate to a folder in ‘www’ and your Trongate app will be in ‘tg_app’. This also copies over DC’s git history '.git' and a '.gitignore' file which are hidden by default. You can either keep them or remove them – it’s up to you. You will need to edit ‘config.php’ and ‘database.php’ found in the ‘config’ folder to match your situation. The ‘Module Import Wizard’ will fire up when you navigate to your app’s URL and create the base tables in your database. If all goes well you should now see the welcome page in your browser.
2. Trongate requires PHP8+ since DC introduced union-type hinting. I added that to the README.md file on GitHub a while back with a 'php8+' icon at the top and info on requirements in the ‘Prerequisites’.
3. In DC’s videos (there are many) and the docs he points out the need to end the ‘BASE_URL’ with a forward slash – note a big sign that you have missed it is the CSS will not work on the Welcome page.

This comment was edited by DaFa on Tuesday 30th January 2024 at 06:49 GMT

Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by DaFa on Tuesday 30th January 2024 at 05:02 GMT

Hi Mac, let's get into installing this web stack in WSL2. I'm having issues with the help bar code block filtering, so I'll break this up into separate posts.

1. Update Package Lists - open your WSL terminal and run
sudo apt update && sudo apt upgrade


2. Install Apache2
sudo apt install apache2


3. Installing PHP 8.3 - first, add the 'ondrej/php repository' then update
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.3


4. Configure PHP with Apache
sudo nano /etc/apache2/apache2.conf

Add these lines at the end
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>


5. Enable gd, intl, and pdo_mysql modules for PHP
sudo apt install php8.3-gd php8.3-intl php8.3-mysql

gd is for the image uploader, intl is for the URL slug for foreign characters, and pdo_mysql is for all the database CRUD Trongate uses in the Model.

6. Check permissions of your root web folder
cd /var/www/html/
ls -l

Then adjust the permissions, which could be your issue...
sudo chmod -R u+w *
sudo chown -R your_username:your_username /var/www/html/

NOTE: If you have installed Trongate manually via GitHub and when you go to its URL and see the module import wizard cycle when it imports the base tables into your database, it is because PHP needs permission to delete the SQL file. To get that working try
sudo chown -R www-data:www-data /var/www
where '/var/www' is your web root folder.

7. Start the Apache service
sudo service apache2 start

You should now have Apache2 running on 'localhost'

This comment was edited by DaFa on Wednesday 31st January 2024 at 01:10 GMT

Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by DaFa on Tuesday 30th January 2024 at 07:44 GMT

Now let us get on installing MariaDB, which is where I was having issues with the help bar code block filtering...

8. Install MariaDB and fix permissions
sudo apt install mariadb-server

and start it up
sudo service mysql start


Change the default Linix auth to 'auth_socket' and set a blank password for root
sudo mysql -u root


Execute some SQL
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root';
ALTER USER 'root'@'localhost' IDENTIFIED BY '';
FLUSH PRIVILEGES;

Restart MariaDB
sudo service mysql restart

Now, you should be able to connect using the root user with no password
mysql -u root


9. Download the Linux version of the Trongate Desktop app and place it in your home directory, then make it executable
chmod +x ~/apps/Trongate-1.0.5.AppImage

Then run it and create a new Trongate app.

10. If all went well you should have a new app installed by the Desktop App. If you see a folder structure in your browser on the welcome landing page, it means mod_rewrite is not enabled.
sudo a2enmod rewrite

Open apache.conf and edit the following
sudo nano /etc/apache2/apache2.conf

<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>


Save and restart Apache

I hope this helps. Feel free to reach out if you have any questions.

Happy coding!

This comment was edited by DaFa on Tuesday 30th January 2024 at 07:48 GMT

Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by Mac on Tuesday 30th January 2024 at 23:11 GMT

Thanks so much Si! You are a legend! Thanks for taking so much time and putting so much effort into answering my question! A great resource for the future. Unfortunately it's still not working for me but what I'm going to do is create a second fresh WSL and replicate your steps. My existing setup already has a lot of customisation as I use it for React Native, Node, etc. and something is messing with the Desktop app.

Many thanks,
Mac
Level One Member

Mac

User Level: Level One Member

Date Joined: 7/01/2024

×