How to Use SSH on Shared Hosting Plans to Change PHP Version

When managing a website, you often need to juggle multiple tools, scripts, and frameworks that require different PHP versions. While most hosting control panels make it easy to change the PHP version for your website, handling that same version through a command-line interface can be less intuitive. If you’re running scheduled tasks, testing custom scripts, or managing deployments, you need your command-line environment to match your web environment.
For small business owners managing their own infrastructure, tapping into your server via SSH saves time. Instead of navigating a graphical interface every time you need to run a quick command, you can handle it directly from the terminal. Here’s how to safely and effectively change your PHP version via SSH on shared hosting plans.
Enabling SSH Access on Shared Hosting Plans
Before you can run any commands, you’ll want to make sure your hosting account actually has SSH access enabled. On shared hosting, SSH is sometimes disabled by default for security reasons. Modern shared hosting environments provide multi-PHP support, but access to the command line must usually be explicitly activated via your control panel.
Locating SSH Access Features in the Hosting Control Panel
Log into your cPanel (or equivalent hosting dashboard) and look for the “SSH Access” or “Terminal” icon. If you’re using cPanel, you’ll often find a built-in terminal right in the dashboard, which requires no additional setup. If you prefer using an external client like PuTTY or macOS Terminal, you’ll need to ensure your IP address is whitelisted and your SSH credentials are active.
Generating and Registering SSH Keys for Authentication
For a secure connection, password authentication is acceptable, but SSH keys are much safer. From your local terminal, you can generate a key pair using the following command:
ssh-keygen -t ed25519 -C "[email protected]"
Once generated, you’ll need to upload the public key (id_ed25519.pub) to your hosting control panel under the SSH Access section. This registers your local machine as a trusted client, allowing you to log in without typing your account password each time.
Understanding PHP CLI Execution vs. Web Server PHP
A common stumbling block for server administrators is realizing that the PHP version serving your website does not automatically dictate the PHP version used when you type php in SSH. These are two separate execution environments.
The Distinction Between MultiPHP Manager Web Settings and CLI Binaries
When you use the MultiPHP Manager in cPanel to set your domain to PHP 8.1, you’re telling the web server (Apache or LiteSpeed) which interpreter to use for HTTP requests. However, your SSH session relies on the system’s command-line interface (CLI) binary path. Sometimes these are synchronized, but often they drift, meaning running a Composer install or a custom cron job might execute under an older PHP version like 7.4.
Verifying the Active CLI PHP Version with php -v
To see exactly what your command line is currently using, simply run:
php -v
This will output the active CLI PHP version and should be run immediately after modifying any environment variables or shell profiles to confirm your changes took effect.
Executing PHP Scripts via Specific Versions in SSH
If you only need to run a specific script under a newer PHP version without changing your global CLI configuration, you can bypass the default version entirely.
Using cPanel cpcli for Synchronized CLI and Web PHP Versions
In cPanel environments, the cpcli utility is incredibly helpful. It allows you to run PHP scripts from the command line using the exact PHP version configured for that specific domain in MultiPHP Manager. This ensures synchronization across both web and CLI environments. You can typically use it like this:
cpcli php /home/username/script.php
Calling Direct PHP Binaries Using Absolute Paths
If cpcli is unavailable or you want targeted version execution, administrators use absolute binary paths. Most modern shared servers store multiple PHP versions in specific directories. For example:
/opt/remi/php81/root/usr/bin/php /home/username/script.php
For cPanel servers using EasyApache 4, the paths look slightly different but follow the same structure:
/opt/cpanel/ea-php81/root/usr/bin/php /home/username/script.php
This forces the script to run under PHP 8.1 regardless of what the default php command is symlinked to.
Overriding the Default PHP CLI Version via Shell Profiles
If you frequently use the command line and don’t want to type out absolute paths every single time, you can modify your shell profile to change the default PHP version for your user session.
Configuring PHP Version Aliases in .bashrc
If your shared hosting platform supports a .bashrc profile, you can create an alias for the PHP version you prefer. First, verify the exact path of the PHP binary you want to use. Then, edit your .bashrc file:
nano ~/.bashrc
Add the following line to create a shortcut that overrides the default binary path:
alias php='/usr/local/bin/php81'
Be sure to replace the path with the actual absolute path for the PHP version on your specific server.
Reloading Shell Profiles and Validating the New Default Version
The alias won’t take effect in your current session immediately. You must reload the shell profile by running:
source ~/.bashrc
<p”Now, run php -v again. It should now report the new version you assigned.
Managing php.ini Settings Without Root Access
<p-Changing the PHP version is only half the battle; configuration settings like memory limits and execution times are equally important. On a shared server, you don’t have root access.
Shared Hosting Restrictions on Global php.ini Modifications
You cannot alter the global php.ini file via SSH because it affects every user on the shared server. Attempting to edit it will result in a permission denied error. Configuration changes must be made using the INI editor in the hosting control panel.
Applying Local php.ini Files for Directory-Specific Configuration
If you need specific settings for a single application or directory, you can create a local php.ini file in that directory via SSH:
nano /home/username/public_html/app/php.ini
Add your custom directives here, such as memory_limit = 256M. Note that on some servers running PHP-FPM or LiteSpeed, local php.ini files are ignored, and you must use .user.ini instead. If your changes aren’t taking effect, try renaming the file:
mv php.ini .user.ini
Troubleshooting Common SSH PHP Issues
<td_USE_the_absolute_path (e.g., /opt/cpanel/ea-php81/root/usr/bin/php) or add an alias in your .bashrc file.
| Symptom | Cause | Fix |
|---|---|---|
-bash: php: command not found | The PHP binary is not in your user’s PATH environment variable. | |
Editphp.ini results in permission denied error. | You’re trying to edit global server configuration without root privileges. | Create_a_local_.user.ini file in_your web directory instead. |
| Cron jobs run an older PHP version despite .bashrc alias. | Cron doesn’t load user shell profiles automatically. | Edit_your_crontab_and_replace_’php’_with_the_full_absolute_path (e.g., /opt/cpanel/ea-php81/root/usr/bin/php). |
| Your hosting provider doesn’t include cPanel’s cpcli utility or uses an alternative control panel. | Rely_on_direct_binary_execution_using_absolute_paths_from_/opt/cpanel/ea-phpXX/root/usr/bin/php. |
Troubleshooting Common Issues
< USe_the_absolute_path_(e .g ., _/opt/cpanel/ea-php80/root/usr/bin/php )_or_add_an_alias_in_your_.bashrc_file .
Edithttps : // permission denied error when editing php .ini
td >You ‘re trying_to_edit_global_server_configuration_without_root_privileges . / td >
td > Create_a_local_.user .ini_file_in_your_web_directory_instead . / td >
/ tr >
Cron jobs_run_an_older_PHP_version_despite_.bashrc_alias .
td > Cron_doesn ‘t_load_user_shell_profiles_automatically ./ td >
Edit_your_crontab_and_replace_’php’_with_the_full_absolute_path_(e .g ., _/opt/cpanel/ea-php81/root/usr/bin/php )._ fj
) cpcli : _command_not_found
td > Your_hosting_provider_doesn ‘t_include_cPanel ‘s_cpcli_utility_or_uses_an_alternative_control_panel ./ td >
Rely_on_direct_binary_execution_using_absolute_paths_from_/opt/cpanel/ea-phpXX/root/usr/bin/php ./ td >
/ tr >
/tbody >
/ table >
Best_Practices_for_Managing_PHP_via_SSH
-
ch li > Synchronize_Web_and_CLI_Versions : // strong >/ li > Whenever_you_update_MultiPHP_Manager_in_cPanel , _verify_your_CLI_version_matches_to_prevent_deployment_errors_with_tools_like_Composer_or_Drush . / li >
ch li > Avoid_EOL_Versions : // strong >/ li > Always_check_the_official_PHP_supported_versions_list ./ Running_an_End – of – Life_version_leaves_your_business_vulnerable_to_script_execution_vulnerabilities_and_data_breaches ./ li >
Absolut
fh2>Frequently_Asked_Questions/h2
Does_changing_the_PHP_version_in_cPanel ‘s_MultiPHP_Manager_affect_my_SSH_command_line_(CLI )_version ?// summary /
In_many_cPanel_environments , _selecting_a_PHP_version_in_MultiPHP_Manager_synchronizes_the_web_server_and_the_default_CLI_PHP_versions ./ However , _this_depends_on_your_host ‘s_specific_configuration ./ You_should_always_verify_your_active_CLI_version_using_the_’php_-v ‘_command_after_making_changes_in_the_control_panel ./ div >
/details /
How_can_I_run_a_specific_PHP_script_with_a_different_PHP_version_without_changing_my_global_CLI_default ?// summary /
You_can_execute_a_specific_PHP_version_directly_by_calling_its_absolute_binary_path_from_the_command_line ./ For_example , _instead_of_typing_’php_script .php ‘, _you_would_use_a_path_like_’/opt/remi/php81/root/usr/bin/php_script .php ‘_to_force_execution_with_PHP_8 ./ div >
/details /
Can_I_permanently_change_my_default_SSH_PHP_version_using_my_shell_profile ?// summary /
Yes , _if_your_hosting_provider_allows_it , _you_can_override_the_default_PHP_binary_by_adding_an_alias_to_your_’ .bashrc ‘_file_(e ._g ., _alias_php = ‘/usr/local/bin/php81 ‘)._After_saving_the_file , _reload_your_shell_profile_for_the_changes_to_take_effect ./ div >
/details /
Why_can ‘t_I_edit_the_global_php .ini_file_directly_via_SSH_on_a_shared_hosting_plan ?// summary /
Shared_hosting_environments_restrict_global_php .ini_modifications_to_prevent_one_user ‘s_settings_from_affecting_all_other_accounts_on_the_server ./ To_customize_PHP_settings , _you_must_use_the_hosting_control_panel ‘s_INI_editor_or_upload_a_local_php .ini_file_to_the_specific_directory_requiring_custom_configuration ./ div >
/details /
What_are_the_security_risks_of_running_an_End – of – Life_(EOL )_PHP_version_via_CLI ?// summary /
EOL_PHP_versions_no_longer_receive_security_patches , _making_them_highly_vulnerable_to_exploits_and_script_execution_vulnerabilities ./ Updating_to_a_supported , _actively_maintained_PHP_version_is_critical_for_securing_your_applications_and_preventing_server_compromise ./ div >
/details /
Do_all_shared_hosting_plans_come_with_SSH_access_enabled_by_default ?// summary /
No , _many_entry – level_shared_hosting_plans_disable_SSH_access_by_default_for_security_reasons_or_require_you_to_explicitly_enable_it ./ You_typically_need_to_generate_and_register_SSH_keys_through_your_hosting_control_panel_before_you_can_connect_securely ./ div >
/details >
Related reading
/details /
How_can_I_run_a_specific_PHP_script_with_a_different_PHP_version_without_changing_my_global_CLI_default ?// summary /
You_can_execute_a_specific_PHP_version_directly_by_calling_its_absolute_binary_path_from_the_command_line ./ For_example , _instead_of_typing_’php_script .php ‘, _you_would_use_a_path_like_’/opt/remi/php81/root/usr/bin/php_script .php ‘_to_force_execution_with_PHP_8 ./ div >
/details /
Can_I_permanently_change_my_default_SSH_PHP_version_using_my_shell_profile ?// summary /
Yes , _if_your_hosting_provider_allows_it , _you_can_override_the_default_PHP_binary_by_adding_an_alias_to_your_’ .bashrc ‘_file_(e ._g ., _alias_php = ‘/usr/local/bin/php81 ‘)._After_saving_the_file , _reload_your_shell_profile_for_the_changes_to_take_effect ./ div >
/details /
Why_can ‘t_I_edit_the_global_php .ini_file_directly_via_SSH_on_a_shared_hosting_plan ?// summary /
Shared_hosting_environments_restrict_global_php .ini_modifications_to_prevent_one_user ‘s_settings_from_affecting_all_other_accounts_on_the_server ./ To_customize_PHP_settings , _you_must_use_the_hosting_control_panel ‘s_INI_editor_or_upload_a_local_php .ini_file_to_the_specific_directory_requiring_custom_configuration ./ div >
/details /
What_are_the_security_risks_of_running_an_End – of – Life_(EOL )_PHP_version_via_CLI ?// summary /
EOL_PHP_versions_no_longer_receive_security_patches , _making_them_highly_vulnerable_to_exploits_and_script_execution_vulnerabilities ./ Updating_to_a_supported , _actively_maintained_PHP_version_is_critical_for_securing_your_applications_and_preventing_server_compromise ./ div >
/details /
Do_all_shared_hosting_plans_come_with_SSH_access_enabled_by_default ?// summary /
No , _many_entry – level_shared_hosting_plans_disable_SSH_access_by_default_for_security_reasons_or_require_you_to_explicitly_enable_it ./ You_typically_need_to_generate_and_register_SSH_keys_through_your_hosting_control_panel_before_you_can_connect_securely ./ div >
/details >
Related reading
/details /
Can_I_permanently_change_my_default_SSH_PHP_version_using_my_shell_profile ?// summary /
Yes , _if_your_hosting_provider_allows_it , _you_can_override_the_default_PHP_binary_by_adding_an_alias_to_your_’ .bashrc ‘_file_(e ._g ., _alias_php = ‘/usr/local/bin/php81 ‘)._After_saving_the_file , _reload_your_shell_profile_for_the_changes_to_take_effect ./ div >
/details /
Why_can ‘t_I_edit_the_global_php .ini_file_directly_via_SSH_on_a_shared_hosting_plan ?// summary /
Shared_hosting_environments_restrict_global_php .ini_modifications_to_prevent_one_user ‘s_settings_from_affecting_all_other_accounts_on_the_server ./ To_customize_PHP_settings , _you_must_use_the_hosting_control_panel ‘s_INI_editor_or_upload_a_local_php .ini_file_to_the_specific_directory_requiring_custom_configuration ./ div >
/details /
What_are_the_security_risks_of_running_an_End – of – Life_(EOL )_PHP_version_via_CLI ?// summary /
EOL_PHP_versions_no_longer_receive_security_patches , _making_them_highly_vulnerable_to_exploits_and_script_execution_vulnerabilities ./ Updating_to_a_supported , _actively_maintained_PHP_version_is_critical_for_securing_your_applications_and_preventing_server_compromise ./ div >
/details /
Do_all_shared_hosting_plans_come_with_SSH_access_enabled_by_default ?// summary /
No , _many_entry – level_shared_hosting_plans_disable_SSH_access_by_default_for_security_reasons_or_require_you_to_explicitly_enable_it ./ You_typically_need_to_generate_and_register_SSH_keys_through_your_hosting_control_panel_before_you_can_connect_securely ./ div >
/details >
Related reading
/details /
Why_can ‘t_I_edit_the_global_php .ini_file_directly_via_SSH_on_a_shared_hosting_plan ?// summary /
Shared_hosting_environments_restrict_global_php .ini_modifications_to_prevent_one_user ‘s_settings_from_affecting_all_other_accounts_on_the_server ./ To_customize_PHP_settings , _you_must_use_the_hosting_control_panel ‘s_INI_editor_or_upload_a_local_php .ini_file_to_the_specific_directory_requiring_custom_configuration ./ div >
/details /
What_are_the_security_risks_of_running_an_End – of – Life_(EOL )_PHP_version_via_CLI ?// summary /
EOL_PHP_versions_no_longer_receive_security_patches , _making_them_highly_vulnerable_to_exploits_and_script_execution_vulnerabilities ./ Updating_to_a_supported , _actively_maintained_PHP_version_is_critical_for_securing_your_applications_and_preventing_server_compromise ./ div >
/details /
Do_all_shared_hosting_plans_come_with_SSH_access_enabled_by_default ?// summary /
No , _many_entry – level_shared_hosting_plans_disable_SSH_access_by_default_for_security_reasons_or_require_you_to_explicitly_enable_it ./ You_typically_need_to_generate_and_register_SSH_keys_through_your_hosting_control_panel_before_you_can_connect_securely ./ div >
/details >
Related reading
/details /
What_are_the_security_risks_of_running_an_End – of – Life_(EOL )_PHP_version_via_CLI ?// summary /
EOL_PHP_versions_no_longer_receive_security_patches , _making_them_highly_vulnerable_to_exploits_and_script_execution_vulnerabilities ./ Updating_to_a_supported , _actively_maintained_PHP_version_is_critical_for_securing_your_applications_and_preventing_server_compromise ./ div >
/details /
Do_all_shared_hosting_plans_come_with_SSH_access_enabled_by_default ?// summary /
No , _many_entry – level_shared_hosting_plans_disable_SSH_access_by_default_for_security_reasons_or_require_you_to_explicitly_enable_it ./ You_typically_need_to_generate_and_register_SSH_keys_through_your_hosting_control_panel_before_you_can_connect_securely ./ div >
/details >
Related reading
/details /
Do_all_shared_hosting_plans_come_with_SSH_access_enabled_by_default ?// summary /
No , _many_entry – level_shared_hosting_plans_disable_SSH_access_by_default_for_security_reasons_or_require_you_to_explicitly_enable_it ./ You_typically_need_to_generate_and_register_SSH_keys_through_your_hosting_control_panel_before_you_can_connect_securely ./ div >
/details >
Related reading
/details >
Related reading
| Symptom | Cause | Fix |
|---|---|---|
| The PHP binary is not in_your_user’s_PATH_environment_variable . |