How To Change What Version of PHP Apache2 Uses?

Solution 1:

If you already install other version of php, you only need to change php* module used by apache.

for example, I have php5 and php7.0. when I want apache use php7.0, I only need to enable his module and disalbe php5 module.

sudo a2dismod php5
sudo a2enmod php7.0

Solution 2:

Depending on your server, you should be looking at Apache, not PHP.

(For RHEL/CentOS) look at /etc/httpd/conf.d/php.ini

# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated web pages.
LoadModule php5_module modules/
# Causes the PHP interpreter to handle files with a .php extension.
AddHandler php5-script .php
AddType text/html .php

You'll see that your PHP module is modules/

AddHandler php5-script .php tells Apache to run PHP on any file with the extension .php.

If you are using an RPM based OS it's probably easier to uninstall (assuming you can do that) the current version of PHP, and reinstall the version you are looking for.

rpm -qa | grep php

will show you what version of PHP is currently installed.