{"id":716,"date":"2021-03-16T18:50:06","date_gmt":"2021-03-16T12:50:06","guid":{"rendered":"https:\/\/mellowhost.com\/blog\/?p=716"},"modified":"2021-03-16T18:50:06","modified_gmt":"2021-03-16T12:50:06","slug":"how-to-run-composer-with-different-php-versions-in-cpanel","status":"publish","type":"post","link":"https:\/\/mellowhost.com\/blog\/how-to-run-composer-with-different-php-versions-in-cpanel.html","title":{"rendered":"How to run composer with different PHP versions in Cpanel?"},"content":{"rendered":"\n<p><strong>Question:<\/strong><\/p>\n\n\n\n<p>When we try to run a composer command, like update, we usually do the following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">composer update<\/pre>\n\n\n\n<p>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?<\/p>\n\n\n\n<p><strong>Solution<\/strong><\/p>\n\n\n\n<p>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:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">root@mirage [~]# which composer\n\/opt\/cpanel\/composer\/bin\/composer<\/pre>\n\n\n\n<p>Cpanel different php binaries are available under the following kind of directory:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/opt\/cpanel\/ea-phpXX\/usr\/bin\/php<\/pre>\n\n\n\n<p>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:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/opt\/cpanel\/ea-php74\/usr\/bin\/php<\/pre>\n\n\n\n<p>Now, to run composer update along with PHP 7.4 binary, you may do something like the following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/opt\/cpanel\/ea-php74\/usr\/bin\/php \/opt\/cpanel\/composer\/bin\/composer update<\/pre>\n\n\n\n<p>First, make sure you are in the directory where you want to install laravel, for example, something like the following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd \/home\/username\/public_html<\/pre>\n\n\n\n<p>Then, you may run the above command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/opt\/cpanel\/ea-php74\/usr\/bin\/php \/opt\/cpanel\/composer\/bin\/composer update\nor in case, you want to to install\n\/opt\/cpanel\/ea-php74\/usr\/bin\/php \/opt\/cpanel\/composer\/bin\/composer install\nor may be, you wan to run update with no-scripts\n\/opt\/cpanel\/ea-php74\/usr\/bin\/php \/opt\/cpanel\/composer\/bin\/composer update --no-scripts<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Question: When we try to run a composer command, like update, we usually do the following: 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 &hellip; <a href=\"https:\/\/mellowhost.com\/blog\/how-to-run-composer-with-different-php-versions-in-cpanel.html\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to run composer with different PHP versions in Cpanel?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,318,337,144,272,273,271],"tags":[515,534,533,532,275,529],"_links":{"self":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/716"}],"collection":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/comments?post=716"}],"version-history":[{"count":1,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/716\/revisions"}],"predecessor-version":[{"id":717,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/716\/revisions\/717"}],"wp:attachment":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/media?parent=716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/categories?post=716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/tags?post=716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}