Changing PHP Version that Apache is Using

Changing PHP Version that Apache is Using

DevOps

PHP

Published: March 6, 2024

Author: Andrew Arscott

Apache uses modules, including the PHP module. You might encounter a time when you need to change the version your apache web server is using. Most notably during an upgrade. This guide assumes you have the relevant PHP packages installed.

You can disable a module by running the following command:

sudo a2dismod phpx.x

replace the x.x with the relevant version you are trying to disable. Then you can enable the new module by running

sudo a2enmod phpx.x

again replacing the x.x with the relevant version.

As an example, if you wanted to disable php 8.1 and enable 8.3 you would run:

sudo a2dismod php8.1
sudo a2enmod php8.3

Finally, you will need to restart your apache server:

sudo service apache2 restart

You can confirm this has worked by creating or editing your index.php file and adding the following:

<?php
	
	phpinfo();

This will output a file such as the following:

This PHP info file can be very useful for debugging your PHP server as it lists all of the current configuration options you have enabled.