When we try to run a composer command, like update, we usually do the following:
composer update
Cpanel has multiple PHP binaries, but in this case, we are unable to select a specific PHP binary to use, instead we have to run it with the default one, how to run composer update with a different php binary in cpanel?
Solution
composer binary file, is a phar file. PHAR is necessarily a PHP Archive and usually automatically detect the running php. But as it is essentially written in php, you may explicitly run it with a different php binary, if you want. To run composer with different php binary, first, you need to find the location of composer. You may do so, using the following:
root@mirage [~]# which composer
/opt/cpanel/composer/bin/composer
Cpanel different php binaries are available under the following kind of directory:
/opt/cpanel/ea-phpXX/usr/bin/php
XX is the version number of PHP. So for example if you need to use PHP 7.4, you would need to run using the following:
/opt/cpanel/ea-php74/usr/bin/php
Now, to run composer update along with PHP 7.4 binary, you may do something like the following:
First, make sure you are in the directory where you want to install laravel, for example, something like the following:
cd /home/username/public_html
Then, you may run the above command:
/opt/cpanel/ea-php74/usr/bin/php /opt/cpanel/composer/bin/composer update
or in case, you want to to install
/opt/cpanel/ea-php74/usr/bin/php /opt/cpanel/composer/bin/composer install
or may be, you wan to run update with no-scripts
/opt/cpanel/ea-php74/usr/bin/php /opt/cpanel/composer/bin/composer update --no-scripts
While trying to run any of the following with Laravel composer installer, you see an error similar to the following:
Uncaught ErrorException: require(/home/username/public_html/vendor/composer/../../app/Helpers/helper.php): failed to open stream: No such file or directory in /home/username/public_html/vendor/composer/autoload_real.php:71
How to fix this?
Solution
The error is appearing, most likely you forgot to add the ‘app’ directory of laravel in your root directory. Make sure, you have the ‘app’ directory in your root directory, then run any of the following:
If this is the first time, you need all laravel packages, run:
composer install
If this is not the first time, you may run the following:
It is trying to look into a sub-sub version of openssl, which is 1h for PHP 7.4, but 1i is installed by default which is not an exact match with 1h, hence the error is appearing. To fix the problem, you can not just run yum update on openssl and fix this as you technically already have the latest version. To work with this, you need to first uninstall the ea-openssl rpm and install the require version. You may do this in the following way:
[root@stack4 yum.repos.d]# rpm -qa|grep ea-openssl
ea-openssl11-devel-1.1.1i-1.el7.cloudlinux.x86_64
ea-openssl-1.0.2u-1.el7.cloudlinux.x86_64
ea-openssl11-1.1.1i-1.el7.cloudlinux.x86_64
[root@stack4 yum.repos.d]# yum install ea-openssl11-1.1.1h-1.el7.cloudlinux.x86_64
Loaded plugins: fastestmirror, rhnplugin, universal-hooks
This system is receiving updates from CLN.
Loading mirror speeds from cached hostfile
* cpanel-plugins: 185.125.185.32
* cloudlinux-x86_64-server-7: xmlrpc.cln.cloudlinux.com
Package matching 1:ea-openssl11-1.1.1h-1.el7.cloudlinux.x86_64 already installed. Checking for update.
Nothing to do
Remember to use rpm uninstaller instead of yum remove, as yum also removes the dependencies, but with rpm you can skip the dependency uninstallation and patch it the above way.
When run the following command in your Laravel Automation Tool Dusk:
php artisan dusk
You get something like the following error:
[elastic-keldysh@pl1 blog]$ php artisan dusk
PHPUnit 9.3.11 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 00:00.339, Memory: 18.00 MB
There was 1 error:
1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\UnknownErrorException: unknown error: cannot find Chrome binary
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:139
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:370
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:136
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/tests/DuskTestCase.php:40
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:200
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/laravel/framework/src/Illuminate/Support/helpers.php:234
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:201
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:95
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:65
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/tests/Browser/ExampleTest.php:21
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
The error actually appears because you do not have Chrome browser installed on your system. Now, exit from your user shell, and drop back to the root shell. From the root shell, if you are using CentOS 7, you may run the following:
Once the installation is done, you may now go back to the user shell and run laravel dusk:
[root@pl1 lib64]# su - elastic-keldysh
Last login: Thu Oct 1 15:39:18 IST 2020 on pts/0
[elastic-keldysh@pl1 ~]$ php artisan dusk
Could not open input file: artisan
[elastic-keldysh@pl1 ~]$ cd blog
[elastic-keldysh@pl1 blog]$ php artisan dusk
PHPUnit 9.3.11 by Sebastian Bergmann and contributors.
R 1 / 1 (100%)
Time: 00:02.367, Memory: 18.00 MB
There was 1 risky test:
1) Tests\Browser\ExampleTest::testBasicExample
This test did not perform any assertions
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/tests/Browser/ExampleTest.php:16
OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.
If you are looking at this post, chances high that, you are trying to run laravel dusk and seeing the following kind of error:
[elastic-keldysh@pl1 blog]$ php artisan dusk
PHPUnit 9.3.11 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 00:00.331, Memory: 18.00 MB
There was 1 error:
1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"binary":"","args":["--disable-gpu","--headless"]}}]},"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args":["--disable-gpu","--headless"]}}}
Failed to connect to localhost port 9515: Connection refused
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:331
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:136
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/tests/DuskTestCase.php:40
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:200
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/laravel/framework/src/Illuminate/Support/helpers.php:234
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:201
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:95
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:65
/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/blog/tests/Browser/ExampleTest.php:21
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Chorme/Chromium browser runs it’s on 9515 port and laravel dusk tries to connect to it through the Browser binary, but failing to do so. To resolve the case, we first, need to check if chromedriver for linux can run or not.
First, browse your laravel root directory, in my case, it’s the blog directory and then run the chromedriver for linux as following:
cd blog
vendor/laravel/dusk/bin/chromedriver-linux
This should return something like the following if the driver able to load in memory:
[elastic-keldysh@pl1 blog]$ vendor/laravel/dusk/bin/chromedriver-linux Starting ChromeDriver 85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}) on port 9515 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully.
But if it can not be loaded, it will return some kind of error like the following:
[elastic-keldysh@pl1 blog]$ vendor/laravel/dusk/bin/chromedriver-linux
vendor/laravel/dusk/bin/chromedriver-linux: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
As the error suggests, it is failing to access the library called libX11-xcb. To install it in CentOS, you may run the following from root shell:
You may now, go back to the user shell, and run the chromedriver-linux again:
[root@pl1 lib64]# su - elastic-keldysh
Last login: Thu Oct 1 15:28:29 IST 2020 on pts/0
[elastic-keldysh@pl1 ~]$ cd blog
[elastic-keldysh@pl1 blog]$ vendor/laravel/dusk/bin/chromedriver-linux
Starting ChromeDriver 85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Now, you may run the following to start using the laravel dusk:
php artisan dusk
After you are done resolving the 9515 error, you might also have to face another error with Chrome Binary, have a look at the following on how to resolve the error:
There are couple of ways you can run composer with Plesk Shell. My favorite one is to add php to your PATH variable, and it will automatically add the composer as well. You may follow through the following to modify your shell path variable to use Plesk PHP:
Once done, now you may run composer command and it shall work:
A PATH variable is a system variable that stores the information about the binary files location that you may run for commands. When you log in as an user, or use a custom control panel like Plesk/Cyberpanel/Cpanel, you might want to add some custom paths as a user to take binary commands. One of the example, could be to change the default php path, or a laravel command location from vendor folder. To do this, you need to extend/update the PATH variable for a specific user.
PATH variable extends with the “:”. If you type the following, in your shell, you may see the existing paths in the PATH variable:
Now, if I want to extend this to take the php binary available in /opt/plesk/php/7.2/bin/php, then we can extend the PATH variable using the following:
PATH=$PATH:/opt/plesk/php/7.2/bin/
Now, if you check, the PATH variable again, you can see it is added:
We have successfully modified the PATH variable, but only for the existing session. If you want to persist the changes, then, you need to add the command in .bashrc/.profile/.bash_profile file depending on your shell type and OS. You can add to either of the file and test with the following command:
Replace .profile with .bashrc or .bash_profile depending on the file that works for you. You may logout and relogin, and then run the echo command again to see if the $PATH is persisting or not.
Your binary to php is probably being used through redirection like .bashrc file and an alias is hooked for your php command to work. A better way to do this, is to hook the php binary to your PATH variable. You may do this and fix the error by following this tutorial: