简体   繁体   English

如何检查 Ubuntu 12.04 LTS 上是否安装了多个版本的 PHP?

[英]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?如何知道我的系统中是否同时安装了 php5.3 和 php5.5? How to delete php5.3 if it is there and configuring Apache2 to work with php5.5?如何删除 php5.3(如果存在)并配置 Apache2 以与 php5.5 一起使用?

I use the following command to view installed PHP versions in Ubuntu:我使用以下命令在 Ubuntu 中查看已安装的 PHP 版本:

sudo update-alternatives --list php

Second way go to php directory where all PHP version configuration file stored:第二种方式转到存储所有 PHP 版本配置文件的php目录:

cd /etc/php 
dir 

Output:输出:

 > 5.6  7.0  7.1

Since you have a Linux environment, you can run this on your console:由于您拥有 Linux 环境,因此您可以在控制台上运行它:

locate bin/php

And then for anything that looks like a PHP binary, get the version.然后对于任何看起来像 PHP 二进制文件的内容,获取版本。 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.其中,有一些看起来像 PHP 二进制文件。 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.这将为您提供已安装的 PHP 版本。

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.您可以只配置控制台版本或 Apache 版本,以使用您想要的版本。


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.回答您的补充问题:您似乎已按照此处的说明将非官方存储库添加到您的 Ubuntu 版本,因为标准存储库不支持 5.5。

We discovered together that the way to get it working was first to upgrade Apache from 2.2 to 2.4:我们一起发现,让它工作的方法是首先将 Apache 从 2.2 升级到 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.应该注意的是,这可能会导致需要进行一些 vhost 修复,因为在此版本中更改了一些 Apache 指令。 Once you have done that, you can get the new version of mod_php :完成后,您可以获得新版本的mod_php

sudo apt-get install libapache2-mod-php5

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:在终端中转到 PHP 安装的配置文件夹,然后键入:

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

我总是使用这个命令来查看 PHP 版本列表,以及将一个版本切换到另一个安装 PHP 版本。

sudo update-alternatives --config php

我使用以下命令查看 Ubuntu 中已安装的 php 版本:

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

您可以在控制台上运行它:

find / -name php | grep bin

Get a list of all installed packages and filter installed PHP versions:获取所有已安装软件包的列表并过滤已安装的 PHP 版本:

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.如果您真的只需要安装没有不必要的 PHP 版本。

Or或者

sudo update-alternatives --list php;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM