Enabling ssh and using different versions of php


Default php version


By default, when using the console, the php version set as basic on the server is used. To be able to use the terminal and use another selected php version, follow these steps:

1)Enable SSH for the account in the client panel

In first step you need to go to smarthost.eu/panel to the services tab and then click the gear icon on the hosting bar, as shown in the screenshot below.


In the next step, enable ssh by going to the settings tab and clicking the switch to turn orange.

2)Configuration of the selected php version

When ssh is already enabled on the account, go to the hosting panel (cPanel) and enter the terminal application.

After clicking, a terminal window will appear in which you must enter the command:

nano .bashrc


Then, in the file, add one of the aliases for the required PHP version under the line “# User specific aliases and functions”, below is a list of what the entry should look like for different PHP versions.

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


The final entry in the file should look like this (php 8.1 was used for the demonstration):


All that remains is to save the file by pressing the ctrl+o key combination, clicking the enter key and pressing ctr+x to exit the file editing.


The last step is to run the command to reload the configuration:

. .bashrc

3)Working on a defined php version

After performing the actions in steps 1 and 2, we can use the terminal with the php version defined in the file.
The alias is called using the phpxx prefix, where xx must be replaced by the appropriately selected php version, in this guide it will be php81.

To check if it works, we can run the command:

php81 -v

After running the command, information about the php version used will be displayed:

Usage example

The command with php 8.1 alias looks like this:

php81 command_to_execute

The word “command_to_execute” should be replaced by command you want to run.

Composer


The composer command with php 8.1 alias looks like this:

php81 /opt/cpanel/composer/bin/composer command_to_execute

The word “command_to_execute” should be replaced by the composer command.

Laravel

laravel command looks like this:

php81 /opt/cpanel/composer/bin/composer create-project laravel/laravel installation_dir "5.0.*" --prefer-dist

Run without alias

If you have not created an alias in point 2 of this guide, you can also alternatively use the full path:

/opt/cpanel/ea-php81/root/usr/bin/php /opt/cpanel/composer/bin/composer create-project laravel/laravel installation_dir "5.0.*" --prefer-dist
Tomasz
Latest posts by Tomasz (see all)