This article describes how to install PHPMSSQL extension in Linux. the environment in this article is SUSELinuxEnterpriseServer10SP3. Other systems are similar. if you need it, you can refer to PHP to provide excellent support for MySQL, however, it takes some time to operate SQL Server using PHP. Today, a project in the team needs to use PHP to operate SQL Server, so we can help you configure the environment.
The system version of the Server is SUSE Linux Enterprise Server 10 SP3.
1. install FreeTDS
Address: FreeTDS
The code is as follows:
Wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
Tar zxvf freetds-stable.tgz
Cd freetds-0.82
./Configure -- prefix =/usr/local/freetds -- with-tdsver = 8.0 -- enable-msdblib -- enable-dbmfix
Make & make install
After successful installation, it is best to update the dynamic connection library cache:
The code is as follows:
Echo "/usr/local/freetds/lib">/etc/ld. so. conf
Ldconfig
2. configure FreeTDS and test the connection
The configuration file of FreeTDS is placed in The etc directory of the installation directory. according To The configure parameter in step 1, we install FreeTDS in/usr/local/freetds:
The code is as follows:
Vim/usr/local/freetds/etc/freetds. conf
It is not clear which configuration items of FreeTDS can be used here, but an important configuration is provided to solve Chinese garbled characters. Add the following statement to the configuration file:
The code is as follows:
Client charset = utf8
Then, we use the tsql command to test whether the database can be connected to the SQL Server database normally:
The code is as follows:
Cd/usr/local/freetds/bin
./Tsql-H 192.168.0.254-p 1433-U sa-P 123456
If the connection is normal, the following statement should be displayed:
The code is as follows:
Locale is "zh_CN.UTF-8"
Locale charset is "UTF-8"
1>
3. install mssql extension for php
The php version on the server is 5.3.13. php has been installed in/usr/local/services/php, and the extended directory is/usr/local/services/php/extensions. The following describes how to install the mssql extension:
The code is as follows:
Cd php-5.3.13/ext/mssql/
/Usr/local/services/php/bin/phpize
./Configure -- with-php-config =/usr/local/services/php/bin/php-config -- with-mssql =/usr/local/freetds
Make # generate the extension file and place it in the module folder of the current directory.
Cp modules/mssql. so/usr/local/services/php/extensions/# Copy the extension file to the extension directory of PHP
4. configure php. ini and verify the installation result.
Open php. ini and add the following extension statement:
The code is as follows:
Extension = mssql. so
After the PHP service is restarted (php-fpm is used on the Server), print phpinfo. the following configuration indicates that php can operate SQL Server normally.