How to use PHP in the terminal

When using PHP in the terminal, you have to specify the full path to the PHP binary. This guide will show you how to use PHP in the terminal.


PHP Paths

The following paths are used to run PHP in the terminal:

  • PHP 5.6
    /opt/cpanel/ea-php56/root/usr/bin/php
    
  • PHP 7.0
    /opt/cpanel/ea-php70/root/usr/bin/php
    
  • PHP 7.1
    /opt/cpanel/ea-php71/root/usr/bin/php
    
  • PHP 7.2
    /opt/cpanel/ea-php72/root/usr/bin/php
    
  • PHP 7.3
    /opt/cpanel/ea-php73/root/usr/bin/php
    
  • PHP 7.4
    /opt/cpanel/ea-php74/root/usr/bin/php
    
  • PHP 8.0
    /opt/cpanel/ea-php80/root/usr/bin/php
    
  • PHP 8.1
    /opt/cpanel/ea-php81/root/usr/bin/php
    
  • PHP 8.2
    /opt/cpanel/ea-php82/root/usr/bin/php
    
  • PHP 8.3
    /opt/cpanel/ea-php83/root/usr/bin/php
    

 

How to use PHP in the terminal

To use PHP in the terminal, you have to specify the full path to the PHP binary. For example, to run composer install using PHP 8.0, you can run the following command:

/opt/cpanel/ea-php80/root/usr/bin/php /usr/local/bin/composer install

 

Adding PHP to the PATH

To add PHP to the PATH, you can create a symbolic link to the PHP binary. For example, to add PHP 8.3 to the PATH, you can run the following command:

ln -s /opt/cpanel/ea-php82/root/usr/bin/php /usr/local/bin/php

After running this command, you can use PHP in the terminal without specifying the full path to the PHP binary.

Alternatively, you can add the following line to your ~/.bashrc file:

export PATH=/opt/cpanel/ea-php82/root/usr/bin:$PATH

You can add this to your ~/.bashrc file by running the following commands:

cd ~
echo 'export PATH=/opt/cpanel/ea-php82/root/usr/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

Remember to adjust the ea-php82 part of the path to match the version of PHP you want to use.

After adding this line, you can use PHP in the terminal without specifying the full path to the PHP binary.

For example, you can run the following command to check the PHP version:

php -v