如何在一台服務器上運行多個版本的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.性能優化和最佳實踐包括使用合適的簽名算法、合理設置有效期、

會話劫持可以通過以下步驟實現:1.獲取會話ID,2.使用會話ID,3.保持會話活躍。在PHP中防範會話劫持的方法包括:1.使用session_regenerate_id()函數重新生成會話ID,2.通過數據庫存儲會話數據,3.確保所有會話數據通過HTTPS傳輸。

在PHP中,異常處理通過try,catch,finally,和throw關鍵字實現。 1)try塊包圍可能拋出異常的代碼;2)catch塊處理異常;3)finally塊確保代碼始終執行;4)throw用於手動拋出異常。這些機制幫助提升代碼的健壯性和可維護性。

PHP中有四種主要錯誤類型:1.Notice:最輕微,不會中斷程序,如訪問未定義變量;2.Warning:比Notice嚴重,不會終止程序,如包含不存在文件;3.FatalError:最嚴重,會終止程序,如調用不存在函數;4.ParseError:語法錯誤,會阻止程序執行,如忘記添加結束標籤。

在PHP中,include,require,include_once,require_once的區別在於:1)include產生警告並繼續執行,2)require產生致命錯誤並停止執行,3)include_once和require_once防止重複包含。這些函數的選擇取決於文件的重要性和是否需要防止重複包含,合理使用可以提高代碼的可讀性和可維護性。

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

PHP是一種廣泛應用於服務器端的腳本語言,特別適合web開發。 1.PHP可以嵌入HTML,處理HTTP請求和響應,支持多種數據庫。 2.PHP用於生成動態網頁內容,處理表單數據,訪問數據庫等,具有強大的社區支持和開源資源。 3.PHP是解釋型語言,執行過程包括詞法分析、語法分析、編譯和執行。 4.PHP可以與MySQL結合用於用戶註冊系統等高級應用。 5.調試PHP時,可使用error_reporting()和var_dump()等函數。 6.優化PHP代碼可通過緩存機制、優化數據庫查詢和使用內置函數。 7

HTTP請求方法包括GET、POST、PUT和DELETE,分別用於獲取、提交、更新和刪除資源。 1.GET方法用於獲取資源,適用於讀取操作。 2.POST方法用於提交數據,常用於創建新資源。 3.PUT方法用於更新資源,適用於完整更新。 4.DELETE方法用於刪除資源,適用於刪除操作。
