Submitting a package to packagist causing “composer_home env variable” error
-
23-12-2019 - |
Pregunta
Whenever I submit a git package to my packagist installation, I get the following error:
Uncaught Exception: [RuntimeException] The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly
I've tried exporting the variable manually, but that doesn't seem to resolve the error.
Solución
The php user didn't have HOME or COMPOSER_HOME set, so I created a php.ini file in my web root with the following contents:
auto_prepend_file = /home/yourusername/directory/set_environment.php
I then created a set_environment.php file in the same directory, and set my COMPOSER_HOME directory.
<?php putenv("COMPOSER_HOME=/home/etc/webapps/novuspackagist/.composer"); ?>
Now, whenever the app is run, the COMPOSER_HOME environment variable will be set.
Otros consejos
A much easier way is to add the environment variable into the apache configuration within the virtual host block, e.g.:
<VirtualHost *:80>
ServerName myhost.home
ServerAdmin webmaster@localhost
DocumentRoot /var/www/packagist/web
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/packagist/web>
AllowOverride All
SetEnv COMPOSER_HOME /home/<user>
</Directory>
</VirtualHost>
As you can see the SetEnv COMPOSER_HOME /home/<user>
directive makes it possible.
This should solve that kind of problems.