August, 17 2023
Deploying Laravel on Cpanel has been a tasking experience for most developers. One of these problems is running commands on the terminal. While most CPanel hosting provides you with a terminal, the experience can be difficult especially when you start upgrading your Laravel application.
As a Laravel developer, you will get to change your PHP version and run composer commands to get your app up to date. I assume that's why you are still reading this so let's jump in.
If your CPanel is deployed on a Linux server with CentOS, then your versions of PHP installation can be found inside the /opt/cpanel/ directory. Also, your composer installation can be located inside the same directory.
To run composer commands with PHP8.1;
/opt/cpanel/ea-php81/root/usr/bin/php /opt/cpanel/composer/bin/composer install
/opt/cpanel/ea-php81/root/usr/bin/php /opt/cpanel/composer/bin/composer update
/opt/cpanel/ea-php81/root/usr/bin/php artisan inspire
That's all you need to know.
For CouldLinux OS, I haven't fully figured it out because it doesn't have out-of-the-box support for multi-PHP on domains & directories.
From my discovery, PHP installations can be found inside the /opt/alt/ directory while the Composer installation can be found inside the /opt/cpanel/ directory.
The difference I noticed is that the default php.ini configuration necessary for most PHP extensions was not enabled for the PHP version. The php.ini configuration file that has these extensions enabled can be found inside the /opt/alt/default_php_ini directory.
To run PHP we need to tell it use any of the configurations inside this directory.
To run composer commands with PHP8.1, change to your project directory:
/opt/alt/php81/usr/bin/php -c /opt/alt/default_php_ini/php81.ini /opt/cpanel/composer/bin/composer install
/opt/alt/php81/usr/bin/php -c /opt/alt/default_php_ini/php81.ini /opt/cpanel/composer/bin/composer update
/opt/alt/php81/usr/bin/php -c /opt/alt/default_php_ini/php81.ini artisan inspire
I am hoping to upgrade the Litehost server from CentOS to AlmaLinux by the end of the year. Hopefully, that will allow me to see what is obtainable from the OS.
My advice is to try the same approach for CloudLinux and see what is obtainable.
Drop your comment and we can have a chat about this issue and possible solutions.
I create and maintain PHP & Laravel applications & packages. I write about PHP & Laravel. Subscribe to get future posts via email. Subscribe here
Litehost is a web hosting platform for PHP & Laravel developers with Composer, Git, PHP & CLI pre-installed. Try it now