apache centos上的多个php [英] multiple php on apache centos

查看:86
本文介绍了apache centos上的多个php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得同时在Centos 6.5上运行的多个php版本?

How can I get multiple php versions running on Centos 6.5 at the same time ?

这是方法.

要求
Centos 6.5(可能与6.6和7兼容)
Apache Apache/2.2.15(可能与其他版本一起使用)

Requirements
Centos 6.5 (Possible works with 6.6 and 7)
Apache Apache/2.2.15 (Possible works with other versions)

该指南的安装和使用
FASTCGI(请参阅注释以了解替代安装)
PHPFARM

此安装是通过这种方式完成的,因此可以与iredmail兼容.
您可以使用此设置在服务器上安装iredmail.

This guide installs and uses
FASTCGI (see the comments for alternative installation)
PHPFARM

This install was done this way so it would be compatable with iredmail.
You can install iredmail on a server with this set up.

第1步
安装PHPFarm

Step 1
Installing PHPFarm

yum install gcc libxml2-devel openssl-devel bzip2-devel curl-devel libjpeg-devel     freetype-devel icu libicu-devel gcc-c++ postgresql-devel aspell-devel git -y

$ cd /opt/
$ git clone https://github.com/cweiske/phpfarm.git phpfarm
$ cd phpfarm/src/
$ cd /opt/phpfarm/src/

对于每个要运行的php版本.但是,如果您想要自定义模块(例如mysql支持),请跳过此步骤并查看其正下方的部分.

For each version of php you want run this. However, If you want custom modules such as mysql support skip this and see the part just below it.

$ ./compile.sh 5.3.1
$ ./compile.sh 5.3.3
$ ./compile.sh 5.5.11

如果遇到编译错误,请重新启动并再次尝试./compile.sh 5.3.1. 当我遇到这个问题时,这对我有用.

MYSQL&模块支持
为PHP 5.5.14版的自定义phpfarm安装获取MySQL支持(和其他模块)的步骤.这些说明适用于任何版本,只需将5.5.14重命名为5.4.3.您当然需要连接mysql服务器才能使用php中的mysql模块.
这些步骤需要按此顺序完成
步骤1A
确保您具有这些路径,并且日期时间正确,我以root用户的身份进行了此操作.您应该具有要使用的date.timezone.

If you get compile errors, reboot and try./compile.sh 5.3.1 again This worked for me when I ran into this problem

MYSQL & Module Support
Steps for getting MySQL support (and other modules) for custom phpfarm install of php version 5.5.14. These instructions work for any version just rename 5.5.14 to what ever like 5.4.3. You will of course need a mysql server to connect to to make use of the mysql module within php.
These steps need to be completed in this order
Step 1A
Ensure you have these paths and the date time is correct I did this as root. You should have the date.timezone you intend to use.

cd /opt/phpfarm/src
vi custom-php.ini

date.timezone=America/Halifax
include_path=".:/opt/phpfarm/inst/php-$version/pear/php/"

步骤1B
确保您具有这些路径,并且日期时间正确

Step 1B
Ensure you have these paths and the date time is correct

cd /opt/phpfarm/src
vi default-custom-php.ini

date.timezone=America/Halifax
include_path=".:/opt/phpfarm/inst/php-$version/pear/php/"

步骤1C
特别注意这一行

Step 1C
Pay Special Attention to this line

--with-config-file-path=/opt/phpfarm/inst/php-5.5.11/lib/ \

需要针对您使用的版本进行调整.作为根

it will need to be adjusted for the version you are working with. As root

vi custom-options-5.5.14.sh

#!/bin/bash

#gcov='--enable-gcov'
configoptions="
--disable-debug \
--with-config-file-path=/opt/phpfarm/inst/php-5.5.11/lib/ \
--enable-short-tags \
--with-pear \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-pcntl \
--enable-soap \
--enable-sockets \
--enable-wddx \
--enable-zip \
--with-zlib \
--with-gettext \
--enable-pdo \
--with-pdo-mysql \
--enable-cgi \
--enable-json \
--with-curl \
--with-openssl \
--enable-openssl \
--with-mysql \
--enable-mysql \
$gcov"

步骤1D
现在以root身份编译.编译5.5.14或任何具有相应版本号的其他版本时,Phpfarm会自动查找名为custom-options-5.5.14.sh的文件.

Step 1D
Now compile as root. Phpfarm will automatically look for a file named custom-options-5.5.14.sh when you compile 5.5.14, or any other version with of course respective version numbers.

./compile.sh 5.5.14

稍后,当您使用phpinfo()检出网页时;功能,您将在页面上看到对这些模块的支持以及不同的配置命令"文本.

Later when you check out your web page with the phpinfo(); function, you will see support for these modules and different "Configure Command" text on the page.

如果未完成这些步骤,则可能必须再次执行. 为了再次执行此操作,请首先从src文件夹和inst文件夹中删除文件.

If these steps are not completed in order you may have to do it again. In order to do this again first remove the files from the src folder and the inst folder.

rm -rf /opt/phpfarm/inst/php-5.5.14

rm -rf /opt/phpfarm/src/php-5.5.14

rm将删除该文件夹,-rf表示r递归和强制. 参考: http://linuxcommand.org/lc3_man_pages/rm1.html

The rm will remove the folder and the -rf stands for r recursive and f force. Ref: http://linuxcommand.org/lc3_man_pages/rm1.html

如果您有任何错误,请与本网站联系.还有其他的,但是我发现这很有用.

If you have errors check with this site. There are others but I found this one useful.

http://crybit.com/20- common-php-compilation-errors-and-fix-unix/

有关mysql和模块支持的参考

Reference for the mysql and module support

使用PHP场激活php扩展

第2步
将phpfarm添加到您的个人资料

Step 2
Adding phpfarm to your profiles

将此命令添加到root和非root用户的.bashrc底部. .bashrc文件可以在用户根文件夹中找到,或者在cd〜/之后找到ls -all,您应该会看到它.

add this to the bottom of .bashrc for root and non-root user. The .bashrc file can be found in the users root folder or cd ~/ then ls -all and you should see it.

PATH="$PATH:/opt/phpfarm/inst/bin:/opt/phpfarm/inst/current-bin"

在将它添加到root和非root用户的.bashrc文件中之后,还要在终端中执行此操作

also execute this in terminal after you have added it to the .bashrc files for root and non-root user

export PATH="$PATH:/opt/phpfarm/inst/bin:/opt/phpfarm/inst/current-bin"

现在退出终端并重新登录.尝试此命令

now exit the terminal and log back in. try this command

switch-phpfarm 5.5.11

您应该能够在diff php版本之间来回切换

you should be able to switch back and forth between diff php versions

[root@test joe]# switch-phpfarm 5.5.11
Setting active PHP version to 5.5.11
PHP 5.5.11 (cli) (built: May 17 2014 22:01:31) (DEBUG)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
[root@test joe]#

添加CentOS/RHEL 6、64位(x86_64)的存储库:

add the repo for CentOS/RHEL 6, 64 Bit (x86_64):

cd /tmp
rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

第3步
安装百胜面包

Step 3
install the yums

yum install php php-cli mod_fastcgi

注意 在这一点上,如果您尝试运行switch-phpfarm 5.5.11,它将无法正常工作,但是没关系.我们仍然可以使用不同版本的php来运行多个网站

NOTE at this point if you try to run the switch-phpfarm 5.5.11 it wont work properly but thats ok. we will still be able to run multiple websites with different versions of php

第4步
确保已创建cgi-bin并配置了文件

Step 4
Ensure your cgi-bin is created and files are configured

$ cd  /var/www

如果cgi-bin尚不在这里,请创建它

If the cgi-bin isn’t already here create it

$ mkdir cgi-bin

对于打算使用的每个PHP版本,请使以下文件之一.用版本号替换结尾

For each version of php you intend to use make one of these files. Replace the ending with the version number

vi /var/www/cgi-bin/php.fastcgi.5.5.11

第5步
在文件php.fastcgi.5.5.11

step 5
Inside the file php.fastcgi.5.5.11

#!/bin/bash
PHPRC="/opt/phpfarm/src/php-5.5.11/php.ini-development"
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
export PHPRC
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec /opt/phpfarm/inst/bin/php-cgi-5.5.11

第一行

PHPRC="/opt/phpfarm/src/php-5.5.11/php.ini-development"

告诉您女巫php.ini,它在ubuntu中是不同的.最后一行

Tells you witch php.ini to use this is different in ubuntu. The last line

exec /opt/phpfarm/inst/bin/php-cgi-5.5.11

对于每个特定版本,还需要更改

.我不确定它的作用,但是我知道它需要更改.

also needs to be changed for each particular version. I am not sure what it does but I do know it needs to be changed.

第6步
使fastcgi文件对于apache可执行:apache用户和组

Step 6
Enable fastcgi files to be executable for apache:apache user and group

示例1

[root@test joe]# chown apache:apache /var/www/cgi-bin/php.fastcgi.5.5.11
[root@test joe]# chmod +x /var/www/cgi-bin/php.fastcgi.5.5.11

示例2

[root@test joe]# chown apache:apache /var/www/cgi-bin/php.fastcgi.5.3.3
[root@test joe]# chmod +x /var/www/cgi-bin/php.fastcgi.5.3.3

示例3

[root@test joe]# chown apache:apache /var/www/cgi-bin/php.fastcgi.5.3.1
[root@test joe]# chmod +x /var/www/cgi-bin/php.fastcgi.5.3.1

第7步
编辑httpd.conf文件
这是/etc/httpd/conf/httpd.conf文件的需求. 首先找到"NameVirtualHost *:80"并将其用作起点.#"表示该行已被注释掉.通过删除#取消注释此行.它现在应该看起来像这样.

Step 7
Editing the httpd.conf file
Here’s what you need for the /etc/httpd/conf/httpd.conf file. First find "NameVirtualHost *:80" and use this as a starting point.The "#" means the line is commented out. Uncomment this line by deleting the #. it Should now look like this.

NameVirtualHost *:80

这将允许多个虚拟主机通过每个虚拟主机引用中的"ServerName"在Apache上运行.我在评论中留下了几行,向您展示了如果没有它,您将无能为力.确保/etc/httpd/conf/httpd.conf的底部看起来像这样.

This will allow multiple virtual host to operate on Apache by their "ServerName" in each virtual host reference. I left some lines commented to show you what you can do without. Make sure the bottom of the /etc/httpd/conf/httpd.conf looks like this.

<VirtualHost *:80>
    ServerName test1.com
   #ServerAdmin admin@tecadmin.net
    DocumentRoot /var/www/html/test1
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    <Directory "/var/www/html/test1">
            Options +Indexes FollowSymLinks +ExecCGI
            AddHandler php5-fastcgi .php
            Action php5-fastcgi /cgi-bin/php.fastcgi.5.5.11
            AllowOverride All
            Order allow,deny
            Allow from All
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerName test2.com
#   ServerAdmin admin@tecadmin.net
    DocumentRoot /var/www/html/test2
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    <Directory "/var/www/html/test2">
            Options +Indexes FollowSymLinks +ExecCGI
            AddHandler php5-fastcgi .php
            Action php5-fastcgi /cgi-bin/php.fastcgi.5.3.3
            AllowOverride All
            Order allow,deny
            Allow from All
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerName test3.org
#   ServerAdmin admin@tecadmin.net
    DocumentRoot /var/www/html/test3
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    <Directory "/var/www/html/test3">
            Options +Indexes FollowSymLinks +ExecCGI
            AddHandler php5-fastcgi .php
            Action php5-fastcgi /cgi-bin/php.fastcgi.5.3.1
            AllowOverride All
            Order allow,deny
            Allow from All
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerName test4.net
#   ServerAdmin admin@tecadmin.net
    DocumentRoot /var/www/html/test6
</VirtualHost>

第8步
编辑etc/hosts文件
这是您在etc/hosts文件中需要的.

Step 8
Editing the etc/hosts file
here is what u need in the etc/hosts file.

127.0.0.1   localhost test1.com test2.com test3.org test4.net
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

第9步

现在重新启动服务器

service httpd restart

第10步
测试
如果您将phpinfo()添加到每个index.php网站,您将注意到所有php版本将有所不同.最后一个test4.net也将使用默认的centos.另请注意,test3.org和test4.net并非.com,但仍可以使用.将来,我计划为phpfarm文件制作一个指南,以便您可以在mysql支持下进行安装.这是我遇到的另一个问题.如果您发现其中的一些错误或难以执行,请发表评论,我会尽快处理.

Step 10
Testing
if you add phpinfo() to each of the index.php sites you will notice that all the php versions will be different. also the last one test4.net will go with the default for centos. Also note that test3.org and test4.net are not .com's but will still work. In the future I plan to make a guide for the phpfarm files so you can install with mysql support. This was another issue I ran into. If you notice some errors in this or have difficult making it work, please comment and I will get to it as soon as I can.

推荐答案

我收到的一些通知:

  1. yum install php php-cli mod_fastcgi不正确.不应启用mod_php.也可以使用mod_fcgid
  2. 在没有外部存储库的情况下安装mod_fastcgi
  3. 对于PHP 5.2和libxml> = 1.2.9,您必须应用此补丁
  1. yum install php php-cli mod_fastcgi is not correct. mod_php should not be enabled. also mod_fastcgi can be installed without external repository using mod_fcgid
  2. For PHP 5.2 and libxml>=1.2.9 you have to apply this patch libxml29_compat.patch
  3. to set php version for all host without mod_php enabled add this to httpd.conf

<Directory "/var/www">
    Options All +ExecCGI
    AddHandler php-cgi .php
    Action php-cgi /cgi-bin/php.fastcgi.5.5.18
</Directory>

  • 在64位系统上编译时,由于lib64文件夹而导致编译失败,因此应在配置选项中添加--with-libdir=lib64
  • when compiling on 64bit systems the compilation fails because of lib64 folder so you should add --with-libdir=lib64 to configoptions
  • 这篇关于apache centos上的多个php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆