How to Change CLI PHP on CyberPanel?

CyberPanel only install LiteSpeed PHPs from LiteSpeed repos. Installation directory for PHP is located at

/usr/local/lsws/lsphpXX

You need to replace XX in the path above with PHP version, for example the path for PHP version 7.4 is /usr/local/lsws/lsphp74

And PHP CLI binary path for each PHP version is

/usr/local/lsws/lsphpXX/bin/php

So PHP binary path for PHP 7.4 is /usr/local/lsws/lsphp74/bin/php

During installation CyberPanel installation code runs following command to set Global PHP CLI:

ln -s /usr/bin/php /usr/local/lsws/lsphp74/bin/php

Which means by default the Global PHP for CLI is 7.4, upon running php -v on command line you will get:

root@ip-172-31-34-208:~# php -v
PHP 7.4.16 (cli) (built: Mar  4 2021 16:36:45) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.16, Copyright (c), by Zend Technologies
root@ip-172-31-34-208:~#

How you can change the default version of PHP on CLI?

If you have certain needs and PHP 7.4 does not work for certain application you can run following command to update the default PHP on CLI.

Set Command line to PHP 8.0

ln -s /usr/bin/php /usr/local/lsws/lsphp80/bin/php

Set Command line to PHP 7.3

ln -s /usr/bin/php /usr/local/lsws/lsphp73/bin/php

Set Command line to PHP 7.2

ln -s /usr/bin/php /usr/local/lsws/lsphp72/bin/php

Set Command line to PHP 7.1

ln -s /usr/bin/php /usr/local/lsws/lsphp71/bin/php


How to use specific PHP Version in your Cron Jobs?

Some applications requires you to set cron jobs and they require PHP CLI executable. Now rather then changing default global php binary version, you can use direct path to that CLI.

For example an application requires that its script should be running through PHP 7.2, you can use the direct path for its binary rather then updating a global binary, such as

/usr/local/lsws/lsphp71/bin/php <your command goes here>

2 Likes

I get this error when I want to replace it with php 8.0

ln: failed to create symbolic link ‘/usr/local/lsws/lsphp80/bin/php’: File exists

2 Likes

I also got this error.

I then ran rm /usr/bin/php and tried again and it didn’t say anything but there’s no /usr/bin/php… I restored that with ln -s /etc/alternatives/php /usr/bin/php

I restored my server snapshot as it all got corrupted. Here’s some info on what is linked to what.

root@vps:/etc/apt# ls -l /etc/alternatives/php
lrwxrwxrwx 1 root root 15 Mar  4 06:54 /etc/alternatives/php -> /usr/bin/php7.4
root@vps:/etc/apt# ls -l /usr/bin/php
lrwxrwxrwx 1 root root 31 May 15 12:54 /usr/bin/php -> /usr/local/lsws/lsphp74/bin/php
root@vps:/etc/apt# ls -l /usr/local/lsws/lsphp74/bin/php
-rwxr-xr-x 1 root root 14944144 Apr 14 01:46 /usr/local/lsws/lsphp74/bin/php
root@vps:/etc/apt# ls -l /usr/bin/php7.4
-rwxr-xr-x 1 root root 4773816 Mar  2 09:36 /usr/bin/php7.4

Then I tried to check the alternatives for php and it said the link group was broken and reinstalled it. This changed the symlink for /usr/bin/php

root@vps:/etc/apt# update-alternatives --config php
There is only one alternative in link group php (providing /usr/bin/php): /usr/bin/php7.4
Nothing to configure.
update-alternatives: warning: forcing reinstallation of alternative /usr/bin/php7.4 because link group php is broken
root@vps:/etc/apt# ls -l /usr/bin/php
lrwxrwxrwx 1 root root 21 May 19 22:44 /usr/bin/php -> /etc/alternatives/php
root@vps:/etc/apt# ls -l /etc/alternatives/php
lrwxrwxrwx 1 root root 15 May 19 22:44 /etc/alternatives/php -> /usr/bin/php7.4

So, it seems clear that there is something wrong with the way CyberPanel creates the symlinks, which is as follows from the CyberPanel Code

rm -f /usr/bin/php
ln -s /usr/local/lsws/lsphp74/bin/php /usr/bin/php

Not sure what to do about it though

1 Like

I just set up a server with RunCloud for a different project and the end result is that it is the same as what CyberPanel does - just a symlink from /usr/bin/php -> /usr/local/lsws/lsphp74/bin/php. They don’t use any alternatives.

I will try later, but perhaps the solution is just to delete /usr/bin/php7.4 as well as the update-alternative php entry.

Isn’t that backwards?

ln -s [OPTIONS] FILE LINK

My CLI PHP 7.4 is PHP 7.1. Other versions is ok. Anyone know how to fix this?

[root@test bin]# ls -alh|grep php
lrwxrwxrwx   1 root    root       37 May 18  2020 alt-mysql-reconfigure -> /usr/bin/alt-php-mysql-reconfigure.py
lrwxrwxrwx   1 root    root       37 May 18  2020 alt-php-mysql-reconfigure -> /usr/bin/alt-php-mysql-reconfigure.py
-rwxr-xr-x   1 root    root      22K May 18  2020 alt-php-mysql-reconfigure.py
lrwxrwxrwx   1 root    root       31 Sep 23 11:16 php -> /usr/local/lsws/lsphp74/bin/php
[root@test bin]# php -v
PHP 7.1.33 (cli) (built: Nov 22 2019 11:33:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with the ionCube PHP Loader + ionCube24 v10.3.9, Copyright (c) 2002-2019, by ionCube Ltd.
    with Zend OPcache v7.1.33, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.9.0, Copyright (c) 2002-2019, by Derick Rethans
[root@test bin]# /usr/local/lsws/lsphp74/bin/php -v
PHP 7.1.33 (cli) (built: Nov 22 2019 11:33:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with the ionCube PHP Loader + ionCube24 v10.3.9, Copyright (c) 2002-2019, by ionCube Ltd.
    with Zend OPcache v7.1.33, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.9.0, Copyright (c) 2002-2019, by Derick Rethans

sh <(curl https://raw.githubusercontent.com/tbaldur/cyberpanel-mods/main/phpmod.sh || wget -O - https://raw.githubusercontent.com/tbaldur/cyberpanel-mods/main/phpmod.sh)