How to Run Laravel Artisan or Composer with the Correct PHP Version in cPanel Terminal
Category: cPanel · Laravel / Development
Overview
If your Laravel application requires PHP 7.4, commands such as php artisan or composer may not work correctly in the cPanel Terminal.
You may see an error similar to:
Status: 500 Internal Server Error
Content-type: text/html; charset=UTF-8
This usually happens when the php command in the Terminal is using a different PHP version than the one required by your Laravel application.
There are two ways to resolve this.
Option 1 — Use the PHP 7.4 Path Directly
This is the quickest option and does not require any configuration changes.
Step 1 — Open cPanel Terminal
Log in to your cPanel account and open:
cPanel → Terminal
Step 2 — Go to Your Laravel Application
For example:
cd ~/repositories/my-laravel-app
Replace ~/repositories/my-laravel-app with the actual location of your Laravel application.
Step 3 — Run Laravel Commands Using PHP 7.4
Instead of:
php artisan key:generate
use:
/opt/cpanel/ea-php74/root/usr/bin/php artisan key:generate
For database migrations:
/opt/cpanel/ea-php74/root/usr/bin/php artisan migrate
You can use the same PHP 7.4 path for other Artisan commands.
Example
cd ~/repositories/my-laravel-app
/opt/cpanel/ea-php74/root/usr/bin/php artisan key:generate
/opt/cpanel/ea-php74/root/usr/bin/php artisan migrate
Note: You will need to enter the full PHP path each time you run a command.
Option 2 — Set PHP 7.4 as the Default Terminal PHP
If you regularly work with this Laravel application, you can configure your cPanel Terminal so that the php command automatically uses PHP 7.4.
This is the recommended option if your application consistently requires PHP 7.4.
Step 1 — Open cPanel Terminal
Log in to cPanel and open:
cPanel → Terminal
Step 2 — Add PHP 7.4 to Your Terminal PATH
Run:
echo 'export PATH=/opt/cpanel/ea-php74/root/usr/bin:$PATH' >> ~/.bashrc
Step 3 — Close and Reopen Terminal
Close the current cPanel Terminal session and open Terminal again.
This allows the new setting to take effect.
Step 4 — Check the PHP Version
Run:
php -v
You should see something similar to:
PHP 7.4.xx (cli)
Step 5 — Run Your Laravel Commands Normally
You can now use:
cd ~/repositories/my-laravel-app
php artisan key:generate
For Composer:
composer install
You can also run other Laravel commands normally, for example:
php artisan migrate
php artisan config:clear
php artisan cache:clear
php artisan route:clear
Important Notes
This Does Not Change Your Website's PHP Version
Changing the PHP command in Terminal does not change the PHP version used by your website.
Your website's PHP version is still controlled separately through:
cPanel → MultiPHP Manager
For example, your website can use PHP 7.4 while another website on the same account uses PHP 8.2.
Using Another PHP Version
If your application requires a different PHP version, replace ea-php74 with the appropriate version.