centos安装php多版本管理工具phpbrew
# centos安装php多版本管理工具phpbrew
本文讲述centos系统上安装php的多版本管理工具phpbrew的步骤。本文以centos8为例。
若想查看phpbrew工具的具体用法,请前往php多版本管理工具phpbrew的用法。
# 1. 安装依赖环境
yum install make gcc gcc-c++ kernel-devel -y yum install php php-json php-bz2 php-devel php-pear bzip2-devel yum-utils libmcrypt-devel libpqxx-devel libxslt-devel pcre-devel libcurl-devel libgsasl-devel openldap-devel lbzip2 krb5-devel openssl-devel yum-builddep -y yum install bison re2c -y
[root@c9428f17a7a6 ~]# yum install make gcc gcc-c++ kernel-devel -y
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 1:11:15 ago on Mon Dec 21 23:49:37 2020.
Package make-1:4.2.1-10.el8.x86_64 is already installed.
Package gcc-8.3.1-5.1.el8.x86_64 is already installed.
Package gcc-c++-8.3.1-5.1.el8.x86_64 is already installed.
Package kernel-devel-4.18.0-240.1.1.el8_3.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@c9428f17a7a6 ~]# yum install php php-bz2 php-devel php-pear bzip2-devel yum-utils libmcrypt-devel libpqxx-devel libxslt-devel pcre-devel libcurl-devel libgsasl-devel openldap-devel yum-builddep php -y
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 1:11:16 ago on Mon Dec 21 23:49:37 2020.
No match for argument: libpqxx-devel
No match for argument: yum-builddep
Error: Unable to find a match: libpqxx-devel yum-builddep
[root@c9428f17a7a6 ~]# yum install bison re2c -y
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 1:12:57 ago on Mon Dec 21 23:49:37 2020.
No match for argument: re2c
Error: Unable to find a match: re2c
[root@c9428f17a7a6 ~]#
执行如上命令提示依赖包
libpqxx-devel
、yum-builddep
和re2c
不存在,则去掉这几项,重新执行。
# 2. 安装phpbrew
执行如下命令,下载phpbrew二进制程序
curl -L -O https://github.com/phpbrew/phpbrew/releases/latest/download/phpbrew.phar
[root@c9428f17a7a6 ~]# curl -L -O https://github.com/phpbrew/phpbrew/releases/latest/download/phpbrew.phar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 138 100 138 0 0 230 0 --:--:-- --:--:-- --:--:-- 229
100 634 100 634 0 0 611 0 0:00:01 0:00:01 --:--:-- 611
100 1539k 100 1539k 0 0 29078 0 0:00:54 0:00:54 --:--:-- 36647
[root@c9428f17a7a6 ~]#
执行如下命令,赋予可执行权限
chmod +x ./phpbrew
移动phpbrew程序到全局PATH目录中,这样可以在系统任意目录发现命令phpbrew。 命令如下:
mv phpbrew.phar /usr/local/bin/phpbrew
[root@c9428f17a7a6 ~]# mv phpbrew.phar /usr/local/bin/phpbrew
[root@c9428f17a7a6 ~]# which phpbrew
/usr/local/bin/phpbrew
[root@c9428f17a7a6 ~]#
# 3. 初始化phpbrew配置
执行命令phpbrew init
初始化 Bash Shell 脚本。
[root@c9428f17a7a6 ~]# phpbrew init
# WARNING: json extension is required for parsing release info.
Using root: /root/.phpbrew
Initialization successfully finished!
<=====================================================>
Phpbrew environment is initialized, required directories are created under
/root/.phpbrew
Paste the following line(s) to the end of your ~/.bashrc and start a
new shell, phpbrew should be up and fully functional from there:
source /root/.phpbrew/bashrc
To enable PHP version info in your shell prompt, please set PHPBREW_SET_PROMPT=1
in your `~/.bashrc` before you source `~/.phpbrew/bashrc`
export PHPBREW_SET_PROMPT=1
To enable .phpbrewrc file searching, please export the following variable:
export PHPBREW_RC_ENABLE=1
For further instructions, simply run `phpbrew` to see the help message.
Enjoy phpbrew at $HOME!!
<=====================================================>
[root@c9428f17a7a6 ~]#
在 .bashrc 或 .zshrc 文件增加如下行
[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc
执行echo命令即可完成该文件的编辑,过程如下:
[root@c9428f17a7a6 ~]# echo "[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc" >> .bashrc
[root@c9428f17a7a6 ~]# cat .bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc
[root@c9428f17a7a6 ~]#
默认情况下, phpbrew的数据目录为~/.phpbrew/。若想更改该目录,则可以在初始化时指定目录位置,如下: mkdir -p /opt/phpbrew phpbrew init --root=/opt/phpbrew