How To Change What Version of PHP Apache2 Uses?
Solution 1
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/libphp5.so
#
# 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/libphp5.so
.
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.
Solution 2
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
Related videos on Youtube
![nicorellius](https://i.stack.imgur.com/zDprA.png?s=256&g=1)
Comments
-
nicorellius almost 2 years
Ubuntu 10.04, MySQL 5.1, Apache 2.2, and PHP 5.2/5.3:
I just discovered that I am using the wrong version of PHP for a CRM application. Once I figured out how to make a simple
phpinfo()
script to tell me what Apache2 is using, I tried changing thephp.ini
such that my webserver would use the PHP I want. Well, this is my problem. Not sure how to do that.I compiled the version of PHP I want to
/etc
here:/etc/php-5.2.8/
Inside this, there was a
php.ini-recommended
file that I made some changes to and renamed tophp.ini
so PHP would use it. But when I opened my browser and cleared my history and went to thehttp://localhost<CRM dir>/install.php
address, the wizard still says I'm not usign the correct version of PHP.Based on this post what do I have to do to change the version of PHP that shows up after I run my
test.php
script? In other words,phpinfo()
says I'm running PHP 5.3.2, but I want to change it to my compiled 5.2.8 version located in/etc
. -
Ben Pilbrow about 14 yearsIt's worth mentioning you should bounce Apache after changing the config so it is picked up.
-
nicorellius about 14 yearsI really wish it was this easy. The only
php.ini
file I have in the server directory is/etc/apache2/php.ini
but not where you suggest. This file doesn't have these components you speak of: LoadModule, AddHandler, AddType, etc. -
dannymilsom about 14 yearsinteresting. What OS flavor are you running on? Was it configured via YUM, APT-Get, or YAST, (or some other package manager)?
-
nicorellius about 14 yearsUbuntu 10.04. The new version of PHP (5.3.2) can easily be installed unsing
apt-get
, which I have done. But hte PHP 5.2.8 and 5.2.13 I compiled, using files from php.net/releases. I actually kind of gave up trying to get older version of PHP to run. I think alternate approaches are in order for the sake of brevity. Thanks for your help, nonetheless... -
mike rodent over 4 yearsThis doesn't work if your Apache installation is not using the system php.
-
junior ruby developer over 3 yearsphp.ini could be extended via includes: /etc/httpd/conf.modules.d/15-php.conf: LoadModule php7_module modules/libphp7.so LoadModule php7_module modules/libphp7-zts.so
-
junior ruby developer over 3 yearsYou can make your php installation system with module enable or scl if you use remi RPMs
-
Admin about 2 yearsalso had to run
sudo a2dismod php7.2
to upgrade to php7.4 from php7.2