58

How to know if I have both php5.3 and php5.5 installed in my system? How to delete php5.3 if it is there and configuring Apache2 to work with php5.5?

Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
Sujata
  • 951
  • 2
  • 10
  • 19

8 Answers8

83

I use the following command to view installed PHP versions in Ubuntu:

sudo update-alternatives --list php

Second way go to php directory where all PHP version configuration file stored:

cd /etc/php 
dir 

Output:

 > 5.6  7.0  7.1
halfer
  • 19,824
  • 17
  • 99
  • 186
Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
36

Since you have a Linux environment, you can run this on your console:

locate bin/php

And then for anything that looks like a PHP binary, get the version. The output for me for the above is:

/home/xx/Development/Personal/Project1/webapp/bin/phpunit
/home/xx/Development/Personal/Project1/webapp-backup/vendor/bin/phpunit
/home/xx/Development/Personal/Project2/app/vendor/bin/phpunit
/home/xx/php-threaded/bin/php
/home/xx/php-threaded/bin/php-cgi
/home/xx/php-threaded/bin/php-config
/home/xx/php-threaded/bin/phpize
/usr/bin/php
/usr/bin/php5
/usr/local/bin/php-cgi
/usr/local/bin/php-config
/usr/local/bin/php53
/usr/local/bin/phpize
/usr/sbin/php5dismod
/usr/sbin/php5enmod
/usr/sbin/php5query

Out of those, there are a few that look like PHP binaries. So let's get the version for each:

/home/xx/php-threaded/bin/php -v
/usr/bin/php -v
/usr/bin/php5 -v
/usr/local/bin/php53 -v

That will give you the versions of PHP you have installed.

I wouldn't bother deleting an old version, it might remove files that will stop things working. You can just configure the console version, or the Apache version, to use the version you want.


In answer to your supplementary question: it seems that you've followed the instructions here to add an unofficial repo to your version of Ubuntu, since the standard repo does not support 5.5.

We discovered together that the way to get it working was first to upgrade Apache from 2.2 to 2.4:

sudo apt-get upgrade apache2

It should be noted that this can cause some vhost repair to be required, as some Apache directives changed in this version. Once you have done that, you can get the new version of mod_php:

sudo apt-get install libapache2-mod-php5
halfer
  • 19,824
  • 17
  • 99
  • 186
36

To check your installed versions type:

cd /etc/php

in your terminal to go to the configuration folder of your PHP installations and then you type:

ls

The output will be the folders that corresponds to the versions installed in your machine. In my case the command outputs:

5.6 7.0 7.1
WeidMaster
  • 547
  • 6
  • 8
  • 2
    Simple and effective :-) – DilbertDave Oct 01 '18 at 07:15
  • 5
    Not always true, even if you have many versions in /etc/php/, it doesn't mean you have many php versions installed. If you see only "mods-available" in php version folder, for example /etc/php/5.6/mods-available, then php5.6 isn't installed. You should have at least "cli" or "fpm" if that version is installed. Try *update-alternatives --display php* to list available php versions. – Takman Sep 20 '19 at 21:33
  • 1
    or you can directly use `ls /etc/php` – Abdullah Oct 14 '22 at 06:39
31

I am always using this command to see list of PHP versions and also for switching one version to another install PHP version.

sudo update-alternatives --config php
Atul Baldaniya
  • 761
  • 8
  • 14
5

You can run this on your console:

find / -name php | grep bin
halfer
  • 19,824
  • 17
  • 99
  • 186
Karthikeyan U
  • 51
  • 1
  • 1
4

I use the following to view installed php versions in Ubuntu:

sudo dpkg --list | grep ' php[0-9]\.[0-9] '

1

Get a list of all installed packages and filter installed PHP versions:

sudo apt list --installed 2>/dev/null | cut -d / -f 1 | grep ^php[0-9].[0-9]$;

or

sudo apt list --installed 2>/dev/null | cut -d / -f 1 | grep ^php[0-9].[0-9]$ | xargs;

if you really need to get only installed PHP versions without unnecessary.

Or

sudo update-alternatives --list php;

Victor S.
  • 2,510
  • 3
  • 22
  • 35
1

I have nextcloud in cyberpanel, This worked for me, cd to public_html:

sudo -u webuser /usr/local/lsws/lsphp81/bin/php occ files:scan -v --all

found above PHP location by:

locate bin/php

for locate to work:

apt install plocate
Dpk Bh
  • 11
  • 2