29

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.

8

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.

5
  • 3
    It's worth mentioning you should bounce Apache after changing the config so it is picked up. – Ben Pilbrow Jun 7 '10 at 22:49
  • 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. – nicorellius Jun 7 '10 at 23:44
  • interesting. What OS flavor are you running on? Was it configured via YUM, APT-Get, or YAST, (or some other package manager)? – grufftech Jun 8 '10 at 18:11
  • 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... – nicorellius Jun 8 '10 at 22:38
  • 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 Oct 23 '20 at 13:51
55

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
2
  • 3
    This doesn't work if your Apache installation is not using the system php. – mike rodent Jan 31 '20 at 16:24
  • You can make your php installation system with module enable or scl if you use remi RPMs – junior ruby developer Oct 23 '20 at 13:52
0

I had the same problem where phpinfo() would show version 7.0 even though I had upgraded to version 7.3. And it turns out I just had to restart apache.

I used sudo systemctl restart httpd on centos7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.