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
.
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.
Depending on your server, you should be looking at Apache, not PHP.
(For RHEL/CentOS) look at
/etc/httpd/conf.d/php.ini
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.
will show you what version of PHP is currently installed.
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 centos7There are two main methods to install a new PHP version and tell Apache to use it:
mod_php
andphp-fpm
.Note: The preffered method is
php-fpm
, and many new distributions (including Fedora) are using it by default.Install PHP as Apache SAPI module
Here is the guide around this for Unix systems, from the official documentation. It has some missing points (at least for my setup), so I walk through the steps:
Build PHP from source. In the
./configure
step, use--with-apxs2
. This will build shared Apache 2 handler module for you.Make sure you have
apxs
command defined in your path, or specify its path as the option's value (i.e.--with-apxs2=/path/to/apxs
).For instance, if you installed Apache system-wide and want to install this command as well (e.g. on a local environment), on Fedora and its derivatives, you can install it by:
After building is done (i.e. after
make
ormake test
), runmake install
(as root, perhaps). Obviously, this will install PHP to the path you specified (i.e. with--prefix
).What is done just before PHP being installed is, because of the
--with-apxs2
option, installing PHP apache2handler SAPI module. It prepares the shared object (e.g. in/usr/lib64/httpd/modules/libphp.so
), and activates the module (e.g. in/etc/httpd/conf/httpd.conf
), by adding one of the following lines to the Apache configuration file, depending on the PHP version you installed (the line is inserted below the section "Dynamic Shared Object (DSO) Support"):Note: While switching on the PHP versions, specially major ones, keep in mind to check there is only one of these
LoadModule
s for PHP available, otherwise the Apache server refuses to start.Install PHP as PHP-FPM (FastCGI Process Manager)
TBD. :)
Final steps
PHP 8.0 and above extra step
In the case your distribution does not support PHP8 yet (e.g. Fedora 34) and you installed Apache2 from the package manager, you should take one more step.
The problem is, from PHP 8.0 onwards, Apache2 uses different identifiers for SAPI modules than before. These identifier are used in order to detect whether you are using
mod_php
orphp-fpm
, in the configuration files. For PHP5, it wasphp5_module
andmod_php5
; for PHP7, it isphp7_module
andmod_php7
, and for PHP8, it isphp_module
andmod_php
.In this case, navigate to Apache2 configurations directory (e.g.
/etc/httpd
), and start editing the fileconf.d/php.conf
. There are twoIfModule
sections there: One for enablingphp-fpm
if you don't usemod_php
, and the other for enablingmod_php
if you are using it (i.e. usingLoadModule
somewhere in the configurations). You should update these conditions to cover PHP8 as well.For instance, consider the following:
You should surround the core configuration with one more
IfModule
section like this:And do the same for the
mod_php
enabler configuration section as well.Last step
Restart the Apache service:
Now,
phpinfo()
should show you the new PHP version you just installed. You should be happy now. :)