centos下多版本php如何分别安装php扩展

centos下多版本php如何分别安装php扩展

centos下多版本php如何分别安装php扩展

php从5.3到7.4版本很多,如果只有一个版本,那么安装扩展会非常简单,我们以ssh2这个扩展为例

一、单版本php扩展安装

1、安装支持库文件

yum install php-devel php-pear libssh2 libssh2-devel -y

2、安装ssh2扩展

pecl install -f ssh2

如果出现需要输入的情况直接按回车键

这个命令的编译过程如下

WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading ssh2-0.13.tgz ...
Starting to download ssh2-0.13.tgz (28,984 bytes)
.........done: 28,984 bytes
6 source files, building
running: phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
libssh2 prefix? [autodetect] :
building in /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13
running: /tmp/pear/temp/ssh2/configure --with-php-config=/usr/local/php56/bin/php-config --with-ssh2
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php56
checking for PHP includes... -I/usr/local/php56/include/php -I/usr/local/php56/include/php/main -I/usr/local/php56/include/php/TSRM -I/usr/local/php56/include/php/Zend -I/usr/local/php56/include/php/ext -I/usr/local/php56/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php56/lib/php/extensions/no-debug-non-zts-20131226
checking for PHP installed headers prefix... /usr/local/php56/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for ssh2 support... yes, shared
checking for ssh2 files in default path... found in /usr
checking for libssh2_session_hostkey in -lssh2... yes
checking for libssh2_agent_init in -lssh2... yes
checking for libssh2_session_set_timeout in -lssh2... yes
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1966080
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/libtool --mode=compile cc -I. -I/tmp/pear/temp/ssh2 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/include -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/main -I/tmp/pear/temp/ssh2 -I/usr/local/php56/include/php -I/usr/local/php56/include/php/main -I/usr/local/php56/include/php/TSRM -I/usr/local/php56/include/php/Zend -I/usr/local/php56/include/php/ext -I/usr/local/php56/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/ssh2/ssh2.c -o ssh2.lo
mkdir .libs
cc -I. -I/tmp/pear/temp/ssh2 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/include -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/main -I/tmp/pear/temp/ssh2 -I/usr/local/php56/include/php -I/usr/local/php56/include/php/main -I/usr/local/php56/include/php/TSRM -I/usr/local/php56/include/php/Zend -I/usr/local/php56/include/php/ext -I/usr/local/php56/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/ssh2/ssh2.c -fPIC -DPIC -o .libs/ssh2.o
/tmp/pear/temp/ssh2/ssh2.c: In function ‘zif_ssh2_publickey_add’:
/tmp/pear/temp/ssh2/ssh2.c:1069: warning: passing argument 1 of ‘_efree’ discards qualifiers from pointer target type
/usr/local/php56/include/php/Zend/zend_alloc.h:61: note: expected ‘void *’ but argument is of type ‘const char *’
/tmp/pear/temp/ssh2/ssh2.c: In function ‘zif_ssh2_publickey_list’:
/tmp/pear/temp/ssh2/ssh2.c:1128: warning: passing argument 4 of ‘add_assoc_stringl_ex’ discards qualifiers from pointer target type
/usr/local/php56/include/php/Zend/zend_API.h:386: note: expected ‘char *’ but argument is of type ‘const unsigned char *’
/tmp/pear/temp/ssh2/ssh2.c:1129: warning: passing argument 4 of ‘add_assoc_stringl_ex’ discards qualifiers from pointer target type
/usr/local/php56/include/php/Zend/zend_API.h:386: note: expected ‘char *’ but argument is of type ‘const unsigned char *’
/bin/sh /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/libtool --mode=compile cc -I. -I/tmp/pear/temp/ssh2 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/include -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/main -I/tmp/pear/temp/ssh2 -I/usr/local/php56/include/php -I/usr/local/php56/include/php/main -I/usr/local/php56/include/php/TSRM -I/usr/local/php56/include/php/Zend -I/usr/local/php56/include/php/ext -I/usr/local/php56/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/ssh2/ssh2_fopen_wrappers.c -o ssh2_fopen_wrappers.lo
cc -I. -I/tmp/pear/temp/ssh2 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/include -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/main -I/tmp/pear/temp/ssh2 -I/usr/local/php56/include/php -I/usr/local/php56/include/php/main -I/usr/local/php56/include/php/TSRM -I/usr/local/php56/include/php/Zend -I/usr/local/php56/include/php/ext -I/usr/local/php56/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/ssh2/ssh2_fopen_wrappers.c -fPIC -DPIC -o .libs/ssh2_fopen_wrappers.o
/tmp/pear/temp/ssh2/ssh2_fopen_wrappers.c:651: warning: initialization from incompatible pointer type
/tmp/pear/temp/ssh2/ssh2_fopen_wrappers.c:872: warning: initialization from incompatible pointer type
/tmp/pear/temp/ssh2/ssh2_fopen_wrappers.c:1013: warning: initialization from incompatible pointer type
/tmp/pear/temp/ssh2/ssh2_fopen_wrappers.c:1281: warning: initialization from incompatible pointer type
/bin/sh /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/libtool --mode=compile cc -I. -I/tmp/pear/temp/ssh2 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/include -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/main -I/tmp/pear/temp/ssh2 -I/usr/local/php56/include/php -I/usr/local/php56/include/php/main -I/usr/local/php56/include/php/TSRM -I/usr/local/php56/include/php/Zend -I/usr/local/php56/include/php/ext -I/usr/local/php56/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/ssh2/ssh2_sftp.c -o ssh2_sftp.lo
cc -I. -I/tmp/pear/temp/ssh2 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/include -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/main -I/tmp/pear/temp/ssh2 -I/usr/local/php56/include/php -I/usr/local/php56/include/php/main -I/usr/local/php56/include/php/TSRM -I/usr/local/php56/include/php/Zend -I/usr/local/php56/include/php/ext -I/usr/local/php56/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/ssh2/ssh2_sftp.c -fPIC -DPIC -o .libs/ssh2_sftp.o
/tmp/pear/temp/ssh2/ssh2_sftp.c:548: warning: initialization from incompatible pointer type
/tmp/pear/temp/ssh2/ssh2_sftp.c:552: warning: initialization from incompatible pointer type
/tmp/pear/temp/ssh2/ssh2_sftp.c:556: warning: initialization from incompatible pointer type
/tmp/pear/temp/ssh2/ssh2_sftp.c:559: warning: initialization from incompatible pointer type
/tmp/pear/temp/ssh2/ssh2_sftp.c:560: warning: initialization from incompatible pointer type
/tmp/pear/temp/ssh2/ssh2_sftp.c:561: warning: initialization from incompatible pointer type
/tmp/pear/temp/ssh2/ssh2_sftp.c:562: warning: initialization from incompatible pointer type
/bin/sh /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/libtool --mode=link cc -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/include -I/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/main -I/tmp/pear/temp/ssh2 -I/usr/local/php56/include/php -I/usr/local/php56/include/php/main -I/usr/local/php56/include/php/TSRM -I/usr/local/php56/include/php/Zend -I/usr/local/php56/include/php/ext -I/usr/local/php56/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -o ssh2.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/modules ssh2.lo ssh2_fopen_wrappers.lo ssh2_sftp.lo -lssh2
cc -shared .libs/ssh2.o .libs/ssh2_fopen_wrappers.o .libs/ssh2_sftp.o -lssh2 -Wl,-soname -Wl,ssh2.so -o .libs/ssh2.so
creating ssh2.la
(cd .libs && rm -f ssh2.la && ln -s ../ssh2.la ssh2.la)
/bin/sh /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/libtool --mode=install cp ./ssh2.la /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/modules
cp ./.libs/ssh2.so /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/modules/ssh2.so
cp ./.libs/ssh2.lai /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/modules/ssh2.la
PATH="$PATH:/sbin" ldconfig -n /tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/modules
----------------------------------------------------------------------
Libraries have been installed in:
/tmp/pear/temp/pear-build-rootlYC8aS/ssh2-0.13/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13" install
Installing shared extensions: /tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13/usr/local/php56/lib/php/extensions/no-debug-non-zts-20131226/
running: find "/tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13" | xargs ls -dils
459099 4 drwxr-xr-x 3 root root 4096 Dec 17 18:41 /tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13
459125 4 drwxr-xr-x 3 root root 4096 Dec 17 18:41 /tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13/usr
459126 4 drwxr-xr-x 3 root root 4096 Dec 17 18:41 /tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13/usr/local
459127 4 drwxr-xr-x 3 root root 4096 Dec 17 18:41 /tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13/usr/local/php56
459128 4 drwxr-xr-x 3 root root 4096 Dec 17 18:41 /tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13/usr/local/php56/lib
459129 4 drwxr-xr-x 3 root root 4096 Dec 17 18:41 /tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13/usr/local/php56/lib/php
459130 4 drwxr-xr-x 3 root root 4096 Dec 17 18:41 /tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13/usr/local/php56/lib/php/extensions
459131 4 drwxr-xr-x 2 root root 4096 Dec 17 18:41 /tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13/usr/local/php56/lib/php/extensions/no-debug-non-zts-20131226
459124 240 -rwxr-xr-x 1 root root 241393 Dec 17 18:41 /tmp/pear/temp/pear-build-rootlYC8aS/install-ssh2-0.13/usr/local/php56/lib/php/extensions/no-debug-non-zts-20131226/ssh2.so

Build process completed successfully
Installing '/usr/local/php56/lib/php/extensions/no-debug-non-zts-20131226/ssh2.so'
install ok: channel://pecl.php.net/ssh2-0.13
configuration option "php_ini" is not set to php.ini location
You should add "extension=ssh2.so" to php.ini

他讲下载解压编译全部放在一起,一步就完成了

3、新建ssh2.ini文件,添加ssh2这个扩展

touch /usr/local/php56/lib/php//etc/php.d/ssh2.ini
echo extension=ssh2.so > /etc/php.d/ssh2.ini

4、最后重启一下php-fpm

service php-fpm restart

ok,这样就完成了php的扩展安装,如果细心的朋友会发现,这个安装命令是默认安装php56这个版本的php扩展,那么如果安装其他的版本呢,比如php55,怎么办呢?

二、多版本php的扩展安装

1、第一个步骤不变,安装支持库

yum install php-devel php-pear libssh2 libssh2-devel -y

2、手动安装ssh2,先下载ssh2的文件

wget http://pecl.php.net/get/ssh2-0.13.tgz

3、解压文件和phpize

tar zxvf ssh2-0.13.tgz

4、编译

cd ssh2-0.13
phpize
./configure --with-php-config=/usr/local/php55/bin/php-config --with-ssh2

注意这个时候with-php-config要改成其他版本的php的目录了

5、make

make
make install

ok,后面的步骤跟上面一样


{{collectdata}}

网友评论0