How to upgrade from PHP 7 to PHP 8

Introduction

As of SimpleRisk 20230106-001 PHP 7 is no longer supported, in this FAQ we will cover the steps to upgrading PHP on Ubuntu. These steps should apply to other distros as well but may require slight changes to the package manager used or the name for apache being httpd.

How To Upgrade

Upgrading PHP is actually quite simple and can be done running the following commands 1 at a time:

sudo apt install software-properties-common

sudo add-apt-repository ppa:ondrej/php -y

sudo apt update

sudo apt dist-upgrade -y

sudo apt install php-intl -y

Once completed you should then restart and enable php 8 apache using:

sudo a2dismod php7.4

sudo a2enmod php8.2

Now we need to make a stop to update the PHP.ini and update the memory_limit to 256mb and the max_input_vars to 3000.


sudo vi /etc/php/8.2/apache2/php.ini


Find memory_limit. Hit "I" for insert. Update the variable from 128mb to 256mb. (if the backup fails you may up this to 512mb)


Find max_input_vars. Update the value from 1000 to 3000 and remove the preceding semicolon to uncomment it.


Hit "esc" and then type ":wq" and hit "enter".


Now restart apache to complete the process.


sudo systemctl restart apache2

If the system fails to restart, run “journalctl -xe” for more details as to why.

If apache restarts but you are still receiving a composer error message when trying to login then it is likely apache is still using the old php. To resolve this you will need to move down the following steps:

  1. Determine the correct module name by using “cd /usr/lib/apache2/modules” then running “ls” to list them. Confirm libphp8.X.so exists and if so we just need to update the path called in the load configuration.

  2. If libphp8 does not exist then we need to determine that php 8 was installed. Run “php -v” and if it reports php 8 exists but no module was installed please contact support at support@simplerisk.com

  3. If you have made it this far and just need to update the file paths find your old php.conf and .load by using “cd /etc/apache2/mods-enabled/” You should have some php7.X load and conf. Simply rename the conf file from php7.x.conf to php8.x.conf where x is your version of php 8. 

  4. Now open the php7.x.load in a text editor as root  or use “sudo vi php7.x.load”. Now we need to update 2 parts of the loadmodule command. First find php7_module and remove the 7 making it php_module.

  5. Now closer to the end of the line find libphp7.x.so and update this to your current version of php so it is libphp8.x.so. 

  6. Finally hit esc and do :wq to write and close the file.

  7. Last you can rename the load and conf files to align with the version in use using “mv php7.x.conf php8.x.conf” the same can be done for the load file as well.

  8. To begin using PHP 8 now use “systemctl restart apache2”

Finishing Upgrade

If you were using this guide as a result of a failure during upgrade once you have completed these steps you may find that when you login you get a http 500 error and this is because the database still needs to be upgraded. You will need to go to mysimpleriskinstanceurl.com/admin/upgrade and login as an admin to run through the database upgrade and regain functionality.

Summary

At this point you have now updated to php 8 if you are still receiving composer errors or still have issues with SimpleRisk please feel free to contact us at support@simplerisk.com