Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if there are multiple versions of PHP installed on Ubuntu 12.04 LTS?

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?

like image 315
Sujata Avatar asked Feb 04 '15 09:02

Sujata


People also ask

How do you see what versions of PHP are installed?

1. Type the following command, replacing [location] with the path to your PHP installation. 2. Typing php -v now shows the PHP version installed on your Windows system.

How do I know if PHP is installed on Ubuntu?

Open a bash shell terminal and use the command “php –version” or “php -v” to get the version of PHP installed on the system.

Can I have 2 versions of PHP installed?

Together, you can use Apache and PHP-FPM to host multiple PHP web-applications, each using a different version of PHP, all on the same server, and all at the same time.


2 Answers

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 
like image 147
Jignesh Joisar Avatar answered Sep 19 '22 07:09

Jignesh Joisar


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 
like image 38
halfer Avatar answered Sep 22 '22 07:09

halfer