分类 服务器 下的文章

因业务需要需要使用MQ,需要用到amqp,但现在所使用的PHP环境没有装这个扩展,参考segmentfault里的一篇教程进行安装,整理出了下面的教程。在这里,感谢@一个向往前端的后端工程师

安装rabbitmq-c

在安装amqp之前还需要安装另外一个通讯扩展rabbitmq-c。

下载源代码

最新源代码地址可以从github获取,这里用的是v0.10.0版本(发布本教程时最新版)

wget https://github.com/alanxz/rabbitmq-c/archive/v0.10.0.zip

解压源代码并转到源代码目录

unzip v0.10.0.zip && cd rabbitmq-c-0.10.0

让cmake根据CMakeList.txt创建Makefile文件

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c .

执行结果

-- The C compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- CMAKE_BUILD_TYPE not specified. Creating Release build
-- Found C inline keyword: inline
-- Looking for getaddrinfo
-- Looking for getaddrinfo - found
-- Looking for socket
-- Looking for socket - found
-- Looking for poll
-- Looking for poll - found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
-- Looking for posix_spawnp in rt
-- Looking for posix_spawnp in rt - found
-- Found OpenSSL: /usr/lib64/libssl.so;/usr/lib64/libcrypto.so (found suitable version "1.0.2k", minimum required is "0.9.8")
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Performing Test HAVE_GNU90
-- Performing Test HAVE_GNU90 - Success
-- Could NOT find POPT (missing:  POPT_INCLUDE_DIR POPT_LIBRARY)
-- Could NOT find XMLTO (missing:  XMLTO_EXECUTABLE)
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE)
-- Building rabbitmq as a shared library - yes
-- Building rabbitmq as a static library - yes
-- Configuring done
-- Generating done
-- Build files have been written to: /root/rabbitmq-c-0.10.0

开始编译rabbitmq-c库

cmake --build . --target install

执行结果

Scanning dependencies of target rabbitmq
[  1%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_framing.c.o
[  2%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_api.c.o
[  4%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_connection.c.o
[  5%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_mem.c.o
[  7%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_socket.c.o
[  8%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_table.c.o
[ 10%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_url.c.o
[ 11%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_tcp_socket.c.o
[ 13%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_time.c.o
[ 14%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_consumer.c.o
[ 15%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_openssl.c.o
[ 17%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_openssl_hostname_validation.c.o
[ 18%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_hostcheck.c.o
[ 20%] Building C object librabbitmq/CMakeFiles/rabbitmq.dir/amqp_openssl_bio.c.o
Linking C shared library librabbitmq.so
[ 20%] Built target rabbitmq
Scanning dependencies of target rabbitmq-static
[ 21%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_framing.c.o
[ 23%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_api.c.o
[ 24%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_connection.c.o
[ 26%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_mem.c.o
[ 27%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_socket.c.o
[ 28%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_table.c.o
[ 30%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_url.c.o
[ 31%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_tcp_socket.c.o
[ 33%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_time.c.o
[ 34%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_consumer.c.o
[ 36%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_openssl.c.o
[ 37%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_openssl_hostname_validation.c.o
[ 39%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_hostcheck.c.o
[ 40%] Building C object librabbitmq/CMakeFiles/rabbitmq-static.dir/amqp_openssl_bio.c.o
Linking C static library librabbitmq.a
[ 40%] Built target rabbitmq-static
Scanning dependencies of target amqp_bind
[ 42%] Building C object examples/CMakeFiles/amqp_bind.dir/amqp_bind.c.o
[ 43%] Building C object examples/CMakeFiles/amqp_bind.dir/utils.c.o
[ 44%] Building C object examples/CMakeFiles/amqp_bind.dir/unix/platform_utils.c.o
Linking C executable amqp_bind
[ 44%] Built target amqp_bind
Scanning dependencies of target amqp_connect_timeout
[ 46%] Building C object examples/CMakeFiles/amqp_connect_timeout.dir/amqp_connect_timeout.c.o
[ 47%] Building C object examples/CMakeFiles/amqp_connect_timeout.dir/utils.c.o
[ 49%] Building C object examples/CMakeFiles/amqp_connect_timeout.dir/unix/platform_utils.c.o
Linking C executable amqp_connect_timeout
[ 49%] Built target amqp_connect_timeout
Scanning dependencies of target amqp_consumer
[ 50%] Building C object examples/CMakeFiles/amqp_consumer.dir/amqp_consumer.c.o
[ 52%] Building C object examples/CMakeFiles/amqp_consumer.dir/utils.c.o
[ 53%] Building C object examples/CMakeFiles/amqp_consumer.dir/unix/platform_utils.c.o
Linking C executable amqp_consumer
[ 53%] Built target amqp_consumer
Scanning dependencies of target amqp_exchange_declare
[ 55%] Building C object examples/CMakeFiles/amqp_exchange_declare.dir/amqp_exchange_declare.c.o
[ 56%] Building C object examples/CMakeFiles/amqp_exchange_declare.dir/utils.c.o
[ 57%] Building C object examples/CMakeFiles/amqp_exchange_declare.dir/unix/platform_utils.c.o
Linking C executable amqp_exchange_declare
[ 57%] Built target amqp_exchange_declare
Scanning dependencies of target amqp_listen
[ 59%] Building C object examples/CMakeFiles/amqp_listen.dir/amqp_listen.c.o
[ 60%] Building C object examples/CMakeFiles/amqp_listen.dir/utils.c.o
[ 62%] Building C object examples/CMakeFiles/amqp_listen.dir/unix/platform_utils.c.o
Linking C executable amqp_listen
[ 62%] Built target amqp_listen
Scanning dependencies of target amqp_listenq
[ 63%] Building C object examples/CMakeFiles/amqp_listenq.dir/amqp_listenq.c.o
[ 65%] Building C object examples/CMakeFiles/amqp_listenq.dir/utils.c.o
[ 66%] Building C object examples/CMakeFiles/amqp_listenq.dir/unix/platform_utils.c.o
Linking C executable amqp_listenq
[ 66%] Built target amqp_listenq
Scanning dependencies of target amqp_producer
[ 68%] Building C object examples/CMakeFiles/amqp_producer.dir/amqp_producer.c.o
[ 69%] Building C object examples/CMakeFiles/amqp_producer.dir/utils.c.o
[ 71%] Building C object examples/CMakeFiles/amqp_producer.dir/unix/platform_utils.c.o
Linking C executable amqp_producer
[ 71%] Built target amqp_producer
Scanning dependencies of target amqp_rpc_sendstring_client
[ 72%] Building C object examples/CMakeFiles/amqp_rpc_sendstring_client.dir/amqp_rpc_sendstring_client.c.o
[ 73%] Building C object examples/CMakeFiles/amqp_rpc_sendstring_client.dir/utils.c.o
[ 75%] Building C object examples/CMakeFiles/amqp_rpc_sendstring_client.dir/unix/platform_utils.c.o
Linking C executable amqp_rpc_sendstring_client
[ 75%] Built target amqp_rpc_sendstring_client
Scanning dependencies of target amqp_sendstring
[ 76%] Building C object examples/CMakeFiles/amqp_sendstring.dir/amqp_sendstring.c.o
[ 78%] Building C object examples/CMakeFiles/amqp_sendstring.dir/utils.c.o
[ 79%] Building C object examples/CMakeFiles/amqp_sendstring.dir/unix/platform_utils.c.o
Linking C executable amqp_sendstring
[ 79%] Built target amqp_sendstring
Scanning dependencies of target amqp_ssl_connect
[ 81%] Building C object examples/CMakeFiles/amqp_ssl_connect.dir/amqp_ssl_connect.c.o
[ 82%] Building C object examples/CMakeFiles/amqp_ssl_connect.dir/utils.c.o
[ 84%] Building C object examples/CMakeFiles/amqp_ssl_connect.dir/unix/platform_utils.c.o
Linking C executable amqp_ssl_connect
[ 84%] Built target amqp_ssl_connect
Scanning dependencies of target amqp_unbind
[ 85%] Building C object examples/CMakeFiles/amqp_unbind.dir/amqp_unbind.c.o
[ 86%] Building C object examples/CMakeFiles/amqp_unbind.dir/utils.c.o
[ 88%] Building C object examples/CMakeFiles/amqp_unbind.dir/unix/platform_utils.c.o
Linking C executable amqp_unbind
[ 88%] Built target amqp_unbind
Scanning dependencies of target test_basic
[ 89%] Building C object tests/CMakeFiles/test_basic.dir/test_basic.c.o
Linking C executable test_basic
[ 89%] Built target test_basic
Scanning dependencies of target test_hostcheck
[ 91%] Building C object tests/CMakeFiles/test_hostcheck.dir/test_hostcheck.c.o
[ 92%] Building C object tests/CMakeFiles/test_hostcheck.dir/__/librabbitmq/amqp_hostcheck.c.o
Linking C executable test_hostcheck
[ 92%] Built target test_hostcheck
Scanning dependencies of target test_merge_capabilities
[ 94%] Building C object tests/CMakeFiles/test_merge_capabilities.dir/test_merge_capabilities.c.o
Linking C executable test_merge_capabilities
[ 94%] Built target test_merge_capabilities
Scanning dependencies of target test_parse_url
[ 95%] Building C object tests/CMakeFiles/test_parse_url.dir/test_parse_url.c.o
Linking C executable test_parse_url
[ 95%] Built target test_parse_url
Scanning dependencies of target test_sasl_mechanism
[ 97%] Building C object tests/CMakeFiles/test_sasl_mechanism.dir/test_sasl_mechanism.c.o
Linking C executable test_sasl_mechanism
[ 97%] Built target test_sasl_mechanism
Scanning dependencies of target test_status_enum
[ 98%] Building C object tests/CMakeFiles/test_status_enum.dir/test_status_enum.c.o
Linking C executable test_status_enum
[ 98%] Built target test_status_enum
Scanning dependencies of target test_tables
[100%] Building C object tests/CMakeFiles/test_tables.dir/test_tables.c.o
Linking C executable test_tables
[100%] Built target test_tables
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/rabbitmq-c/lib64/pkgconfig/librabbitmq.pc
-- Installing: /usr/local/rabbitmq-c/lib64/librabbitmq.so.4.4.0
-- Installing: /usr/local/rabbitmq-c/lib64/librabbitmq.so.4
-- Installing: /usr/local/rabbitmq-c/lib64/librabbitmq.so
-- Installing: /usr/local/rabbitmq-c/lib64/librabbitmq.a
-- Installing: /usr/local/rabbitmq-c/include/amqp.h
-- Installing: /usr/local/rabbitmq-c/include/amqp_framing.h
-- Installing: /usr/local/rabbitmq-c/include/amqp_tcp_socket.h
-- Installing: /usr/local/rabbitmq-c/include/amqp_ssl_socket.h

到这里就已经安装完成了。不过这里有一个坑。

软链接

你可以看一下/usr/local/rabbitmq-c下的目录只有include和lib64。因为后面编译安装amqp扩展的时候系统会到/usr/local/rabbitmq-c/lib目录下搜索依赖库,导致错误。所以这里需要加一步

ln -s /usr/local/rabbitmq-c/lib64 /usr/local/rabbitmq-c/lib

安装amqp扩展

下载源代码

最新源代码地址可以从PHP Pecl获取,这里用的是v1.9.4版本(发布本教程时最新版)

wget http://pecl.php.net/get/amqp-1.9.4.tgz

解压源代码并转到源代码目录

tar zxvf amqp-1.9.4.tgz && cd amqp-1.9.4

phpize

phpize 命令是用来准备 PHP 扩展库的编译环境的,主要是根据系统信息生成对应的configure文件。
宝塔支持同时使用多个PHP版本,所以注意这里的路径(/www/server/php/73/bin/phpize),换成你要添加的PHP版本对应的路径。

/www/server/php/73/bin/phpize

配置编译参数

宝塔支持同时使用多个PHP版本,所以注意这里的路径,换成你要添加的PHP版本对应的路径(/www/server/php/73/bin/php-config)。

./configure --with-php-config=/www/server/php/73/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c

执行结果

checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
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-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /www/server/php/73
checking for PHP includes... -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib
checking for PHP extension directory... /www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731
checking for PHP installed headers prefix... /www/server/php/73/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 amqp support... yes, shared
checking for amqp... yes, shared
checking for supported PHP versions... supported (7.3.13)
yes
checking for pkg-config... /usr/bin/pkg-config
checking for amqp files in default path... found in /usr/local/rabbitmq-c
checking for librabbitmq version... 0.10.0
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... 1572864
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

开始编译安装

make && make install

执行结果

/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp.c -o amqp.lo
mkdir .libs
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp.c  -fPIC -DPIC -o .libs/amqp.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_type.c -o amqp_type.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_type.c  -fPIC -DPIC -o .libs/amqp_type.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_exchange.c -o amqp_exchange.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_exchange.c  -fPIC -DPIC -o .libs/amqp_exchange.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_queue.c -o amqp_queue.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_queue.c  -fPIC -DPIC -o .libs/amqp_queue.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_connection.c -o amqp_connection.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_connection.c  -fPIC -DPIC -o .libs/amqp_connection.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_connection_resource.c -o amqp_connection_resource.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_connection_resource.c  -fPIC -DPIC -o .libs/amqp_connection_resource.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_channel.c -o amqp_channel.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_channel.c  -fPIC -DPIC -o .libs/amqp_channel.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_envelope.c -o amqp_envelope.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_envelope.c  -fPIC -DPIC -o .libs/amqp_envelope.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_basic_properties.c -o amqp_basic_properties.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_basic_properties.c  -fPIC -DPIC -o .libs/amqp_basic_properties.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_methods_handling.c -o amqp_methods_handling.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_methods_handling.c  -fPIC -DPIC -o .libs/amqp_methods_handling.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_timestamp.c -o amqp_timestamp.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_timestamp.c  -fPIC -DPIC -o .libs/amqp_timestamp.o
/bin/sh /root/amqp-1.9.4/libtool --mode=compile cc  -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2   -c /root/amqp-1.9.4/amqp_decimal.c -o amqp_decimal.lo
 cc -I. -I/root/amqp-1.9.4 -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include -DHAVE_CONFIG_H -g -O2 -c /root/amqp-1.9.4/amqp_decimal.c  -fPIC -DPIC -o .libs/amqp_decimal.o
/bin/sh /root/amqp-1.9.4/libtool --mode=link cc -DPHP_ATOM_INC -I/root/amqp-1.9.4/include -I/root/amqp-1.9.4/main -I/root/amqp-1.9.4 -I/www/server/php/73/include/php -I/www/server/php/73/include/php/main -I/www/server/php/73/include/php/TSRM -I/www/server/php/73/include/php/Zend -I/www/server/php/73/include/php/ext -I/www/server/php/73/include/php/ext/date/lib -I/usr/local/rabbitmq-c/include  -DHAVE_CONFIG_H  -g -O2    -o amqp.la -export-dynamic -avoid-version -prefer-pic -module -rpath /root/amqp-1.9.4/modules  amqp.lo amqp_type.lo amqp_exchange.lo amqp_queue.lo amqp_connection.lo amqp_connection_resource.lo amqp_channel.lo amqp_envelope.lo amqp_basic_properties.lo amqp_methods_handling.lo amqp_timestamp.lo amqp_decimal.lo -Wl,-rpath,/usr/local/rabbitmq-c/lib -L/usr/local/rabbitmq-c/lib -lrabbitmq
cc -shared  .libs/amqp.o .libs/amqp_type.o .libs/amqp_exchange.o .libs/amqp_queue.o .libs/amqp_connection.o .libs/amqp_connection_resource.o .libs/amqp_channel.o .libs/amqp_envelope.o .libs/amqp_basic_properties.o .libs/amqp_methods_handling.o .libs/amqp_timestamp.o .libs/amqp_decimal.o  -L/usr/local/rabbitmq-c/lib -lrabbitmq  -Wl,-rpath -Wl,/usr/local/rabbitmq-c/lib -Wl,-soname -Wl,amqp.so -o .libs/amqp.so
creating amqp.la
(cd .libs && rm -f amqp.la && ln -s ../amqp.la amqp.la)
/bin/sh /root/amqp-1.9.4/libtool --mode=install cp ./amqp.la /root/amqp-1.9.4/modules
cp ./.libs/amqp.so /root/amqp-1.9.4/modules/amqp.so
cp ./.libs/amqp.lai /root/amqp-1.9.4/modules/amqp.la
PATH="$PATH:/sbin" ldconfig -n /root/amqp-1.9.4/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /root/amqp-1.9.4/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'.

Installing shared extensions:     /www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731/

启用扩展

配置php.ini

大概在配置文件九百多行的位置新建一行,加入以下代码

extension=/www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731/amqp.so

重启php

重启php-fpm或重载配置

查看phpinfo()

查看phpinfo(),搜索amqp.host,如果找到基本就是安装成功。

以下是参考官方文档安装ODBC驱动的过程,跟官方教程是一毛一样,只是加上了每行命令的说明。

添加安装源到本机

curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo

卸载部分包,避免冲突

yum remove unixODBC-utf16 unixODBC-utf16-devel

安装msodbcsql17

ACCEPT_EULA=Y yum install msodbcsql17

安装mssql-tools

ACCEPT_EULA=Y yum install mssql-tools

写入环境变量

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile

写入环境变量

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc

让刚刚写入的环境变量生效

source ~/.bashrc

安装unixODBC-devel

yum install unixODBC-devel

最后,查看/etc/odbcinst.ini文件内容

cat /etc/odbcinst.ini

可以看到最后面有[ODBC Driver 17 for SQL Server]的配置,恭喜你,驱动安装完成

[PostgreSQL]
Description=ODBC for PostgreSQL
Driver=/usr/lib/psqlodbcw.so
Setup=/usr/lib/libodbcpsqlS.so
Driver64=/usr/lib64/psqlodbcw.so
Setup64=/usr/lib64/libodbcpsqlS.so
FileUsage=1

[MySQL]
Description=ODBC for MySQL
Driver=/usr/lib/libmyodbc5.so
Setup=/usr/lib/libodbcmyS.so
Driver64=/usr/lib64/libmyodbc5.so
Setup64=/usr/lib64/libodbcmyS.so
FileUsage=1

[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.4.so.1.1
UsageCount=1

最后,在PHP里测试下是否能正常连接,如果输出Connected就是成功了
注意更换成自己对应的信息:127.0.0.1数据库地址、1433数据库端口、jwj数据库名、sa数据库用户名、password数据库密码

<?php
try {
    $conn = new PDO('odbc:Driver={ODBC Driver 17 for SQL Server};Server=127.0.0.1,1433;Database=jwj;', 'sa', 'password');
} catch (PDOException $e) {
    exit('Error:' . $e->getMessage());
}
exit('Connected');

因业务需要,需要连接其它系统所使用的Microsoft SQL Server数据库,然后要使用PDO ODBC才能连接,但现在所使用的PHP环境没有装这个扩展,经过一系列踩坑,整理出了下面的教程。

安装unixODBC

unixODBC是一个数据库连接组件,安装pdo_odbc前需要安装这个,否则安装pdo_odbc时会出现Cannot find header file(s) for pdo_odbc错误

yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel

转到pdo_odbc源代码目录

从PHP5.1开始,PDO_ODBC包含在PHP源代码中。可以使用configure命令将PDO_ODBC扩展编译为静态或共享模块。
所以我们只需要转到pdo_odbc源代码目录进行编译,而不用再去另外下载了。

cd /www/server/php/56/src/ext/pdo_odbc

make clean

如果你在尝试这篇教程直接,尝试过其它网上的方法,先执行下以下命令清除缓存,否则加载扩展时可能会出现PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) '/www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226/pdo_odbc.so' in Unknown on line 0

make clean

phpize

phpize 命令是用来准备 PHP 扩展库的编译环境的,主要是根据系统信息生成对应的configure文件。

/www/server/php/56/bin/phpize

configure

./configure --with-php-config=/www/server/php/56/bin/php-config  --with-pdo-odbc=unixODBC,/usr/

执行结果

checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
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... /www/server/php/56
checking for PHP includes... -I/www/server/php/56/include/php -I/www/server/php/56/include/php/main -I/www/server/php/56/include/php/TSRM -I/www/server/php/56/include/php/Zend -I/www/server/php/56/include/php/ext -I/www/server/php/56/include/php/ext/date/lib
checking for PHP extension directory... /www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226
checking for PHP installed headers prefix... /www/server/php/56/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 ODBC v3 support for PDO... yes, shared
checking for PDO includes... checking for PDO includes... /www/server/php/56/include/php/ext
checking for selected PDO ODBC flavour... unixODBC
          libs       /usr//lib,
          headers    /usr//include
checking for odbc.h in /usr//include... no
checking for odbcsdk.h in /usr//include... no
checking for iodbc.h in /usr//include... no
checking for sqlunix.h in /usr//include... no
checking for sqltypes.h in /usr//include... yes
checking for sqlucode.h in /usr//include... yes
checking for sql.h in /usr//include... yes
checking for isql.h in /usr//include... no
checking for sqlext.h in /usr//include... yes
checking for isqlext.h in /usr//include... no
checking for udbcext.h in /usr//include... no
checking for sqlcli1.h in /usr//include... no
checking for LibraryManager.h in /usr//include... no
checking for cli0core.h in /usr//include... no
checking for cli0ext.h in /usr//include... no
checking for cli0cli.h in /usr//include... no
checking for cli0defs.h in /usr//include... no
checking for cli0env.h in /usr//include... no
checking for SQLBindCol in -lodbc... yes
checking for SQLAllocHandle in -lodbc... 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... 1572864
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

make

make && make install

执行结果

/bin/sh /www/server/php/56/src/ext/pdo_odbc/libtool --mode=link cc -DPHP_ATOM_INC -I/www/server/php/56/src/ext/pdo_odbc/include -I/www/server/php/56/src/ext/pdo_odbc/main -I/www/server/php/56/src/ext/pdo_odbc -I/www/server/php/56/include/php -I/www/server/php/56/include/php/main -I/www/server/php/56/include/php/TSRM -I/www/server/php/56/include/php/Zend -I/www/server/php/56/include/php/ext -I/www/server/php/56/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -o pdo_odbc.la -export-dynamic -avoid-version -prefer-pic -module -rpath /www/server/php/56/src/ext/pdo_odbc/modules  pdo_odbc.lo odbc_driver.lo odbc_stmt.lo -Wl,-rpath,/usr//lib -L/usr//lib -lodbc
cc -shared  .libs/pdo_odbc.o .libs/odbc_driver.o .libs/odbc_stmt.o  -L/usr//lib -lodbc  -Wl,-rpath -Wl,/usr//lib -Wl,-soname -Wl,pdo_odbc.so -o .libs/pdo_odbc.so
creating pdo_odbc.la
(cd .libs && rm -f pdo_odbc.la && ln -s ../pdo_odbc.la pdo_odbc.la)
/bin/sh /www/server/php/56/src/ext/pdo_odbc/libtool --mode=install cp ./pdo_odbc.la /www/server/php/56/src/ext/pdo_odbc/modules
cp ./.libs/pdo_odbc.so /www/server/php/56/src/ext/pdo_odbc/modules/pdo_odbc.so
cp ./.libs/pdo_odbc.lai /www/server/php/56/src/ext/pdo_odbc/modules/pdo_odbc.la
PATH="$PATH:/sbin" ldconfig -n /www/server/php/56/src/ext/pdo_odbc/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /www/server/php/56/src/ext/pdo_odbc/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'.

Installing shared extensions:     /www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226/

查看so文件是否生成

ls -lh /www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226/
total 2.1M
-rwxr-xr-x 1 root root 1.3M Sep  3 15:13 opcache.a
-rwxr-xr-x 1 root root 610K Sep  3 15:13 opcache.so
-rwxr-xr-x 1 root root 126K Sep  3 15:13 pdo_odbc.so

配置php.ini

大概在配置文件九百多行的位置新建一行,加入以下代码

extension=/www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226/pdo_odbc.so

重启php和httpd环境

重启php-fpm和nginx等

查看phpinfo()

查看phpinfo(),搜索PDO_ODBC,如果找到基本就是安装成功。

安装了扩展,还要在服务器安装数据库连接驱动才能连接SQL Server数据库,可以看我的下一篇文章。

最近,在阿里云的一台机子安装svn时,提示"Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"

# yum install -y subversion
Loaded plugins: fastestmirror
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/epel/7/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package subversion.x86_64 0:1.7.14-14.el7 will be installed
--> Processing Dependency: subversion-libs(x86-64) = 1.7.14-14.el7 for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_wc-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_subr-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_repos-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_ra_svn-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_ra_neon-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_ra_local-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_ra-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_fs_util-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_fs_fs-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_fs_base-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_fs-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_diff-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_delta-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_client-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libneon.so.27()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package neon.x86_64 0:0.30.0-3.el7 will be installed
--> Processing Dependency: libgnutls.so.28(GNUTLS_2_12)(64bit) for package: neon-0.30.0-3.el7.x86_64
--> Processing Dependency: libgnutls.so.28(GNUTLS_1_4)(64bit) for package: neon-0.30.0-3.el7.x86_64
--> Processing Dependency: libproxy.so.1()(64bit) for package: neon-0.30.0-3.el7.x86_64
--> Processing Dependency: libpakchois.so.0()(64bit) for package: neon-0.30.0-3.el7.x86_64
--> Processing Dependency: libgnutls.so.28()(64bit) for package: neon-0.30.0-3.el7.x86_64
---> Package subversion-libs.x86_64 0:1.7.14-14.el7 will be installed
--> Running transaction check
---> Package gnutls.x86_64 0:3.3.26-9.el7 will be installed
--> Processing Dependency: trousers >= 0.3.11.2 for package: gnutls-3.3.26-9.el7.x86_64
--> Processing Dependency: libnettle.so.4()(64bit) for package: gnutls-3.3.26-9.el7.x86_64
--> Processing Dependency: libhogweed.so.2()(64bit) for package: gnutls-3.3.26-9.el7.x86_64
---> Package libproxy.x86_64 0:0.4.11-11.el7 will be installed
--> Processing Dependency: libmodman.so.1()(64bit) for package: libproxy-0.4.11-11.el7.x86_64
---> Package pakchois.x86_64 0:0.4-10.el7 will be installed
--> Running transaction check
---> Package libmodman.x86_64 0:2.0.1-8.el7 will be installed
---> Package nettle.x86_64 0:2.7.1-8.el7 will be installed
---> Package trousers.x86_64 0:0.3.14-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================
 Package                         Arch                   Version                          Repository            Size
====================================================================================================================
Installing:
 subversion                      x86_64                 1.7.14-14.el7                    base                 1.0 M
Installing for dependencies:
 apr                             x86_64                 1.4.8-3.el7_4.1                  base                 103 k
 apr-util                        x86_64                 1.5.2-6.el7                      base                  92 k
 gnutls                          x86_64                 3.3.26-9.el7                     base                 677 k
 libmodman                       x86_64                 2.0.1-8.el7                      base                  28 k
 libproxy                        x86_64                 0.4.11-11.el7                    base                  64 k
 neon                            x86_64                 0.30.0-3.el7                     base                 165 k
 nettle                          x86_64                 2.7.1-8.el7                      base                 327 k
 pakchois                        x86_64                 0.4-10.el7                       base                  14 k
 subversion-libs                 x86_64                 1.7.14-14.el7                    base                 922 k
 trousers                        x86_64                 0.3.14-2.el7                     base                 289 k

Transaction Summary
====================================================================================================================
Install  1 Package (+10 Dependent packages)

Total download size: 3.6 M
Installed size: 12 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
apr-1.4.8-3.el7_4.1.x86_64.rpm FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/apr-1.4.8-3.el7_4.1.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
apr-util-1.5.2-6.el7.x86_64.rp FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/apr-util-1.5.2-6.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
gnutls-3.3.26-9.el7.x86_64.rpm FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/gnutls-3.3.26-9.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
libmodman-2.0.1-8.el7.x86_64.r FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/libmodman-2.0.1-8.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
libproxy-0.4.11-11.el7.x86_64. FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/libproxy-0.4.11-11.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
neon-0.30.0-3.el7.x86_64.rpm   FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/neon-0.30.0-3.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
nettle-2.7.1-8.el7.x86_64.rpm  FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/nettle-2.7.1-8.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
pakchois-0.4-10.el7.x86_64.rpm FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/pakchois-0.4-10.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
subversion-1.7.14-14.el7.x86_6 FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/subversion-1.7.14-14.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
subversion-libs-1.7.14-14.el7. FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/subversion-libs-1.7.14-14.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
trousers-0.3.14-2.el7.x86_64.r FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/trousers-0.3.14-2.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.


Error downloading packages:
  neon-0.30.0-3.el7.x86_64: [Errno 256] No more mirrors to try.
  trousers-0.3.14-2.el7.x86_64: [Errno 256] No more mirrors to try.
  libmodman-2.0.1-8.el7.x86_64: [Errno 256] No more mirrors to try.
  subversion-1.7.14-14.el7.x86_64: [Errno 256] No more mirrors to try.
  libproxy-0.4.11-11.el7.x86_64: [Errno 256] No more mirrors to try.
  pakchois-0.4-10.el7.x86_64: [Errno 256] No more mirrors to try.
  apr-1.4.8-3.el7_4.1.x86_64: [Errno 256] No more mirrors to try.
  nettle-2.7.1-8.el7.x86_64: [Errno 256] No more mirrors to try.
  gnutls-3.3.26-9.el7.x86_64: [Errno 256] No more mirrors to try.
  apr-util-1.5.2-6.el7.x86_64: [Errno 256] No more mirrors to try.
  subversion-libs-1.7.14-14.el7.x86_64: [Errno 256] No more mirrors to try.

经过查询资料得知,mirrors.cloud.aliyuncs.com是阿里云ECS VPC 用户专用的镜像源域名。
那不能说停就停吧?如果停了对阿里云上所有的ECS应该都会有很大影响。
然后换了另外一台阿里云的机器测试,发现另一台服务也是用的这个镜像源域名,但是却使用正常。

再排查机器配置,发现DNS不一样
问题机器的DNS是223.5.5.5223.6.6.6
正常机器的DNS是100.100.2.136100.100.2.138

最后修改DNS为正常机器的

# cat /etc/resolv.conf
nameserver 100.100.2.136
nameserver 100.100.2.138

再重新执行安装,就正常安装了

# yum install -y subversion
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package subversion.x86_64 0:1.7.14-14.el7 will be installed
--> Processing Dependency: subversion-libs(x86-64) = 1.7.14-14.el7 for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_wc-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_subr-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_repos-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_ra_svn-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_ra_neon-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_ra_local-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_ra-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_fs_util-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_fs_fs-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_fs_base-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_fs-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_diff-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_delta-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libsvn_client-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libneon.so.27()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: subversion-1.7.14-14.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package neon.x86_64 0:0.30.0-3.el7 will be installed
--> Processing Dependency: libgnutls.so.28(GNUTLS_2_12)(64bit) for package: neon-0.30.0-3.el7.x86_64
--> Processing Dependency: libgnutls.so.28(GNUTLS_1_4)(64bit) for package: neon-0.30.0-3.el7.x86_64
--> Processing Dependency: libproxy.so.1()(64bit) for package: neon-0.30.0-3.el7.x86_64
--> Processing Dependency: libpakchois.so.0()(64bit) for package: neon-0.30.0-3.el7.x86_64
--> Processing Dependency: libgnutls.so.28()(64bit) for package: neon-0.30.0-3.el7.x86_64
---> Package subversion-libs.x86_64 0:1.7.14-14.el7 will be installed
--> Running transaction check
---> Package gnutls.x86_64 0:3.3.29-9.el7_6 will be installed
--> Processing Dependency: trousers >= 0.3.11.2 for package: gnutls-3.3.29-9.el7_6.x86_64
--> Processing Dependency: libnettle.so.4()(64bit) for package: gnutls-3.3.29-9.el7_6.x86_64
--> Processing Dependency: libhogweed.so.2()(64bit) for package: gnutls-3.3.29-9.el7_6.x86_64
---> Package libproxy.x86_64 0:0.4.11-11.el7 will be installed
--> Processing Dependency: libmodman.so.1()(64bit) for package: libproxy-0.4.11-11.el7.x86_64
---> Package pakchois.x86_64 0:0.4-10.el7 will be installed
--> Running transaction check
---> Package libmodman.x86_64 0:2.0.1-8.el7 will be installed
---> Package nettle.x86_64 0:2.7.1-8.el7 will be installed
---> Package trousers.x86_64 0:0.3.14-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================
 Package                                   Arch                             Version                                    Repository                         Size
===============================================================================================================================================================
Installing:
 subversion                                x86_64                           1.7.14-14.el7                              base                              1.0 M
Installing for dependencies:
 apr                                       x86_64                           1.4.8-3.el7_4.1                            base                              103 k
 apr-util                                  x86_64                           1.5.2-6.el7                                base                               92 k
 gnutls                                    x86_64                           3.3.29-9.el7_6                             updates                           680 k
 libmodman                                 x86_64                           2.0.1-8.el7                                base                               28 k
 libproxy                                  x86_64                           0.4.11-11.el7                              base                               64 k
 neon                                      x86_64                           0.30.0-3.el7                               base                              165 k
 nettle                                    x86_64                           2.7.1-8.el7                                base                              327 k
 pakchois                                  x86_64                           0.4-10.el7                                 base                               14 k
 subversion-libs                           x86_64                           1.7.14-14.el7                              base                              922 k
 trousers                                  x86_64                           0.3.14-2.el7                               base                              289 k

Transaction Summary
===============================================================================================================================================================
Install  1 Package (+10 Dependent packages)

Total download size: 3.6 M
Installed size: 12 M
Downloading packages:
(1/11): apr-1.4.8-3.el7_4.1.x86_64.rpm                                                                                                  | 103 kB  00:00:00
(2/11): libmodman-2.0.1-8.el7.x86_64.rpm                                                                                                |  28 kB  00:00:00
(3/11): libproxy-0.4.11-11.el7.x86_64.rpm                                                                                               |  64 kB  00:00:00
(4/11): apr-util-1.5.2-6.el7.x86_64.rpm                                                                                                 |  92 kB  00:00:00
(5/11): neon-0.30.0-3.el7.x86_64.rpm                                                                                                    | 165 kB  00:00:00
(6/11): nettle-2.7.1-8.el7.x86_64.rpm                                                                                                   | 327 kB  00:00:00
(7/11): pakchois-0.4-10.el7.x86_64.rpm                                                                                                  |  14 kB  00:00:00
(8/11): gnutls-3.3.29-9.el7_6.x86_64.rpm                                                                                                | 680 kB  00:00:00
(9/11): subversion-1.7.14-14.el7.x86_64.rpm                                                                                             | 1.0 MB  00:00:00
(10/11): trousers-0.3.14-2.el7.x86_64.rpm                                                                                               | 289 kB  00:00:00
(11/11): subversion-libs-1.7.14-14.el7.x86_64.rpm                                                                                       | 922 kB  00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                           12 MB/s | 3.6 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : apr-1.4.8-3.el7_4.1.x86_64                                                                                                                 1/11
  Installing : apr-util-1.5.2-6.el7.x86_64                                                                                                                2/11
  Installing : pakchois-0.4-10.el7.x86_64                                                                                                                 3/11
  Installing : nettle-2.7.1-8.el7.x86_64                                                                                                                  4/11
  Installing : libmodman-2.0.1-8.el7.x86_64                                                                                                               5/11
  Installing : libproxy-0.4.11-11.el7.x86_64                                                                                                              6/11
  Installing : trousers-0.3.14-2.el7.x86_64                                                                                                               7/11
  Installing : gnutls-3.3.29-9.el7_6.x86_64                                                                                                               8/11
  Installing : neon-0.30.0-3.el7.x86_64                                                                                                                   9/11
  Installing : subversion-libs-1.7.14-14.el7.x86_64                                                                                                      10/11
  Installing : subversion-1.7.14-14.el7.x86_64                                                                                                           11/11
  Verifying  : trousers-0.3.14-2.el7.x86_64                                                                                                               1/11
  Verifying  : libmodman-2.0.1-8.el7.x86_64                                                                                                               2/11
  Verifying  : neon-0.30.0-3.el7.x86_64                                                                                                                   3/11
  Verifying  : subversion-1.7.14-14.el7.x86_64                                                                                                            4/11
  Verifying  : subversion-libs-1.7.14-14.el7.x86_64                                                                                                       5/11
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                                                                                                6/11
  Verifying  : nettle-2.7.1-8.el7.x86_64                                                                                                                  7/11
  Verifying  : pakchois-0.4-10.el7.x86_64                                                                                                                 8/11
  Verifying  : gnutls-3.3.29-9.el7_6.x86_64                                                                                                               9/11
  Verifying  : apr-1.4.8-3.el7_4.1.x86_64                                                                                                                10/11
  Verifying  : libproxy-0.4.11-11.el7.x86_64                                                                                                             11/11

Installed:
  subversion.x86_64 0:1.7.14-14.el7

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7_4.1                 apr-util.x86_64 0:1.5.2-6.el7        gnutls.x86_64 0:3.3.29-9.el7_6       libmodman.x86_64 0:2.0.1-8.el7
  libproxy.x86_64 0:0.4.11-11.el7              neon.x86_64 0:0.30.0-3.el7           nettle.x86_64 0:2.7.1-8.el7          pakchois.x86_64 0:0.4-10.el7
  subversion-libs.x86_64 0:1.7.14-14.el7       trousers.x86_64 0:0.3.14-2.el7

Complete!

一、检查是否已安装

# svnserve --version

如果出现下列提示,则代表没有安装

-bash: svnserve: command not found

如果出现下列提示,则代表已经安装了,直接跳到四步

svnserve, version 1.7.14 (r1542130)
   compiled Apr 11 2018, 02:40:28

Copyright (C) 2013 The Apache Software Foundation.
This software consists of contributions made by many people; see the NOTICE
file for more information.
Subversion is open source software, see http://subversion.apache.org/

The following repository back-end (FS) modules are available:

* fs_base : Module for working with a Berkeley DB repository.
* fs_fs : Module for working with a plain file (FSFS) repository.

Cyrus SASL authentication is available.

二、安装

# yum install -y subversion

三、再次检查是否已安装

# svnserve --version

四、创建并进入到储存版本库的目录

# mkdir /data/svn-repository
# cd /data/svn-repository

五、创建一个版本库(项目)
test为版本库的名称

# svnadmin create test

六、显示版本库目录的文件列表

# ls test
名称类型说明
conf目录配置文件目录
conf/authz文件负责账号权限的管理,控制账号是否读写权限
conf/passwd文件负责账号和密码的用户名单管理
conf/svnserve.conf文件版本库配置文件
db目录版本数据存储目录
hooks目录版本库钩子脚本文件目录
locks目录db锁文件和db_logs锁文件的目录,用来追踪存取文件库的客户端
format文件存储一个整数的文件,此整数代表库层次结构版本
README.txt文件说明文件

七、设置全局配置
默认情况下,都是使用版本库目录下conf目录的配置,一两个项目还没问他,但是项目一多,管理就很麻烦了。
先把配置目录复制出来,作为全局配置

# cp -R test/conf conf

八、新增该版本库的用户
打开passwd文件

# vi conf/passwd

在文件末新增一行,输入用户名jwj和密码123456

### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.

[users]
# harry = harryssecret
# sally = sallyssecret
jwj = qq2254

九、设置版本库用户的权限
打开authz文件

# vi conf/authz

jwj用户赋予test版本库根目录的读写权限

### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
###  - a single user,
###  - a group of users defined in a special [groups] section,
###  - an alias defined in a special [aliases] section,
###  - all authenticated users, using the '$authenticated' token,
###  - only anonymous users, using the '$anonymous' token,
###  - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').

[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average

[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe

# [/foo/bar]
# harry = rw
# &joe = r
# * =

# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

[test:/]
jwj = rw

当然,还有更多权限的写法,下面列出部分,想详细了解的话,请查阅其他资料

十、设置svn服务开机自启

#vi /etc/init.d/svn

然后输入以下内容

#!/bin/sh
# chkconfig: 2345 85 85
# processname: svn

svn_bin=/bin
svn_port=3690
svn_home=/mnt/svn-repository
svn_config=/mnt/svn-repository/conf/svnserve.conf

if [ ! -f "$svn_bin/svnserve" ]
then
    echo "svnserver startup: cannot start"
exit
fi

case "$1" in
    start)
        echo "Starting svnserve..."
        $svn_bin/svnserve -d -r $svn_home --config-file $svn_config --listen-port $svn_port
        echo "Successfully!"
    ;;
    stop)
        echo "Stoping svnserve..."
        killall svnserve
        echo "Successfully!"
    ;;
    restart)
        $0 stop
        $0 start
    ;;
    *)
        echo "Usage: svn { start | stop | restart } "
        exit 1
    ;;
esac

给文件添加可执行权限

# chmod +x /etc/init.d/svn

开启开机自启动

# chkconfig svn on

十一、启动svn

# service svn start