How To Change What Version of PHP Apache2 Uses?

161,211

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
Share:
161,211

Related videos on Youtube

nicorellius
Author by

nicorellius

python | django | app usability | ui/ux

Updated on September 17, 2022

Comments

  • nicorellius
    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 the php.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 to php.ini so PHP would use it. But when I opened my browser and cleared my history and went to the http://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
    Ben Pilbrow about 14 years
    It's worth mentioning you should bounce Apache after changing the config so it is picked up.
  • nicorellius
    nicorellius about 14 years
    I 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
    dannymilsom about 14 years
    interesting. What OS flavor are you running on? Was it configured via YUM, APT-Get, or YAST, (or some other package manager)?
  • nicorellius
    nicorellius about 14 years
    Ubuntu 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
    mike rodent over 4 years
    This doesn't work if your Apache installation is not using the system php.
  • junior ruby developer
    junior ruby developer over 3 years
    php.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
    junior ruby developer over 3 years
    You can make your php installation system with module enable or scl if you use remi RPMs
  • Admin
    Admin about 2 years
    also had to run sudo a2dismod php7.2 to upgrade to php7.4 from php7.2