How to set ynh_composer_version : unbound variable in helper script

Hi all,

After a long while, I’m trying to create a package for Yunohost!

I keep running into being unable to set ynh_composer_version.

I read Aleks’ [post about 2.1 helper scripts,](https://forum.yunohost.org/t/new-
experimental-2-1-helpers/30114 ) but I don’t know how to apply it.

I modelled my package after Lychee, which also runs composer and artisan.

My last install log is available at https://paste.yunohost.org/raw/iqagazomuz ; I try to set the composer version at around line 35 in my install script at my_idlers_ynh/scripts/install at development - wbk/my_idlers_ynh - Forgejo

1 Like

You have to add
composer_version="2.7.7"
In _common.sh
Like here

1 Like

Thanks! Is it so easy?!

I know composer on my test system is 2.5.5. Should I not define it dynamically? Does it matter which version it is?

I did get a step further with the hardcoded version; it breaks now at there being no composer.phar, which I read about in Aleks’ post, but which is not available/created in the upstream source of the app (as far as I can see on manual install).

Any idea?

Excuses, forgot the log, https://paste.yunohost.org/raw/vosinehoha

Error: Unable to install my_idlers: An error occurred inside the app installation script
Info: The operation 'Install the 'my_idlers' app' could not be completed. Please share the full log of this operation using the command 'yunohost log share 20250226-212518-app_install-my_idlers' to get help
Warning: Here's an extract of the logs before the crash. It might help debugging the error:
Info: DEBUG - + cp -f /var/cache/yunohost/app_tmp_work_dirs/app_go2hwpee/conf/systemd.service /etc/systemd/system/my_idlers.service
Info: DEBUG - + _ynh_replace_vars /etc/systemd/system/my_idlers.service
Info: DEBUG - + local file=/etc/systemd/system/my_idlers.service
Info: DEBUG - ++ sed 's@__\([^.]*\)__@\L\1@g'
Info: DEBUG - ++ sort --unique
Info: DEBUG - ++ grep -oP '__[A-Z0-9]+?[A-Z0-9_]*?[A-Z0-9]*?__' /etc/systemd/system/my_idlers.service
Info: DEBUG - + uniques_vars=('app' 'install_dir')
Info: DEBUG - + ynh_store_file_checksum /etc/systemd/system/my_idlers.service
Info: DEBUG - + systemctl enable my_idlers --quiet
Info: DEBUG - + systemctl daemon-reload
Info: DEBUG - + yunohost service add my_idlers '--description=Web app for displaying, organizing and storing information about servers (VPS), shared hosting, reseller hosting, domains and more.' --log=/var/log/my_idlers/my_idlers.log
Info: DEBUG - SUCCESS The service 'my_idlers' was added
Info: INFO - [#######+++..........] > Installing app with Composer...
Info: DEBUG - + ynh_composer_exec update
Info: DEBUG - + local workdir=/var/www/my_idlers
Info: DEBUG - + COMPOSER_HOME=/var/www/my_idlers/.composer
Info: DEBUG - + COMPOSER_MEMORY_LIMIT=-1
Info: DEBUG - + sudo -E -u my_idlers php8.3 /var/www/my_idlers/composer.phar update -d /var/www/my_idlers --no-interaction --no-ansi
Info: DEBUG - Could not open input file: /var/www/my_idlers/composer.phar
Info: DEBUG - + ynh_exit_properly
Warning: Removing the app after installation failure…

_common.sh is the place where to put code that can be used by other scripts. Composer version will be used in install and upgrade scripts.

1 Like

Wohoo, a few iterations later, it finished the installation script succesfully!

Turned out to be a case of “Operation successful, patient died” though. Using the default template for nginx and hoping for the best, I get a bad gateway when visiting the app-URL.

  • php artisan serve will serve the app to localhost:8000
  • There is an attempt at a systemd service file to make artisan actually do that in the background, but I also started it manually without a port-in-use error so it needs more looking into.

Either way, I have to point the nginx configuration at port 8000 one way or another.

Would one of the helper scripts find a free port for me, since the next artisan app will use 8000 as well, or does artisan do some proxying by itself?

1 Like

I know very little about artisan etc, but maybe you can get some inspiration from bookstack which also seem to be using artisan in its systemd conf : bookstack_ynh/conf/systemd.service at master · YunoHost-Apps/bookstack_ynh · GitHub

I’m a bit surprised though that it wants to listen on port 8000, typically PHP apps will use PHP-FPM which works differently than the “daemon listening on port” scheme … x_X

Anyway ideally your app shouldn’t need to use one specific port but use a port chosen ~randomly (possibly with a default value) and making sure that no other app or process uses that port. In packaging v2+ it is done using the “port” resource : App resources | Yunohost Documentation (typically just having [resource.ports] with no option/property should be fine and will create a variable $port / __PORT__ to be used in configurations etc

1 Like

While searching for a solution, “learning” kicked in. I should indeed use PHP-FPM, with artisan preferably only for quick proof-of-concept uses while developing.

I’ll do some more studying and triyng before posting back here!

1 Like

It was all a bit more involved that I had anticipated, but in the end there is a package that delivers a working app on installation :slight_smile:

It seems I also succeeded in pushing my changes to a fork of the example_ynh app on Github, it’s available at GitHub - w-b-k/my_idlers_ynh at development

I installed the app on a new Yunohost to see whether all dependencies are pulled in correctly. They do, more or less, but the result is not quite what I expcted. Something’s off in the permissions, eg, CSS is 404.

I can’t quite figure out what the problem is. After comparing permissions on two working installations (one Yunohost where I created the package, one Yunohost without package but upstream Github install with redirect instead), I can’t find why my new installation (via the package) does not function.

access.log :

2a10:3781::15e4 - wbk [01/Mar/2025:21:58:19 +0100] "GET / HTTP/2.0" 200 16639 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0"
2a10:3781::15e4 - wbk [01/Mar/2025:21:58:20 +0100] "GET /css/dark.css HTTP/2.0" 404 3694 "https://idlers.dus.osba.nl/" "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0"
2a10:3781::15e4 - wbk [01/Mar/2025:21:58:20 +0100] "GET /css/app.css HTTP/2.0" 404 3694 "https://idlers.dus.osba.nl/" "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0"
2a10:3781::15e4 - wbk [01/Mar/2025:21:58:20 +0100] "GET /js/app.js HTTP/2.0" 404 3694 "https://idlers.dus.osba.nl/" "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0

Curren permissions, after fiddling to and fro:

root@dus:/var/www/my_idlers# ls -la public/css/
total 704
drwxr-sr-x 2 my_idlers www-data   4096 Dec 28 11:44 .
drwxr-sr-x 5 my_idlers www-data   4096 Dec 28 11:44 ..
-rw-r--r-- 1 my_idlers www-data 169936 Dec 28 11:44 app.css
-rw-r--r-- 1 my_idlers www-data 258147 Dec 28 11:44 dark.css
-rw-r--r-- 1 my_idlers www-data 276112 Dec 28 11:44 light.css
root@dus:/var/www/my_idlers# 

Any idea?

Edit: by the way, I set the composer version in the common script as suggested:

composer_version="2.5.5"
php_version="8.3"

Edit2: changed the link to the repo, it’s development instead of master.

I would comment my_idlers_ynh/scripts/install at b32ccf5ee8fb1e7ebad26b4412cf3da02166a1b7 · w-b-k/my_idlers_ynh · GitHub
And probably the line above it because they are specific to lychee.
Also check nginx config. Does it contain the code recommended by the dev of the app?
Try a chmod -R 640 and see if it helps.
Check the nginx error log for that domain, it may speak more.

Thanks for looking into the package and for your suggestions!

I think they are specific to Laravel, with Lychee also built on that framework. Laravel wants to write to appdir/storage, if it can’t, the app won’t run.

Is there a better way to ensure that access is permissive enough?

The dev gives install instructions to run with Artisan, no nginx suggestions :frowning:

I tried very permissive access, even that did not work. Reviewing nginx conf for the app, I added a rewrite earlier on to have index.php ‘working’,

# try redirecting stuff to index.php
rewrite ^(.*)$ /index.php$1 last;

That actually tried to put every file in index.php, also .css

The correct way seems to be

try_files $uri $uri/ /index.php?$query_string;

but when using that, I get redirected to /usr/share/nginx/htmlindex.php , ie, there must be a relative path instead of an absolute path somewhere, and a / goes missing. The result is 404 of course.

In that situation, things tend to work more or less when explicitly/manually requesting index.php in the URL in the browser. That’s a no-go of course, because the portal won’t use a link to index.php.

Would you have an idea as to why try_files without the rewrite don’t work?

Edit: the reason I opened the topic, $composer_version, was solved by your reply last week. I’ll open a new ticket to address further packaging woes!