SSH Access and PHP Version Management
Secure Shell (SSH) is a protocol that provides secure command-line access to your hosting account. This guide is to explain how to connect your hosting account via SSH and how to update PHP to a different version.
Table of Contents:
-
How to Access Your Hosting Account via SSH
-
Windows - Access SSH via Third-Party Clients
-
macOS/Linux - Access SSH via Terminal
-
Control Panel - Access SSH via Terminal
-
-
How to Run Different PHP Versions via SSH
-
Available PHP Handlers
-
How to Check your PHP Version via SSH
How to Access Your Hosting Account via SSH
With SSH, you use a terminal (or Shell) client to connect to the server. There are many different types of SSH clients you can choose, depending on your operating system, but the process is similar.
Windows - Access SSH via Third-Party Clients
If you are a Microsoft Windows user, you will need to connect to your server via a third-party SSH client. Every Windows SSH client has its own way to be installed and launched, but once you've set it up, there is no difference in further operations.
-
Download your SSH client such as PuTTY, WinSCP, or other terminal applications.
-
Open your SSH client, Enter your IP address and the appropriate port number.
-
Note that modern Windows versions come with built-in SSH capabilities through Windows Command Prompt or PowerShell.
macOS/Linux - Access SSH via Terminal
Both Mac OS X and Linux (which are UNIX based OS) include SSH clients, so there is no need to install any third-party clients. Simply start up a terminal to connect to your hosting account via SSH.
To open the terminal in Mac, go to Applications → Utilities → Terminal. Otherwise, you can use the keyboard shortcut Command + Space.
A window with a user$ sign and a blinking cursor will open. That's the basic command prompt. You can use it to establish an SSH connection to your hosting server.
To connect, execute the following command:
ssh USER@SERVER -p PORT
-
USER - input the user for whom you want to establish the SSH connection, which would be your control panel username.
-
SERVER - hostname or IP of the server you need to establish connecting with.
-
PORT - connection port. As the standard port 22 can be an easy target for attackers, many web hosts change the SSH port to a custom port.
Your computer will now attempt to establish a connection with your hosting server. If that's the first time you're trying to connect to the server, you will see a message that's asking you to confirm your connection request. Type Yes and press Enter to proceed.
There will be a request to input your control panel account password. Type it in and press Enter. Keep in mind that the cursor will not move while you are typing in your password.
If everything is okay, your line will now begin with [user@server ~]$. That will indicate a successfully established SSH connection to the hosting server.
Control Panel - Access SSH via Terminal
Some control panel interfaces offer access to an in-browser application for direct command-line (CLI) within a control panel session. To access this feature, do the following:
Open your control panel and look for a Terminal or SSH Access section.
There might be a warning notice, which pops up if you are using the Terminal for the first time. Click to proceed.
With the control panel Terminal, you will not have to input your username and password, because you are already logged in. You can now run your SSH commands.
How to Run Different PHP Versions via SSH
Every website owner knows that the security and performance of their website are important. PHP gets better in terms of performance and security with each new version, and thus you would want your site to run on appropriate PHP versions. You can accomplish that via SSH, not only through the visual PHP selector in your control panel.
So, you already know how to access your hosting account via SSH, let us now help you with the commands you need to run for different PHP versions. We currently offer various PHP versions including PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, and 8.3.
Assuming you have already logged in to your hosting account via SSH session, all you have to do now is open the .htaccess file and edit it. Here is the command you need:
nano public_html/.htaccess
Once you have opened the file you can customize the version of PHP that runs your PHP files by directly editing your .htaccess file. To do so add one of the following directives in the .htaccess file of your website:
Available PHP Handlers
# To switch to PHP 8.3: AddHandler application/x-httpd-php83 .php .php5 # To switch to PHP 8.2: AddHandler application/x-httpd-php82 .php .php5 # To switch to PHP 8.1: AddHandler application/x-httpd-php81 .php .php5 # To switch to PHP 8.0: AddHandler application/x-httpd-php80 .php .php5 # To switch to PHP 7.4: AddHandler application/x-httpd-php74 .php .php5 # To switch to PHP 7.3: AddHandler application/x-httpd-php73 .php .php5 .php4 .php3 # To switch to PHP 7.2: AddHandler application/x-httpd-php72 .php .php5 .php4 .php3 # To switch to PHP 7.1: AddHandler application/x-httpd-php71 .php .php5 .php4 .php3 # To switch to PHP 7.0: AddHandler application/x-httpd-php70 .php .php5 .php4 .php3 # To switch to PHP 5.6: AddHandler application/x-httpd-php56 .php .php5 .php4 .php3
This will change the PHP version for that site and all of its subfolders. In case you'd like to have a different version of PHP in a subdirectory, create a new .htaccess file in it with the directive for the desired PHP version.
Alternatively, you can use SetHandler directives:
# To switch to PHP 8.3: <FilesMatch ".(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp83 </FilesMatch> # To switch to PHP 8.2: <FilesMatch ".(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp82 </FilesMatch> # To switch to PHP 8.1: <FilesMatch ".(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp81 </FilesMatch> # To switch to PHP 8.0: <FilesMatch ".(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp80 </FilesMatch> # To switch to PHP 7.4: <FilesMatch ".(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp74 </FilesMatch> # To switch to PHP 7.3: <FilesMatch ".(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp73 </FilesMatch> # To switch to PHP 7.2: <FilesMatch ".(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp72 </FilesMatch> # To switch to PHP 7.1: <FilesMatch ".(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp71 </FilesMatch> # To switch to PHP 7.0: <FilesMatch ".(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp70 </FilesMatch> # To switch to PHP 5.6: <FilesMatch ".(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp56 </FilesMatch>
After you add the to your .htaccess file, you have to press ^X (Ctrl+X) to exit the Terminal. When you are asked to confirm the changes - press Y (for Yes).
How to Check your PHP Version via SSH
Double-checking is always a good idea. If you're interested in implementing new features on your website or are trying to pinpoint a bug you want to check your PHP version while you are still in the Terminal. You can do that by using the following input:
php -v
You will see an output similar to the one in this sample:
PHP 8.1.12 (cli) (built: Oct 25 2022 16:29:56) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.1.12, Copyright (c) Zend Technologies
Conclusion
There are many reasons why you should run appropriate PHP versions, but probably the most important ones are the increase in website security and performance. So, for both you and your visitors to enjoy a faster and safer website, you should maintain appropriate PHP versions for your applications.