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:
This 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:
Upload the file to your website’s root directory.
Visit
https://yourdomain.com/phpinfo.php
in 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:
Replace php81
with your desired PHP version.
Change PHP Version via Command Line (Linux)
For VPS or dedicated servers:
List available PHP versions:
Change PHP version:
Verify the change:
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_limit
upload_max_filesize
post_max_size
max_execution_time
Save changes.
Modify PHP Settings via php.ini
For servers with direct access to PHP configuration files:
Locate the
php.ini
file:Edit it using a text editor:
Modify values, for example:
Save and restart the web server:
Modify PHP Settings via .htaccess
If you do not have access to php.ini
, modify settings via .htaccess
:
Save the file and check if the changes take effect.
Modify PHP Settings via CLI
For CLI applications:
Troubleshooting 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.log
or/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:
Check for multiple
php.ini
files using:Verify changes with
phpinfo()
.
"Extensions Not Loading"
Enable necessary PHP extensions in cPanel > Select PHP Version.
Install missing extensions via CLI:
Restart 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?