How to install MSSQL extension for PHP 5.6 on CentOS 7

background

I wrote an article two days ago on  how to install MSSQL extensions for PHP 5.6 in OSX MAMP . It is  about how to  install  extensions for your personal computer, that is, how to PHP 5.6 install the  MSSQLextensions in the development environment  . Now it's going to be in production, and I will continue to talk about how to  CentOS7install  PHP - MSSQLextensions.

Operating environment

operating system

  • CentOS Linux release 7.8.2003 (Core)

Integrated environment

  • pagoda

  • PHP 5.6.40

step

As before, let’s sort out the overall steps first:

1. Install  freetds
2. Install the  mssql.so extension ( php the  mssql extension depends on  freetds)

Overall  OSX , the steps to install the extension are the same.

detailed steps

1. Download freetds

Execute the following scripts in sequence:

cd /usr/local/src/
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz
tar -zxvf freetds-patched.tar.gz123

That is, enter the  /usr/local/src directory (I usually put the source code used for compilation here), download  freetds the source code, and then unzip it.

2. Installation freetds

Execute the following scripts in sequence:

cd freetds-1.2/
./configure --prefix=/usr/local/freetds --with-tdsver=7.4 --enable-msdblib
make && make install123

Pay attention to the above  freetds-1.2, depending on the different freetds versions you downloaded  , here may be different, anyway, just enter the folder you unzipped. Then  --with-tdsver=7.4 here, SqlServer you can choose flexibly according to  the different versions. For details, you can refer to the following figure to choose by yourself. I am using  SqlServer 2012, so the selected  7.4 version:

Insert picture description here

The selected content of the above version comes from  freetds the official document, document address: https://www.freetds.org/userguide/ChoosingTdsProtocol.html

3. Configuration freetds

Execute the following commands in sequence to initialize the  freetds configuration:

echo "/usr/local/freetds/lib/" > /etc/ld.so.conf.d/freetds.conf
ldconfig12

No other configuration is needed. There are some tutorials on the Internet to write  the connection information to  freetds.conf be configured  MSSQLin. In fact, you don't need to, you can configure it when you call it, that is PHP , configure it in the code , which is  so flexible.

4. Test freetds

Execute the following command to view the  freetds version:

# /usr/local/freetds/bin/tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v1.2
             freetds.conf directory: /usr/local/freetds/etc
     MS db-lib source compatibility: yes
        Sybase binary compatibility: no
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 7.4
                              iODBC: no
                           unixodbc: no
              SSPI "trusted" logins: no
                           Kerberos: no
                            OpenSSL: yes
                             GnuTLS: no
                               MARS: yes12345678910111213141516

Execute the following command to test the  freetds connection:

# /usr/local/freetds/bin/tsql -H example.com -p 1433 -U username -P password
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> select @@version
2> go

Microsoft SQL Server 2012 - 11.0.2100.60 (X64)
	Feb 10 2012 19:39:15
	Copyright (c) Microsoft Corporation
	Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)

(1 row affected)12345678910111213

Where  example.com is  MSSQL the  host address,  username and  password is  MSSQL the username and password respectively.

5. Download the  PHP-5.6.40 source code

Execute the following scripts in sequence:

cd /usr/local/src/
wget https://www.php.net/distributions/php-5.6.40.tar.gz
tar -zxvf php-5.6.40.tar.gz123

It is the freetds same as the download above  , so I won't repeat it here.

6. Install the  PHP-5.6.40-MSSQL extension

Execute the following scripts in sequence:

cd php-5.6.40/ext/mssql/
/www/server/php/56/bin/phpize
./configure --with-php-config=/www/server/php/56/bin/php-config --with-mssql=/usr/local/freetds/
make && make install1234

The above  /www/server/php/56/bin/ path, because the php installation path used in the pagoda  is this, so the path is written like this, and you can adjust it according to your own situation.

Get output similar to the following, indicating that the extension installation is complete:

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

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

7. Modify php.ini

You can modify it at will, I just used the front end of the pagoda to modify it directly, without using the command line. In  php.ini the Add the following lines:

[mssql]
extension=mssql.so12

Save after modification, and then restart the  php service.

Check  phpinfo, you can see that the  mssql extension has been enabled.

Insert picture description here

That's it.

Guess you like

Origin blog.csdn.net/zl17822307869/article/details/113875235