I checked the PHP version in Lightsail SSH protocol and it was different from the web server. So I looked into it to see if there could be a problem, and found out that unexpected errors can occur if the versions are different.
The content was that if the PHP version of the web server you are using is different from the PHP version when you enter the php -v command after connecting via SSH, debugging may become complicated and may not function properly due to version differences in the development and deployment environment of the PHP code.
So, you need to upgrade so that the versions are the same. In the case of web servers, you can easily upgrade using management panels such as Cpanel and Cyberpanel. If you are in an environment without a management panel, you can use the latest version of PHP by replacing the instance.
SSH can easily upgrade PHP by running a few commands. Since the problem will be solved if you install the same PHP version as the web server, please refer to the explanation below and enter the commands in order.
The description below is the same installation process for PHP 8.2, so if you have a different version, just enter a different version in the description below.
Table of Contents
Check web server version
The easiest way to check the PHP version on your web server is to go to WordPress > Tools > Site Health , then click About at the top, and you’ll see Server Information.
If you are not in a WordPress environment, you can check by connecting via SSH and entering the command below.
- LiteSpeed : ps aux | grep php-fpm
- Apache : apachectl -M | grep php
- Nginx : cat /etc/nginx/sites-available/default
If you have checked the PHP version of the web server you are currently using using the command above, you can now check which version of PHP is being used via SSH.
Check CLI PHP version
If you type php -v in the SSH protocol , you can check the current CLI (Command Line Interface) PHP version as shown above. Let’s learn about SSH and CLI here.
This may be a difficult part, but I’ll explain the terms below because you might need them when searching.
- SSH (Secure Shell) : A protocol that allows you to connect to a remote system in a secure manner. Using SSH, you can securely connect to a remote server and execute commands.
- CLI(Command Line Interface) : An interface in which users interact with a computer system by entering text-based commands.
SSH is one of the tools available in the CLI, which is an interface where you can enter and execute various commands including SSH.
Change CLI PHP version
If the web server and CLI (Command Line Interface) PHP versions are different, you can upgrade by entering the command below. The command is written based on Ubuntu.
sudo apt list --installed | grep php8.2
First, by entering the command above, you can check if the php 8.2 package is installed.
sudo apt update
If you have checked the php 8.2 package list, you can proceed with the update by entering the command above.
sudo apt install php8.2-cli
Then, you can install PHP 8.2 CLI by entering the command above.
sudo update-alternatives --set php /usr/bin/php8.2
If you have installed PHP 8.2 CLI, you can now change the PHP CLI version by entering the command above.
php - v
Once all the steps are done, you can check the CLI PHP version by entering the php -v command. If the installation is done properly, you can enter the restart command that is appropriate for your server .
Although different versions may not cause major problems, it is recommended to set the PHP versions to the same value because problems may occur later.
▶ How to install Redis server on OpenliteSpeed web server
▶ LightSail CDN: Recapping How to Set Up LiteSpeed Cache
▶ How to install the OpenLiteSpeed (OLS) web server on Lightsail