php - 多 PHP 如何在 Ubuntu 14.04 上安装带有 PEAR 和扩展的 php 5.3

标签 php mysql ubuntu pdo ubuntu-14.04

我刚刚安装了一个带有 php 5.5 的新服务器。但是我的一个旧项目需要 php 5.3。

所以我安装了 php 5.3

wget http://www.php.net/get/php-5.3.28.tar.bz2/from/a/mirror
tar -xvjf mirror
cd php-5.3.28
./configure --prefix /usr/local/php.5.3.28
make
make install

但是缺少 php_mysql 和 php_pdo_mysql 扩展。所以我想知道如何将它们安装到运行有多个 php 版本的服务器上的自定义 php 构建中?

服务器运行在 ubuntu 14.04

最佳答案

最近我不得不迁移带有非常旧的 php 代码的服务器,需要 PHP 5.3 版才能运行它。由于我的虚拟机提供商使用最新和最好的,并且有不允许旧的 linux 发行版的政策,我不得不使用 Ubuntu 14.04。问题是,正如您所说,它随 php 5.5 一起提供,所以我必须想出一种方法来启动和运行 php 5.3。在互联网上搜索了一段时间后,我发现了多种解决方案,我首先尝试的是您从源代码安装的解决方案。那确实安装了 php 5.3 但后来我遇到了你似乎遇到的相同问题所以我尝试了另一个推荐的解决方案并使用 CGI 来支持 php 5.3。我以为我已经找到了这个难题的最终解决方案,但过了一会儿我意识到它非常不稳定并且存在问题。所以我想到了如何解决这个问题,这就是我想出的办法。在我揭示我如何在我的 Ubuntu 14.04 上正确安装 php 5.3 之前,我想说这可能不是最优雅的方法,但我花了很多时间在一个应该是简单的任务上,回想起来它是一个公平的解决方案.不管怎样,这里是:

    $ cd /etc/apt/
    $ sudo cp sources.list sources.list.14_04

使用您喜欢的编辑器编辑 sources.list 并删除文件内容,然后将以下内容粘贴到您的文件中(这是 Ubuntu 12.04 的 sources.list)

    # deb cdrom:[Ubuntu-Server 12.04.1 LTS _Precise Pangolin_ - Release     amd64 (20120817.3)]/ dists/precise/main/binary-i386/
    # deb cdrom:[Ubuntu-Server 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120817.3)]/ dists/precise/restricted/binary-i386/
    # deb cdrom:[Ubuntu-Server 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120817.3)]/ precise main restricted

    #deb cdrom:[Ubuntu-Server 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120817.3)]/ dists/precise/main/binary-i386/
    #deb cdrom:[Ubuntu-Server 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120817.3)]/ dists/precise/restricted/binary-i386/
    #deb cdrom:[Ubuntu-Server 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120817.3)]/ precise main restricted

    # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
    # newer versions of the distribution.
    deb http://us.archive.ubuntu.com/ubuntu/ precise main restricted
    deb-src http://us.archive.ubuntu.com/ubuntu/ precise main restricted

    ## Major bug fix updates produced after the final release of the
    ## distribution.
    deb http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted
    deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted

    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    ## team. Also, please note that software in universe WILL NOT receive any
    ## review or updates from the Ubuntu security team.
    deb http://us.archive.ubuntu.com/ubuntu/ precise universe
    deb-src http://us.archive.ubuntu.com/ubuntu/ precise universe
    deb http://us.archive.ubuntu.com/ubuntu/ precise-updates universe
    deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates universe

    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    ## team, and may not be under a free licence. Please satisfy yourself as to
    ## your rights to use the software. Also, please note that software in
    ## multiverse WILL NOT receive any review or updates from the Ubuntu
    ## security team.
    deb http://us.archive.ubuntu.com/ubuntu/ precise multiverse
    deb-src http://us.archive.ubuntu.com/ubuntu/ precise multiverse
    deb http://us.archive.ubuntu.com/ubuntu/ precise-updates multiverse
    deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates multiverse

    ## N.B. software from this repository may not have been tested as
    ## extensively as that contained in the main release, although it includes
    ## newer versions of some applications which may provide useful features.
    ## Also, please note that software in backports WILL NOT receive any review
    ## or updates from the Ubuntu security team.
    deb http://us.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse
    deb-src http://us.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse

    deb http://security.ubuntu.com/ubuntu precise-security main restricted
    deb-src http://security.ubuntu.com/ubuntu precise-security main restricted
    deb http://security.ubuntu.com/ubuntu precise-security universe
    deb-src http://security.ubuntu.com/ubuntu precise-security universe
    deb http://security.ubuntu.com/ubuntu precise-security multiverse
    deb-src http://security.ubuntu.com/ubuntu precise-security multiverse

    ## Uncomment the following two lines to add software from Canonical's
    ## 'partner' repository.
    ## This software is not part of Ubuntu, but is offered by Canonical and the
    ## respective vendors as a service to Ubuntu users.
    # deb http://archive.canonical.com/ubuntu precise partner
    # deb-src http://archive.canonical.com/ubuntu precise partner

    ## Uncomment the following two lines to add software from Ubuntu's
    ## 'extras' repository.
    ## This software is not part of Ubuntu, but is offered by third-party
    ## developers who want to ship their latest software.
    # deb http://extras.ubuntu.com/ubuntu precise main
    # deb-src http://extras.ubuntu.com/ubuntu precise main

现在保存并退出。

    $ sudo apt-get clean
    $ sudo apt-get check
    $ sudo apt-get update
    $ sudo apt-get install php5 php-mysql

    Install whatever package you want to work with php version 5.3

    $ php -version
    PHP 5.3.10-1ubuntu3.19 with Suhosin-Patch (cli) (built: Jul  2 2015 15:05:04)
    Copyright (c) 1997-2012 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

如果您需要安装 mysql-server,您必须将 sources.list 切换回 sources.list.14_04 文件

    $ sudo mv sources.list sources.list.12_04
    $ sudo mv sources.list.14_04 sources.list
    $ sudo apt-get clean
    $ sudo apt-get check
    $ sudo apt-get update

除此之外,您应该有一个 Ubuntu 14.04 以及运行良好的 php 版本 5.3 和 php_mysql 扩展。希望这有帮助!

关于php - 多 PHP 如何在 Ubuntu 14.04 上安装带有 PEAR 和扩展的 php 5.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24861866/

相关文章:

php curl ssl 错误号 35

php - 将行和/或列合并到 GROUP BY 中的一个字段中

php - 基于条件的sql查询结果

php - 在 PHP 中缓存辩论/论坛条目

ubuntu - 如何使用命令行为 ubuntu 安装 ffmpeg?

docker - Google 不会从页面上的 api 索引数据

php - 在 MAC OSX 上的 XAMPP 中更新 PHP

php - AJAX 请求后返回不需要的新行

php - MySQL 更新 "link"表

phpmyadmin 2002 错误