How to install with Composer?

What type of hardware are you using: VPS bought online
What YunoHost version are you running: 11.2.30.2 (stable)
How are you able to access your server: The webadmin
SSH

Describe your issue

Hello everyone,

I would like to install my own CMS (Contao) in a My_WebApp environment. To do this, I need to call an install.phar file (or as install.phar.php) from the WebRoot folder (www).
If I understand this correctly, then I also need to install the Composer. Is that correct?
Are there any conflicts with the YunoHost system?
Can any of you give me tips?
Thank you very much
Tinder

Share relevant logs or error messages

No Logs

NaĂŻvely, I would:

  1. Install My Webapp, choose the PHP version compatible with the CMS, and note its id (my_webapp, or my_webapp__2, if you have multiple, etc.)
  2. Open the app’s shell: sudo yunohost app shell my_webapp
  3. Open the www directory: cd www
  4. Follow the Composer installation instructions, use php for the PHP command (it will point the PHP version you selected during the installation).
2 Likes

@tituspijean Thanks for your reply :slightly_smiling_face: Yea, the app’s shell! I forgot them. Maybe this is a better way. I 'll try it.

Ok, you think it’s not such a big risk to install Composer? It won’t affect the YunoHost system?

It should not affect the rest of the system, no. :slight_smile:

@tituspijean Ok, thank you very much :slightly_smiling_face:

I’ll use this topic as my use case its the same.
I tried to install composer inside mywebapp but gives an error on php composer-setup.php:

unable to create composer home directory /.composer mkdir() permission denied

i think its trying to install on /var/www/mywebapp and doesn’t have permissions. I tried to set location argument `php composer-setup.php --install-dir=/var/www/mywebapp/www but it tried to install on the same location
How can i install composer on webapp?

Hijacking topics? I’ll keep the option to split it.

Please show that you have followed the steps of the second post of this thread. Do not hesitate to copy the content of the terminal and not only the error.

yes i followed the steps you said

sudo yunohost app shell my_webapp__3
cd www

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php

All settings correct for using Composer
Unable to create Composer home directory “/var/www/my_webapp__3/.config/composer”: mkdir(): Permission denied


I think I found two problems and solutions:

The my_webapp $HOME permissions do not allow the my_webapp user to write, but this can be seen as good thing for a public web app. One can create the required user writable .config and .cache dirs (or symlinks) as root.

The php command does not call the correct php version in all cases. It’s currently just a php() shell function, but only having e.g. ~/bin with an appropriate symlink in it, and exporting an adjusted $PATH can have an effect for arbitrary scripts and binaries.

Perfect! Thank you for your investigation. :slight_smile:

That’s a bit more worrisome, the point of that command redefined with Bash is to point to that correction version. Can you show some examples of that command not using the right version?

Yeah, the shell function can select the correct (configured) version, but for sure only for shell interpreted scripts.

For example, not for #!/bin/php scripts, or php calls (scripts started through bash) that themselves call further php scripts.

It’s a common issue if you search for it, with the solution being to instead place a symlink to the desired php version in an exported custom $PATH (a general unix/posix thing).

i have created the .config .config/composer and .cache folders inside my_webapp as root and now it gives the error

Unable to write keys.dev.pub to: /var/www/my_webapp__3/.config/composer

In any case the installing user needs to be granted write permissions for the install, at least during the install, eg. with chmod as root.

As far as I remember it needs .cache .local and .config directories.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.