I wanted to know which php version I am using so I wrote the standard script:


Which gives me

PHP version 5.6.10

The correct PHP version needed for my application. When I tried in terminal:

php -i


php -v

It shows me:

PHP version 5.3.2

Which I don’t need. Then I tried with:

which php

It shows me:


Now I am confused which version of PHP I am using. The files are uploaded to the hosting website and I cannot make any changes to the config files like httpd.conf or php.ini.

7 Answers 7


Shorter answer.

Don’t panic! If you are concerned about what PHP version your Apache server is using, the output of phpinfo() is always what you should pay attention to. The Apache PHP module and the PHP command line binary are two different things that don’t interfere with each other.

In fact you can compile and load various PHP versions you want to work with Apache as long as you adjust Apache to properly load it. The PHP command line interface will never come into play in the case of Apache parsing PHP pages.

The command line version of PHP is simply there for command line specific tasks and the PHP module for Apache will never touch, use or need that.

Longer answer.

You say this:

I wanted to know which php version I am using so I wrote the standard script:


Which gives me PHP version 5.6.10- the correct PHP version needed for my application. When I tried in terminal:

php -i or php -v   

It shows me PHP version 5.3.2 which I don’t need.

The version of PHP available from the command line has 100% nothing to do with the version of PHP loaded as a module. These are completely separate things.

So if you are concerned about which version of PHP your web application is using, if phpinfo() shows version 5.6.10 and that is what you want/need that is 100% fine.

The command line version of PHP is a completely separate system item. So the only thing that matters is the output of phpinfo().

If for some reason you wanted to use a different version of PHP with Apache, all you need to do is install the compiled Apache PHP module somewhere and add—or adjust—this line in your system’s Apache config:

LoadModule php5_module    /path/to/php/and/the/module/for/apache2/libphp5.so

And just adjust the path to the libphp5.so—which is what Apache uses to parse PHP—then restart Apache and you are in business.

For example, at one point I had to compile PHP version 5.1.6 from source (with GD library support) for use on an Ubuntu 12.04 machine running PHP 5.3.5. In the server’s PHP module loading file here:


I had lines like this:

# LoadModule php5_module        /usr/lib/apache2/modules/libphp535.so
LoadModule php5_module        /usr/lib/apache2/modules/libphp516-gd.so

Note how one line is commented out for libphp535.so and the other one for libphp516-gd.so is uncommented? What I did is I renamed the default PHP 5.3.5 libphp5.so Apache module to libphp535.so with the version number in the name so I could have it there for reference and then named the PHP 5.1.6 (with GD library support) module libphp516-gd.so so I know what that is as well. This way I have them both available to me side-by-side on the system.

And—like I said at the outset—the PHP version used in the command line has utterly nothing to do with the Apache PHP module. So you can have any number of different versions of Apache PHP modules sitting on the system ready to go; just adjust a config and restart Apache and you should be all in business to use whatever PHP version you specified Apache should use.


If you have this problem while upgrading from PHP5 to PHP7 on Ubuntu 14.04 with Apache, here's what helped me (credit goes here):

Disable PHP5 module on Apache:

sudo a2dismod php5

Now enable PHP7:

sudo a2enmod php7.1

To reflect changes Apache restart is required:

sudo systemctl restart apache2
  • this may crash the project if php.ini are different
    – KawaiKx
    May 11, 2017 at 6:44
  • also ensure the php libraries for the new version are installed, i mean gd, mcrypt, xml etc.
    – korwalskiy
    Jan 23, 2020 at 14:46

If you are trying to run PHP code from your web server, then the version you are using is the one reported by phpinfo() = 5.6.10.

Your server apparently has multiple versions of PHP installed, and when you login and run php on the command line, you are getting the older version which is installed to /usr/bin/php.

A server can have many versions of PHP, and yours seems to.

If you need to manually execute the same PHP as your web server then you need to find the other version. Try running these commands:

/usr/local/bin/php -v
/opt/local/bin/php -v
/opt/bin/php -v

One of those might reveal a PHP with the same version as your web server, and when you figure out which one it is, you can use that one instead of the default.


Just an update, I was able to solve this issue by disable all other php apache modules via a2dismod php7.*

I hope this helps someone!


If I may add my 2 cents...

I was upgrading my Nextcloud version. When I run the upgrade procedure, I have to "sudo php" as the apache user, but it refused to run because the php CLI version run by default by the apache user was too old. However, phpinfo(); on my server displayed the latest php version installed.

I realized that it's because the PATH variable in the /home/apache/.bashrc file was set to the first version of php I had installed on my server, and it was never updated again (I always compile / install php from source on Github)

The solution:

When you update php on your web server and want to make sure the CLI php version used is the most current when you sudo as the apache user, don't forget to change it in the .bashrc file of this user, like this:

PATH=$PATH:/var/www/html: /usr/local/php7.1.32/bin export PATH

  • This was the solution for me. It was just a wrongly set $PATH variable in my .bash_profile file for my Mac user. Since I updated MAMP and it contained different versions of PHP than the older version of MAMP I used, the version set in my $PATH variable didn't exist anymore, so when trying to run "php -v" from command line it called the "php" instance in /usr/bin instead of the one in my MAMP app directory, which is the one I intended to use. Setting the right directory for the $PATH variable made the PHP called from my terminal the same as the one used by the server, as stated by phpinfo()
    – OMA
    Oct 26, 2021 at 20:48

Steps to fix this. First of all which PHP version its showing you.

php -v

Now you will need a PHP path, If you don't know then you can contact your hosting support for PHP path. In my case it was


Now, It's time to run this command in terminal.

alias php='/opt/php71/bin/php'

This will change your PHP version to PHP 7.1 If you want to change it to 7.2 you can try

alias php='/opt/php72/bin/php'

You are done. Verify it with

php -v

Create an environment variable path for php latest version ex:C:\wamp64\bin\php\php7.2.4 Now change your previous php version folder .php5.6.35 to some another number php5.6.354.. Then check php -v your wamp server and cli php will same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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