The method of adding the PHP extension Module MSSQL in CENTOS6

Source: Internet
Author: User
Tags bz2 install php microsoft sql server mssql php and phpinfo zts iptables
If you need to use PHP to connect to a Microsoft SQL Server 2005 database on a Linux system, our common way to connect to a database is to use ODBC to connect.
FreeTDS provides an open source client for the TDS protocol for Linux systems. Because MSSQL and Sybase use the TDS protocol, you can use FreeTDS to connect MSSQL in Linux, and the following Jinschau use PHP's db-lib to connect to a Microsoft SQL Server 2005 database.
Linux operating system: centOS6.3 64bit (Installation of the system default development package)
apache:httpd-2.4.4
php:php-5.4.13
freetds:freetds-0.91
I. Closing iptables and SELinux
The code is as follows Copy Code
# Service Iptables Stop
# Setenforce 0
# Vi/etc/sysconfig/selinux
---------------
Selinux=disabled
---------------
Two. Sync time
The code is as follows Copy Code
# ntpdate Cn.pool.ntp.org
I. Installation of apache+php
Transmission door: HTTP://WWW.SHOWERLEE.COM/ARCHIVES/6
Two. Use FreeTDS to enable PHP connection MSSQL
1. Download FreeTDS
The code is as follows Copy Code
# Su-
# wget Ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz
2. Install FreeTDS
The code is as follows Copy Code
# TAR-ZXVF Freetds-stable.tgz
# CD freetds-0.91
#./configure--prefix=/usr/local/freetds--with-tdsver=8.0--enable-msdblib--enable-dbmfix--with-gnu-ld-- Enable-shared--enable-static
# Make && make install
3. Enable PHP connection MSSQL
Method one: Compile PHP plus FreeTDS path (initial deployment recommended)
  code is as follows copy code
# wget HTTP://CN2.PHP.NET/DISTRIBUTIONS/PHP-5.4.13.TAR.BZ2
# TAR-JXVF PHP-5.4.13.TAR.BZ2
# CD php-5.4.13
#./configure--prefix=/usr/local/php5--with-apxs2=/usr/local/apache2/bin/apxs--with-libxml-dir=/usr/local/lib-- With-zlib-dir=/usr/local/lib--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config-- WITH-GD--enable-soap--enable-sockets--enable-xml--enable-mbstring--with-png-dir=/usr/local /local--with-curl=/usr/lib--with-freetype-dir=/usr/include/freetype2/freetype/--enable-bcmath--enable-calendar --enable-zip--enable-maintainer-zts--with-mssql=/usr/local/freetds
# Make && make install
Method Two: Compile the MSSQL Extension of PHP and add the FreeTDS path (two deployment recommendations)
The code is as follows Copy Code
# wget HTTP://CN2.PHP.NET/DISTRIBUTIONS/PHP-5.4.13.TAR.BZ2
# TAR-JXVF PHP-5.4.13.TAR.BZ2
# CD Php-5.4.13/ext/mssql
#/usr/local/php/bin/phpize
#./configure--with-php-config=/usr/local/php/bin/php-config--with-mssql=/usr/local/freetds
# Make && make install
After installation, follow the instructions for compiling the installation
The mssql.so module is saved by default in the/usr/local/php5/lib/php/extensions/no-debug-zts-20090626/directory
Load the module into PHP
The code is as follows Copy Code
# Vi/usr/local/php5/lib/php.ini
Add the following line:
Extension = "/usr/local/php5/lib/php/extensions/no-debug-zts-20090626/mssql.so"
Restart Apache:
#/usr/local/apache2/bin/apachectl Restart
Note: If the FreeTDS directory cannot be found when compiling PHP load FreeTDS, the following actions are required (official FAQ)
# Touch/usr/local/freetds/include/tds.h
# TOUCH/USR/LOCAL/FREETDS/LIB/LIBTDS.A
4. Add phpinfo function, test page
Add the following info.php to/usr/local/apache2/htdocs/to test whether the PHP module is loaded.
The code is as follows Copy Code
# vi/usr/local/apache2/htdocs/info.php
---------------
<?php
Echo Phpinfo ();
?>
---------------
Check if port 80 is open
# lsof-i:80
Browser input http://localhost/info.php
Shows the following test page content, the Mssql.so module is loaded successfully under PHP

5. Database Connection Test page:
Assume that the MSSQL database IP is 192.168.100.10, the port is 1433, and the Administrator account password is "sa"
# vi/usr/local/apache2/htdocs/test_mssql_conn.php
---------------------------------------------
The code is as follows Copy Code
<?php
if (Mssql_connect (' 192.168.100.10,1433 ', ' sa ', ' sa ')) {
echo "Success";
}
else {
echo "Failed";
}
?>
---------------------------------------------
Browser input http://localhost/test_mssql_conn.php
Test the final connection status.
Done....
PostScript: If some friends use Yum installed lamp environment, then later need to add the MSSQL module to PHP.
Deployment methods:
# yum Install Php-mssql-y
# Service httpd Restart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.