如何在一台服务器上运行多个版本的PHP
>在这篇特定的文章中,我们将演示一个解决方案,以安装Phalcon和PHP的多个版本,并在单个Web服务器上运行它们。 PHP 5.5.x和5.6.x将在此处使用,但是您可以用其他版本替换它们。任何支持PHP-FPM的服务器都足够,但我们建议使用NGINX。本教程中使用的环境是Fedora OS - 一个Linux系统,但对于任何其他 *NIX OS。
钥匙要点- >利用nginx和php-fpm在单个服务器上运行多个版本的PHP,如PHP 5.5.5.x和Fedora OS上的5.6.x所示。
- 确保安装了所有必要的开发工具和库,例如GCC,Make和libtool,以成功地从源构建PHP。 >克隆来自GitHub的PHP源代码访问多个PHP版本,并使用`。/configure`脚本与特定选项(例如'–Enable-fpm`为php-fpm支持)配置它们。
- 在单独的目录(/opt/php-5.5`,`/opt/php-5.6`)中安装和配置不同的PHP版本以隔离它们并避免冲突。 >
- >将NGINX配置修改为基于服务器名称将流量引向不同的PHP版本,允许同时托管多个需要不同PHP环境的应用程序。
- >初步注释
- 本教程将涵盖PHP 5.5.x的安装,并使用Phalcon 1.3.x和Php 5.6.x,带有Phalcon 2.0.0。我们还将构建一些其他PHP扩展,例如APC,memcache,memcached和ioncube。 >安装nginx
然后,我们为Nginx创建系统启动链接并开始
建立php
从PHP开始之前,我们需要安装构建php5的先决条件:
GCC或其他一些编译器套件。
sudo yum install nginx
make,这是PHP使用的构建管理工具。
sudo chkconfig nginx on sudo service nginx start
> libtool,帮助我们管理共享库。
>野牛(2.4或更高),用于生成PHP解析器。
(可选)RE2C,用于生成PHP Lexer。由于GIT存储库已经包含生成的lexer,因此只有在您想对其进行更改时才需要RE2C。- >
- >在CentOS/Fedora上,您可以使用以下命令安装所有这些:
- 然后,我们需要获取其源代码。有两种方法:您可以从PHP的下载页面下载存档,也可以从GitHub中克隆Git存储库。
>我们建议您从git中查看源代码,因为它为您提供了一种简单的方法,可以使安装保持最新状态并使用不同版本尝试代码。如果要提交补丁或拉动请求,则还需要结帐。
克隆存储库,在您的终端中运行以下命令:>
sudo yum install nginx
sudo chkconfig nginx on sudo service nginx start
>
sudo yum install gcc libxml2-devel libXpm-devel gmp-devel libicu-devel t1lib-devel aspell-devel openssl-devel bzip2-devel libcurl-devel libjpeg-devel libvpx-devel libpng-devel freetype-devel readline-devel libtidy-devel libxslt-devel libmcrypt-devel pcre-devel curl-devel mysql-devel ncurses-devel gettext-devel net-snmp-devel libevent-devel libtool-ltdl-devel libc-client-devel postgresql-devel bison gcc make
我认为,将整个Web服务器存储在单个目录中是最好的,因此我在此处使用 /选择。打开终端并键入以下命令。
>通过上述步骤生成./configure脚本后,您可以使用它来自定义PHP构建。您可以使用–HELP列出所有受支持的选项:
sudo mkdir /opt/source && cd /opt/source git clone git@github.com:php/php-src.git && cd php-src
>上面的命令将列出各种通用选项,所有基于AutoConf的配置脚本都支持这些通用选项。其中一个已经提到 - prefix = dir,它更改了Make Install使用的安装目录。另一个有用的选项是-c,它将缓存config.cache文件中各种测试的结果,并加快后续的./configure调用。只有一旦您已经有了工作构建,并且想快速在不同的配置之间进行更改。
<span> PHP 5.3: git checkout PHP-5.3 </span><span> PHP 5.4: git checkout PHP-5.4 </span><span> PHP 5.6: git checkout PHP-5.6 </span><span> PHP HEAD: git checkout master </span>
完成准备后,我们安装了PHP版本5.6。运行以下内容:
sudo ./buildconf
应该在终端中打印成功的消息:
>sudo mkdir -p /opt/php-5.6 sudo mkdir -p /opt/php-5.5
现在,您可以使用Make来执行实际的汇编:
此操作的主要结果将是启用SAPI的PHP二进制文件(默认情况下,SAPI/CLI/PHP和SAPI/CGI/PHP-CGI),以及模块/目录中的共享扩展。
现在,您可以通过使用-prefix Configuration运行“ MAKE INSTAL”将PHP安装到 /usr /local(默认)或其他目录中。在这种情况下,是/OPT/PHP-5.6./configure --help
请注意,MAKE INSTARM不会创建INI文件。
[...] Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print `checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for `--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or `..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, `make install' will install all the files in `/usr/local/bin', `/usr/local/lib' etc. You can specify an installation prefix other than `/usr/local' using `--prefix', for instance `--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] [...]
>复制php.ini和php-fpm.conf到正确的目录:
我们再一次验证并检查PHP版本。
./configure \ --prefix=/opt/php-5.6 \ --with-pdo-pgsql \ --with-zlib-dir \ --with-freetype-dir \ --enable-mbstring \ --with-libxml-dir=/usr \ --enable-soap \ --enable-calendar \ --with-curl \ --with-mcrypt \ --with-zlib \ --with-gd \ --with-pgsql \ --disable-rpath \ --enable-inline-optimization \ --with-bz2 \ --with-zlib \ --enable-sockets \ --enable-sysvsem \ --enable-sysvshm \ --enable-pcntl \ --enable-mbregex \ --with-mhash \ --enable-zip \ --with-pcre-regex \ --with-mysql \ --with-pdo-mysql \ --with-mysqli \ --with-png-dir=/usr \ --enable-gd-native-ttf \ --with-openssl \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --with-libdir=lib64 \ --enable-ftp \ --with-imap \ --with-imap-ssl \ --with-kerberos \ --with-gettext \ --with-gd \ --with-jpeg-dir=/usr/lib/ --enable-fpm
sudo yum install nginx
> open/opt/php-5.6/etc/php-fpm.conf并调整收听行中的设置。您必须更改为未使用的端口(例如9001; Fedora可能正在使用9000端口9000)
sudo chkconfig nginx on sudo service nginx start
sudo yum install gcc libxml2-devel libXpm-devel gmp-devel libicu-devel t1lib-devel aspell-devel openssl-devel bzip2-devel libcurl-devel libjpeg-devel libvpx-devel libpng-devel freetype-devel readline-devel libtidy-devel libxslt-devel libmcrypt-devel pcre-devel curl-devel mysql-devel ncurses-devel gettext-devel net-snmp-devel libevent-devel libtool-ltdl-devel libc-client-devel postgresql-devel bison gcc make
> init脚本设置
>您可能需要为新的PHP-FPM创建一个初始脚本。幸运的是,PHP 5.3已经为您提供了它,只需将INIT脚本复制到您的目录并更改权限:
:sudo mkdir /opt/source && cd /opt/source git clone git@github.com:php/php-src.git && cd php-src
您的初始脚本已经准备就绪。现在,您可以启动,停止和重新加载php-fpm:
<span> PHP 5.3: git checkout PHP-5.3 </span><span> PHP 5.4: git checkout PHP-5.4 </span><span> PHP 5.6: git checkout PHP-5.6 </span><span> PHP HEAD: git checkout master </span>
我们打开终端并键入以下命令。
>
sudo ./buildconf
>要安装包括phalcon 2.0在内的多个版本的phalcon,我们需要安装Zephir
sudo mkdir -p /opt/php-5.6 sudo mkdir -p /opt/php-5.5
PHPIZE扮演与用于PHP构建的./buildconf脚本相似的角色:首先,它将通过从$ prefix/lib/php/build复制文件来将PHP构建系统导入扩展名。其中包括acinclude.m4(php的M4宏),phpize.m4(将重命名为扩展程序中的配置。 然后,Phpize将调用AutoConf生成一个./configure文件,该文件可用于自定义扩展构建。例如安装备忘录,您必须添加 - 启用 - 磁性。
>记住!在构建扩展时,您必须指定 - wish-php-config选项(除非您只有单个全局安装PHP)。否则。/configure将无法正确确定PHP版本和标志。此外,php-config脚本还确保“ make install”命令将将生成的 *.SO文件移至右扩展名目录。
构建第一个php phalcon(2.0)
请检查它是否成功
安装扩展程序后。您仍然需要通过将其包括在php.ini文件中来激活它。
./configure --help
构建第二个php phalcon(1.3.x)
[...] Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print `checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for `--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or `..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, `make install' will install all the files in `/usr/local/bin', `/usr/local/lib' etc. You can specify an installation prefix other than `/usr/local' using `--prefix', for instance `--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] [...]
我们再次检查以确保安装成功
./configure \ --prefix=/opt/php-5.6 \ --with-pdo-pgsql \ --with-zlib-dir \ --with-freetype-dir \ --enable-mbstring \ --with-libxml-dir=/usr \ --enable-soap \ --enable-calendar \ --with-curl \ --with-mcrypt \ --with-zlib \ --with-gd \ --with-pgsql \ --disable-rpath \ --enable-inline-optimization \ --with-bz2 \ --with-zlib \ --enable-sockets \ --enable-sysvsem \ --enable-sysvshm \ --enable-pcntl \ --enable-mbregex \ --with-mhash \ --enable-zip \ --with-pcre-regex \ --with-mysql \ --with-pdo-mysql \ --with-mysqli \ --with-png-dir=/usr \ --enable-gd-native-ttf \ --with-openssl \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --with-libdir=lib64 \ --enable-ftp \ --with-imap \ --with-imap-ssl \ --with-kerberos \ --with-gettext \ --with-gd \ --with-jpeg-dir=/usr/lib/ --enable-fpm
配置nginx
[...] creating libtool appending configuration tag "CXX" to libtool Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/fpm/php-fpm.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands
以下配置将创建两个服务器:phalcon-prd.localhost在php 5.5.5.x和phalcon-dev.localhost上运行,可与PHP 5.6.x一起使用。这是一个示例,您可以将其自定义为所需的任何内容,请参阅Nginx文档
make
设置本地主机文件
sudo make install
新主机文件看起来像。
/opt/php-5.6/bin/php --ini Configuration File (php.ini) Path: /opt/php-5.6/lib Loaded Configuration File: (none) Scan for additional .ini files in: (none) Additional .ini files parsed: (none)
这个拦截了phalcon-dev.localhost和phalcon-prd.localhost的所有请求。测试
>用于测试,我们创建了一个名为test.php的新文件,并将其放入与上述NGINX配置相对应的文件夹中。在每个文件中,我们添加以下命令。
sudo yum install nginx
现在,在每个服务器中运行test.php文件,我们在http://phancon-dev.localhost http://phancon-prd.localhost/test.php上看到一个phalcon 1.3.x phpinfo() /test.php应该有Phalcon 2.0.x.
的phpinfo()
总结
在本教程中,我们了解了如何在服务器上轻松地在服务器上轻松运行多个主动运行版本的PHP版本,每个版本在必要时都有自己的一组不同的扩展名。如果您进行共享托管,或者您需要支持古老的旧应用程序,同时可以在尖端版本上开发和部署。
>在下面的评论中留下您的反馈,一如既往,如果您喜欢的话,请分享本文!>经常询问有关在一台服务器上运行多个PHP版本的问题
>如何在Ubuntu 18.04上使用Apache和PHP-FPM在一台服务器上运行多个PHP版本?安装所需的PHP版本和Apache。然后,您需要配置Apache来为每个站点使用PHP-FPM版本。您可以通过编辑每个站点的Apache配置文件并设置ProxyPassMatch指令以使用正确的PHP-FPM池来执行此操作。之后,您需要为每个PHP版本创建一个PHP-FPM池。最后,重新启动apache和php-fpm以应用更改。>如何在服务器上的不同php版本之间切换?
>您可以使用A2ENMOD在服务器上的不同PHP版本之间切换和a2dismod命令。 A2ENMOD命令启用一个模块,A2Dismod命令禁用模块。要切换到其他PHP版本,您需要禁用当前的PHP版本并启用所需的PHP版本。之后,您需要重新启动apache应用更改。
>如何运行具有不同版本的PHP的不同网站?
以运行具有不同版本的PHP的不同网站,您需要配置每个网站以使用不同的PHP版本。您可以通过编辑每个网站的Apache配置文件来做到这一点,并设置ProxyPassMatch指令以使用正确的PHP-FPM池。之后,您需要为每个PHP版本创建一个PHP-FPM池。最后,重新启动apache和php-fpm以应用更改。>
>如何使用Apache和PHP-FPM和PHP-FPM在Fedora 35上安装多个PHP版本? apache。然后,您需要配置Apache来为每个站点使用PHP-FPM版本。您可以通过编辑每个站点的Apache配置文件并设置ProxyPassMatch指令以使用正确的PHP-FPM池来执行此操作。之后,您需要为每个PHP版本创建一个PHP-FPM池。最后,重新启动Apache和php-fpm以应用更改。
>我如何使用PHPENV管理多个PHP版本?
您可以使用PHPENV通过安装PHPENV和PHP版本来管理多个PHP版本。必需的PHP版本。然后,您可以使用PHPENV命令在不同的PHP版本之间切换。您还可以使用PHPENV Global命令设置全局PHP版本,而PHPENV LOCAL命令为特定目录设置本地PHP版本。
>如何检查服务器上的当前PHP版本?您可以通过在终端中运行PHP -V命令来检查服务器上的当前PHP版本。此命令将显示当前的PHP版本和有关PHP安装的其他信息。>
>如何在服务器上安装特定的PHP版本?>您可以在服务器上安装特定的PHP版本通过使用apt-get安装命令,然后使用所需的PHP版本的软件包名称。例如,要安装PHP 7.2,您将运行命令apt-get install php7.2。通过编辑Apache配置文件并设置ProxyPassMatch指令以使用正确的PHP-FPM池来使用特定的PHP版本。之后,您需要重新启动apache应用更改。
>如何为特定的PHP版本创建PHP-fpm池?特定的PHP版本是通过在/etc/php/7.2/fpm/pool.d/ directory中创建新的池配置文件。配置文件应包含PHP-FPM池的设置,例如收听地址和端口,用户和组以及Process Manager设置。
>我如何在运行多个PHP版本上的问题上解决问题。一台服务器?
您可以通过选中APACHE和PHP-FPM错误日志在一台服务器上运行多个PHP版本的问题进行故障排除。错误日志可以提供有关Apache配置或PHP-FPM池的任何问题的信息。您还可以使用php -v命令检查当前的PHP版本和A2enMod命令,以检查启用了哪些PHP模块。
>以上是如何在一台服务器上运行多个版本的PHP的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

JWT是一种基于JSON的开放标准,用于在各方之间安全地传输信息,主要用于身份验证和信息交换。1.JWT由Header、Payload和Signature三部分组成。2.JWT的工作原理包括生成JWT、验证JWT和解析Payload三个步骤。3.在PHP中使用JWT进行身份验证时,可以生成和验证JWT,并在高级用法中包含用户角色和权限信息。4.常见错误包括签名验证失败、令牌过期和Payload过大,调试技巧包括使用调试工具和日志记录。5.性能优化和最佳实践包括使用合适的签名算法、合理设置有效期、

PHP8.1中的枚举功能通过定义命名常量增强了代码的清晰度和类型安全性。1)枚举可以是整数、字符串或对象,提高了代码可读性和类型安全性。2)枚举基于类,支持面向对象特性,如遍历和反射。3)枚举可用于比较和赋值,确保类型安全。4)枚举支持添加方法,实现复杂逻辑。5)严格类型检查和错误处理可避免常见错误。6)枚举减少魔法值,提升可维护性,但需注意性能优化。

SOLID原则在PHP开发中的应用包括:1.单一职责原则(SRP):每个类只负责一个功能。2.开闭原则(OCP):通过扩展而非修改实现变化。3.里氏替换原则(LSP):子类可替换基类而不影响程序正确性。4.接口隔离原则(ISP):使用细粒度接口避免依赖不使用的方法。5.依赖倒置原则(DIP):高低层次模块都依赖于抽象,通过依赖注入实现。

会话劫持可以通过以下步骤实现:1.获取会话ID,2.使用会话ID,3.保持会话活跃。在PHP中防范会话劫持的方法包括:1.使用session_regenerate_id()函数重新生成会话ID,2.通过数据库存储会话数据,3.确保所有会话数据通过HTTPS传输。

静态绑定(static::)在PHP中实现晚期静态绑定(LSB),允许在静态上下文中引用调用类而非定义类。1)解析过程在运行时进行,2)在继承关系中向上查找调用类,3)可能带来性能开销。

RESTAPI设计原则包括资源定义、URI设计、HTTP方法使用、状态码使用、版本控制和HATEOAS。1.资源应使用名词表示并保持层次结构。2.HTTP方法应符合其语义,如GET用于获取资源。3.状态码应正确使用,如404表示资源不存在。4.版本控制可通过URI或头部实现。5.HATEOAS通过响应中的链接引导客户端操作。

在PHP中,异常处理通过try,catch,finally,和throw关键字实现。1)try块包围可能抛出异常的代码;2)catch块处理异常;3)finally块确保代码始终执行;4)throw用于手动抛出异常。这些机制帮助提升代码的健壮性和可维护性。

匿名类在PHP中的主要作用是创建一次性使用的对象。1.匿名类允许在代码中直接定义没有名字的类,适用于临时需求。2.它们可以继承类或实现接口,增加灵活性。3.使用时需注意性能和代码可读性,避免重复定义相同的匿名类。
