Try running the following at the command line.
To just get the version information:
php -v
Or to get a lot of info:
php -i
It should give you all information you need about the php install.
Answer from Paxxi on Stack ExchangeI 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
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
Do it from your command line:
php -v
mysql -V
and:
php -i | grep -i '^libxml'
OR
Put this in your root directory:
<?php
phpinfo();
php?>
Save it as phpinfo.php and point your browser to it (this could be http://localhost/phpinfo.php)
Use dpkg to find the installed package versions.
dpkg -l | grep '\(php\|mysql\)'
This great technote tells me to use the php -v command.: https://www.linuxcnf.com/2018/05/how-to-check-php-version-in-centos-7.html Told command not found.
I do not have the info.php /var/www/html/ in this directory. I know I have php installed because mediawiki is already using it. I need to know the version before I start upgrading.
Extending Jeff Schaller's answer, skip the pipeline altogether and just ask for the internal constant representation:
$ php -r 'echo PHP_VERSION;'
7.1.15
You can extend this pattern to get more, or less, information:
$ php -r 'echo PHP_MAJOR_VERSION;'
7
See the PHP list of pre-defined constants for all available.
The major benefit: it doesn't rely on a defined output format of php -v. Given it's about the same performance as a pipeline solution, then it seems a more robust choice.
If your objective is to test for the version, then you can also use this pattern. For example, this code will exit 0 if PHP >= 7, and 1 otherwise:
php -r 'exit((int)version_compare(PHP_VERSION, "7.0.0", "<"));'
For reference, here are timings for various test cases, ordered fastest first:
$ time for (( i=0; i<1000; i++ )); do php -v | awk '/^PHP [0-9]/ { print $2; }' >/dev/null; done
real 0m13.368s
user 0m8.064s
sys 0m4.036s
$ time for (( i=0; i<1000; i++ )); do php -r 'echo PHP_VERSION;' >/dev/null; done
real 0m13.624s
user 0m8.408s
sys 0m3.836s
$ time for (( i=0; i<1000; i++ )); do php -v | head -1 | cut -f2 -d' ' >/dev/null; done
real 0m13.942s
user 0m8.180s
sys 0m4.160s
If you've installed php via the package manager (e.g. RPM or yum), then you can query the version from there:
rpm -q --queryformat="%{VERSION}" php
Alternatively, you can ask php to tell you its version directly:
php -r 'echo phpversion();'