How to Change PHP Version & Settings
PHP is a widely used scripting language for web development, and different applications may require different PHP versions or settings to function properly. Whether you need to upgrade for security reasons, downgrade for compatibility, or modify settings for performance, this guide will show you how to change your PHP version and customize settings on different platforms.
Why Change PHP Version?
Changing the PHP version can be necessary for several reasons:
Application Compatibility: Some websites and applications require a specific PHP version.
Security Updates: Newer PHP versions include important security patches.
Performance Optimization: Later PHP versions improve performance and reduce resource usage.
Feature Support: Some functions and libraries are only available in newer versions of PHP.
How to Check Your Current PHP Version
Before making changes, check the current PHP version running on your server.
Check PHP Version via Command Line
If you have SSH access, run the following command:
php -vThis will display the installed PHP version.
Check PHP Version via cPanel
Log in to cPanel.
Navigate to Software > Select PHP Version.
Your current PHP version will be displayed at the top of the page.
Check PHP Version via a PHP Script
Create a new file called
phpinfo.php.Add the following code:
<?php phpinfo(); ?>Upload the file to your website’s root directory.
Visit
https://yourdomain.com/phpinfo.phpin your browser.
How to Change PHP Version
Change PHP Version in cPanel
Log in to cPanel.
Go to Select PHP Version under the Software section.
Use the dropdown menu to choose your desired PHP version.
Click Set as Current to apply the change.
If needed, enable or disable PHP extensions.
Change PHP Version in Plesk
Log in to Plesk.
Navigate to Websites & Domains > PHP Settings.
Use the dropdown menu to select a different PHP version.
Click Apply or OK to save changes.
Change PHP Version Using .htaccess (Apache Servers)
If your server allows .htaccess overrides, add this line:
AddHandler application/x-httpd-php81 .phpReplace php81 with your desired PHP version.
Change PHP Version via Command Line (Linux)
For VPS or dedicated servers:
List available PHP versions:
update-alternatives --list phpChange PHP version:
sudo update-alternatives --set php /usr/bin/php8.1Verify the change:
php -v
How to Modify PHP Settings
Certain applications may require modifications to PHP settings like memory limit, max execution time, and file upload size.
Modify PHP Settings via cPanel
Log in to cPanel.
Go to Select PHP Version > Options.
Adjust settings such as:
memory_limitupload_max_filesizepost_max_sizemax_execution_time
Save changes.
Modify PHP Settings via php.ini
For servers with direct access to PHP configuration files:
Locate the
php.inifile:find /etc -name php.iniEdit it using a text editor:
sudo nano /etc/php/8.1/apache2/php.iniModify values, for example:
memory_limit = 256M max_execution_time = 300 upload_max_filesize = 64MSave and restart the web server:
sudo systemctl restart apache2
Modify PHP Settings via .htaccess
If you do not have access to php.ini, modify settings via .htaccess:
php_value memory_limit 256M
php_value max_execution_time 300
php_value upload_max_filesize 64MSave the file and check if the changes take effect.
Modify PHP Settings via CLI
For CLI applications:
php -d memory_limit=256M script.phpTroubleshooting PHP Version Issues
"500 Internal Server Error" After Changing PHP Version
Ensure that required PHP extensions are enabled.
Check the error log (
/var/log/apache2/error.logor/var/log/nginx/error.log).Try switching back to a previous PHP version to see if the issue resolves.
"php.ini Changes Not Taking Effect"
Restart Apache or Nginx:
sudo systemctl restart apache2sudo systemctl restart nginxCheck for multiple
php.inifiles using:php --iniVerify changes with
phpinfo().
"Extensions Not Loading"
Enable necessary PHP extensions in cPanel > Select PHP Version.
Install missing extensions via CLI:
sudo apt install php8.1-mbstringRestart PHP services after installing extensions.
Conclusion
Changing PHP versions and modifying settings is essential for compatibility, security, and performance. Whether using cPanel, Plesk, CLI, or .htaccess, following the correct steps ensures a smooth transition. Regularly updating to supported PHP versions and optimizing settings helps keep your applications running efficiently.
Last updated
Was this helpful?

