π Introduction
CyberPanel is a powerful web hosting control panel powered by OpenLiteSpeed. Each website (virtual host or “vHost”) in CyberPanel has its own configuration file that specifies which version of PHP it uses.
When a new PHP version like 8.1 is installed, CyberPanel does not automatically update vHost configurations. If your sites are still using older versions like PHP 7.3, 7.4, or 8.0, you’ll need to manually update these configurations to point to PHP 8.1.
This guide explains how to update the PHP path for all virtual hosts using command-line tools and includes backup and rollback instructions for safety.
π οΈ Step-by-Step Guide
π Identify vHosts Using Old PHP Versions
Before making any changes, identify which vHost config files are using outdated PHP versions:
grep -r path /usr/local/lsws/conf/vhosts/*/vhost.conf | grep lsphp73
grep -r path /usr/local/lsws/conf/vhosts/*/vhost.conf | grep lsphp74
grep -r path /usr/local/lsws/conf/vhosts/*/vhost.conf | grep lsphp80
β What This Does:
- Scans all virtual host configuration files (
vhost.conf) under/usr/local/lsws/conf/vhosts/ - Looks for entries specifying the path to
lsphp73,lsphp74, orlsphp80, which indicate PHP 7.3, 7.4, or 8.0 is being used.
ποΈ Backup Virtual Host Configurations
Before modifying anything, create a backup of all vHost configuration files:
cp -prf /usr/local/lsws/conf/vhosts/ /usr/local/lsws/conf/vhosts_bk
β What This Does:
- Creates a full backup of all vHost configuration directories and files.
- If anything goes wrong during the update, you can easily restore this backup.
Β βοΈ Update PHP Paths in vHost Files to PHP 8.1
Now, update the configuration files to use the PHP 8.1 binary instead of the old versions:
Replace PHP 7.3 path with PHP 8.1 path
sed -i 's|/usr/local/lsws/lsphp73/bin/lsphp|/usr/local/lsws/lsphp81/bin/lsphp|g' /usr/local/lsws/conf/vhosts/*/vhost.conf
Replace PHP 7.4 path with PHP 8.1 path
sed -i 's|/usr/local/lsws/lsphp74/bin/lsphp|/usr/local/lsws/lsphp81/bin/lsphp|g' /usr/local/lsws/conf/vhosts/*/vhost.conf
Replace PHP 8.0 path with PHP 8.1 path
sed -i 's|/usr/local/lsws/lsphp80/bin/lsphp|/usr/local/lsws/lsphp81/bin/lsphp|g' /usr/local/lsws/conf/vhosts/*/vhost.conf
β What This Does:
- Uses
sedto search and replace the old PHP binary path with the PHP 8.1 binary path in allvhost.conffiles. - Ensures all websites that were using PHP 7.3, 7.4, or 8.0 are now using 8.1.
π Restart OpenLiteSpeed to Apply Changes
Restart the OpenLiteSpeed service to load the updated configuration files:
systemctl restart lsws
β What This Does:
- Applies the configuration changes.
- Without restarting, the web server may continue using the old settings.
β Verify the Changes
Run this command to confirm that all virtual hosts are now pointing to PHP 8.1:
grep -r path /usr/local/lsws/conf/vhosts/*/vhost.conf | grep lsphp81
Optional:
Also test your websites or create a phpinfo.php file in your siteβs root with the following content:
<?php phpinfo(); ?>
Access the file in your browser to confirm that PHP 8.1 is active.
π Rollback Instructions (If Needed)
If you experience issues after the upgrade, you can easily restore your previous settings:
cp -prf /usr/local/lsws/conf/vhosts_bk/* /usr/local/lsws/conf/vhosts/
systemctl restart lsws
π Additional Notes
- This process only updates the web server PHP version, not the command-line (CLI) PHP version. If you want to change the system-wide PHP CLI version, use
update-alternativesor your package manager (apt,yum, etc.). - Ensure that your applications are compatible with PHP 8.1 before making the switch.
- If PHP 8.1 is not installed yet, install it via CyberPanel or the LiteSpeed script repository.