>在这篇特定的文章中,我们将演示一个解决方案,以安装Phalcon和PHP的多个版本,并在单个Web服务器上运行它们。 PHP 5.5.x和5.6.x将在此处使用,但是您可以用其他版本替换它们。任何支持PHP-FPM的服务器都足够,但我们建议使用NGINX。本教程中使用的环境是Fedora OS - 一个Linux系统,但对于任何其他 *NIX OS。
钥匙要点建立php
GCC或其他一些编译器套件。
sudo yum install nginx
make,这是PHP使用的构建管理工具。
sudo chkconfig nginx on sudo service nginx start
野牛(2.4或更高),用于生成PHP解析器。
(可选)RE2C,用于生成PHP Lexer。由于GIT存储库已经包含生成的lexer,因此只有在您想对其进行更改时才需要RE2C。>我们建议您从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
>您可能需要为新的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
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)
请检查它是否成功
./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
[...] 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)
>用于测试,我们创建了一个名为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版本的问题
>您可以使用A2ENMOD在服务器上的不同PHP版本之间切换和a2dismod命令。 A2ENMOD命令启用一个模块,A2Dismod命令禁用模块。要切换到其他PHP版本,您需要禁用当前的PHP版本并启用所需的PHP版本。之后,您需要重新启动apache应用更改。
>
>我如何使用PHPENV管理多个PHP版本?
>
>如何在服务器上安装特定的PHP版本?>如何为特定的PHP版本创建PHP-fpm池?特定的PHP版本是通过在/etc/php/7.2/fpm/pool.d/ directory中创建新的池配置文件。配置文件应包含PHP-FPM池的设置,例如收听地址和端口,用户和组以及Process Manager设置。
您可以通过选中APACHE和PHP-FPM错误日志在一台服务器上运行多个PHP版本的问题进行故障排除。错误日志可以提供有关Apache配置或PHP-FPM池的任何问题的信息。您还可以使用php -v命令检查当前的PHP版本和A2enMod命令,以检查启用了哪些PHP模块。
>以上是如何在一台服务器上运行多个版本的PHP的详细内容。更多信息请关注PHP中文网其他相关文章!