2014-07-21 50 views
2

我刚刚安装了一个新的服务器,它带有php 5.5。然而我的一个老项目需要php 5.3。Multi-PHP如何在Ubuntu上安装php 5.3与PEAR和扩展14.04

所以我安装了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

回答

0

最近,我不得不与需要PHP 5.3版来运行它很老的PHP代码迁移服务器上运行。由于我的虚拟机提供商使用最新,最好的策略,并且不允许旧版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的服务器你有你的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扩展运行良好。希望这可以帮助 !

+0

我有同样的问题,我需要降级到PHP 5.3,我会试一试。 –