参照: 基于Linux下PHP连接SQL Server的FreeTDS配置
使用phpize建立php扩展 Cannot find config.m4.
注:php安装地方 /usr/local/php
php源码包 /usr/local/src/php-4.3.5
FreeTDs下载http://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
1、编译安装FreeTDS
tar zxvf freetds-stable.tgz cd freetds-0.91 ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib make make install echo "/usr/local/freetds/lib/" > /etc/ld.so.conf.d/freetds.conf ln -s /usr/local/freetds/lib/libsybdb.so.5.0.0 /usr/local/freetds/lib/libsybdb.so.4 /sbin/ldconfig cd /usr/local/freetds/etc cp freetds.conf freetds.conf.bak vi freetds.conf
修改freetds.conf
[global] # TDS protocol version ; tds version = 4.2 # Whether to write a TDSDUMP file for diagnostic purposes # (setting this to /tmp is insecure on a multi-user system) ; dump file = /tmp/freetds.log ; debug flags = 0xffff # Command and connection timeouts ; timeout = 10 ; connect timeout = 10 # If you get out-of-memory errors, it may mean that your client # is trying to allocate a huge buffer for a TEXT field. # Try setting 'text size' to a more reasonable limit text size = 64512 host = mssql.yourdomain.com port = 1433 tds version = 8.0 client charset = UTF-8
2、配置phpize
由于运行/usr/local/php/bin/phpize时报以下的错,所以要配置一下phpize。如果运行phpize不报错,则直接跳至3
[root@ns root]# /usr/local/php/bin/phpize
Cannot find config.m4.
Make sure that you run /usr/local/bin/phpize in the top level source directory of the module
解决方法
cd /usr/local/src/php-4.3.5/ext/ ./ext_skel --extname=sdomain cd sdomain/ vi config.m4
2.1、修改config.m4
将
dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support, dnl Make sure that the comment is aligned: dnl [ --enable-my_module Enable my_module support])
PHP_ARG_ENABLE(my_module, whether to enable my_module support, [ --enable-my_module Enable my_module support])
2.2、修改sdomain.c
将其中的代码修改成
function_entry my_module_functions[] = { PHP_FE(say_hello, NULL) /* 添加这一行代码 */ PHP_FE(confirm_my_module_compiled, NULL) /* For testing, remove later. */ {NULL, NULL, NULL} /* Must be the last line in my_module_functions[] */ };
在文件最后添加
PHP_FUNCTION(say_hello) { zend_printf("hello sdomain!"); }
2.3 修改php_sdomain.h
PHP_FUNCTION(confirm_my_module_compiled ); /* For testing, remove later. */ /*这行的下面添加一行*/ PHP_FUNCTION(say_hello); /* For testing, remove later. */
2.4运行phpize
[root@ns sdomain]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20020918
Zend Module Api No: 20020429
Zend Extension Api No: 20050606
出现以上信息,则配置成功啦!
3、重新编译PHP,使用phpize会保留以前的配置
先确保php.ini里的extension_dir="/usr/local/php/ext",如果不先设置它的扩展路径的话,重新编译不会把mssql.so放到/usr/local/php/ext下的。当然,你不设置也可以。make install时,它会提示扩展放到那里去了。
cd /usr/local/src/php-4.3.5/ext/mssql/ /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-mssql=/usr/local/webserver/freetds/ make make install
在php.ini增加一行extension = "mssql.so"
4、重启PHP FastCGI, 用phpinfo();查看一下如果看见mssql模块就成功了。