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
Videos
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\)'
Put this in your root directory:
<?php
phpinfo();
?>
Save it as phpinfo.php and point your browser to it (this could be http://localhost/phpinfo.php)
- More information (you can get much more information than just the version).
- Example (random image):

Try with command from terminal
sudo /opt/lampp/bin/php -v
On Debian (and thus Ubuntu), the Apache configuration files are stored under /etc/apache2. In that directory, there are 2 sub-directories for configuring modules: mods-available and mods-enabled. When you install an Apache module (ie: foo), it will put foo.load (and possibly foo.conf) into the /etc/apache2/mods-available directory. When you enable an Apache module using a2enmod, it will create a symbolic link in /etc/apache2/mods-enabled for each of the matching files from /etc/apache2/mods-available.
Thus for an Ubuntu server with PHP5 enabled, you should see something like this:
$ cd /etc/apache2
$ ls -l mods-*/*php*
-rw-r--r-- 1 root root 133 2008-02-27 15:49 mods-available/php5.conf
-rw-r--r-- 1 root root 59 2008-02-27 15:49 mods-available/php5.load
lrwxrwxrwx 1 root root 27 2009-02-05 07:30 mods-enabled/php5.conf -> ../mods-available/php5.conf
lrwxrwxrwx 1 root root 27 2009-02-05 07:30 mods-enabled/php5.load -> ../mods-available/php5.load
If the php5 configuration files aren't shown in the mods-enabled directory, enable them as follows:
$ sudo a2enmod php5
$ sudo /etc/init.d/apache2 restart
Once you've done that, in order to test that PHP5 is configured, create /var/www/test.php as follows:
$ echo "<?php phpinfo(); ?>" | sudo tee /var/www/test.php
$ sudo chown www-data:www-data /var/www/test.php
$ sudo chmod 755 /var/www/test.php
Once that's done, you should be able to browse to /test.php on that server and see the PHP configuration data.
Use the phpinfo() function. Create a .php file that Apache will serve up and include the following:
<?php
phpinfo();
?>
When you navigate to the .php file, and php is installed, it should give you a whole lot of information about the php version you have installed.
This command works while running in PHP
<?php
echo PHP_VERSION;
You can get it in bash, like
PHP_VERSION=$(php -r "echo PHP_VERSION;")
Here is all of PHP Predefined Constants
I got it to work with the following commands:
# Full version
php -v | head -n 1 | cut -d " " -f 2
# Major.Minor version
php -v | head -n 1 | cut -d " " -f 2 | cut -f1-2 -d"."