How to resolve some common issues after a PHP upgrade

Newer versions of PHP offer greater stability, security, and features. However, you may experience problems with your web site after a PHP version upgrade. This article discusses some ways to resolve them.

Reverting to the previous version

If you experience problems after a PHP upgrade, you can always revert to an earlier version. To do this, use the PHP version tool in cPanel. For more information about how to change the PHP version for your web site, please see this article.

You may receive deprecation errors when you view your web site after a PHP upgrade. This is because functions or features that your site uses have been removed in the newer version. You can either modify your web site's code to make it compliant with the new version, or you can revert PHP to the previous version.

Copying an updated version of php.ini

If you use a custom php.ini file, make sure you use the correct file for your PHP version. For example:

  • If you are using PHP 5.3, copy the php.ini file located at /usr/local/lib/php.ini. This is the default php.ini file.
  • If you are using PHP 5.2.17, copy the php.ini file located at /opt/php/php-5.2.17/lib/php.ini.
  • You can find additional PHP versions in the /opt/php directory.

To copy the updated php.ini file to your public_html directory, log in to your account using SSH and then use the cp command. For example, the following command copies the default php.ini file to a user's public_html directory. Replace USERNAME with your own account username:

cp /usr/local/lib/php.ini /home/USERNAME/public_html/php.ini

To make the php.ini settings apply to all subdirectories, add the following line to your .htaccess file. Replace USERNAME with your own account username:

SuPHP_ConfigPath /home/USERNAME/public_html/
If you are using custom settings, such as allow_url_fopen or register_globals, you must reconfigure these settings after you copy the updated php.ini file.

For more information about how to use custom php.ini files, please see this article.

“500 Internal Server Error” messages after changing the PHP version

If you receive “500 Internal Server Error” messages after changing the PHP version on your web site, check the .htaccess file in your public_html directory. At the end of the .htaccess file you should see text similar to the following:

# Start A2 Switcher Block
# Do not remove or modify this block! Added by PHP Switcher from cPanel to use an alternate PHP version. Contact Support for details.
<IfModule mod_suphp.c>
  AddHandler application/x-httpd-php-5.4.13 .php
</IfModule>
# End A2 Switcher Block

The AddHandler value determines the PHP version for your site. Make sure that the correct version is specified, and that the line formatting is correct. Depending on how the .htaccess file was previously configured, you may find that lines of text have been merged, which could cause problems.

You may also see php_flag values configured in the .htaccess file. Any php_flag values should now be configured directly in a custom php.ini file. For more information about how to use custom php.ini files, please see this article.

Zend Optimizer and Zend Guard

In PHP 5.3, Zend Optimizer changed to Zend Guard Loader. If you already have a custom php.ini file that calls the old Zend Optimizer libraries, you may receive the following error message:

Fatal error: Incompatible file format: The encoded file has format major ID 2, whereas the Loader expects 4

To resolve this issue, you must invoke the correct Zend libraries for your PHP version:

  • For PHP 5.3, add the following line to your php.ini file:
    zend_extension="/usr/local/Zend/lib/Guard-5.5.0/php-5.3.x/ZendGuardLoader.so"
  • For PHP 5.2.17, add the following lines to your php.ini file:

    zend_extension=/opt/php/build/ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/ZendOptimizer.so
    zend_loader.enable=1

If you are receiving Ioncube loader errors, you may need to set your site to use PHP version 5.2.17. Copy over the php.ini file located at /opt/php/php-5.2.17/lib/php.ini, and then add the following line to the top of your php.ini file:

zend_extension="/usr/local/IonCube/ioncube_loader_lin_5.2.so"

To make the php.ini settings apply to all subdirectories, add the following line to your .htaccess file. Replace USERNAME with your own account username:

SuPHP_ConfigPath /home/USERNAME/public_html/

 

Using cron with PHP version 5.2.17

If you experience problems using cron with PHP version 5.2.17, make sure you set the path to PHP to /opt/php/php-5.2.17/bin/php.

The libraries for PHP version 5.2.17 are located in the /opt/php/php-5.2.17/include/php directory.

Still not working?

If you encounter problems using any of these methods, or are still experiencing issues, please open a support ticket on the A2 Hosting Customer Portal at https://my.a2hosting.com.

Article Details

  • Level: Intermediate

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.