Introduction
The error Composer should be invoked via the CLI version of PHP, not the CGI-fcgi SAPI typically appears when the PHP binary that the cPanel user is using is for the CGI/fcgi version of PHP instead of the CLI version of PHP. This can be shown in the below example.
[root@server /home/user]cPs# sudo -u user php -v
PHP 7.2.34 (cgi-fcgi) (built: Oct 26 2021 21:37:16)
Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0,
Copyright (c) 1998-2018 Zend Technologies
Note the PHP (CGI-fcgi) handler next to the PHP version. The correct handler below is shown by calling the exact path to the PHP CLI binary.
[root@server /home/user]cPs# sudo -u user /opt/cpanel/ea-php72/root/usr/bin/php -v
PHP 7.2.34 (cli) (built: Oct 26 2021 21:36:56) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Procedure
To resolve this for the user who is having this problem, creating an alias for the composer is required, as an example, the alias to have the composer command use the PHP-binary for PHP 7.4 will be below. Note that this will have to be added to the user's .bashrc located in the first line below; you will need to replace 'user' with the cPanel username.
/home/user/.bashrc
alias composer='/opt/cpanel/ea-php74/root/usr/bin/php /opt/cpanel/composer/bin/composer'
After this is done, you will need to either log out, then log back into ssh, or directly call the .bashrc with the below command while replacing 'user' with the cPanel username.
source /home/user/.bashrc
Comments
0 comments
Article is closed for comments.