How to Install the PHP SQLSRV Extension

回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

How to Install the PHP SQLSRV Extension

文章 yehlu »

https://serverpilot.io/docs/how-to-inst ... -extension

To install a PECL extension for multiple PHP versions, repeat the PECL extension installation for each PHP version.
The SQLSRV extension provides functions for accessing Microsoft SQL Server databases.

In late 2016, after more than four years of this extension not being updated, Microsoft began releasing updates to greatly improve this extension and add support for PHP 7. As of early 2017, this extension is now considered stable again.

This extension only supports PHP 7.0, 7.1, and 7.2. PHP 7.3 is not yet supported.

Additionally, this extension only supports Ubuntu 16.04 and 18.04. You will not be able to use this extension on Ubuntu 12.04 or 14.04.

You can follow Microsoft's work on this extension through the PHP SQL Server Team blog.

Installing the SQLSRV Extension on PHP 7.X
In the examples shown, replace "7.X" with your app's PHP version (for example, "7.0").
To install the PHP SQLSRV extension, SSH in to your server as root and run the following commands to install prerequisites:

On Ubuntu 16.04

curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo bash -c "curl -s https://packages.microsoft.com/config/u ... /prod.list > /etc/apt/sources.list.d/mssql-release.list"
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools
sudo apt-get -y install unixodbc-dev
On Ubuntu 18.04

curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo bash -c "curl -s https://packages.microsoft.com/config/u ... /prod.list > /etc/apt/sources.list.d/mssql-release.list"
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools
sudo apt-get -y install unixodbc-dev
Next, run the following commands to install the extension:

sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config
sudo pecl7.X-sp install sqlsrv
sudo pecl7.X-sp install pdo_sqlsrv
Once installed, create configuration files for the extension and restart PHP by running the following commands as root:

sudo bash -c "echo extension=sqlsrv.so > /etc/php7.X-sp/conf.d/sqlsrv.ini"
sudo bash -c "echo extension=pdo_sqlsrv.so > /etc/php7.X-sp/conf.d/pdo_sqlsrv.ini"
sudo service php7.X-fpm-sp restart
Possible Errors
If you get the following error while installing prerequisites using the instructions above:

Installation Failed, ODBC Driver 13 for SQL Server Detected!
this may be caused by a previous installation of Microsoft's msodbcsql package while the new SQLSRV driver was still in development and not yet released. In this case, the solution is to start over with a clean Ubuntu 16.04 server, connect it to ServerPilot, and follow the PHP SQLSRV extension installation steps again on the new server.

Installing the SQLSRV Extension on PHP 5.X
This extension no longer supports PHP 5.X.

Verifying the Installation
You can verify the SQLSRV extension is installed with the command:

php7.X-sp -i | grep -i sqlsrv
If SQLSRV is installed correctly, you will see the following:

/etc/php7.1-sp/conf.d/pdo_sqlsrv.ini,
/etc/php7.1-sp/conf.d/sqlsrv.ini,
Registered PHP Streams => https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, zip, phar, sqlsrv
PDO drivers => dblib, mysql, odbc, pgsql, sqlite, sqlsrv
pdo_sqlsrv
pdo_sqlsrv support => enabled
pdo_sqlsrv.client_buffer_max_kb_size => 10240 => 10240
pdo_sqlsrv.log_severity => 0 => 0
sqlsrv
sqlsrv support => enabled
sqlsrv.ClientBufferMaxKBSize => 10240 => 10240
sqlsrv.LogSeverity => 0 => 0
sqlsrv.LogSubsystems => 0 => 0
sqlsrv.WarningsReturnAsErrors => On => On
Uninstalling the SQLSRV Extension
To uninstall this extension, as root run the commands:

sudo rm /etc/phpX.Y-sp/conf.d/sqlsrv.ini
sudo rm /etc/phpX.Y-sp/conf.d/pdo_sqlsrv.ini
sudo peclX.Y-sp uninstall sqlsrv
sudo peclX.Y-sp uninstall pdo_sqlsrv
Next, restart PHP-FPM with the command:

sudo service phpX.Y-fpm-sp restart
Using the PHP SQLSRV Extension
See the extension's GitHub page for an example of how to use the extension.

Note that the MSDN Online Documentation for this extension has not yet been updated for PHP 7.
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

sudo: pecl7.2-sp: command not found

文章 yehlu »

https://stackoverflow.com/questions/520 ... -not-found

2

I am on ubuntu 16:04 and the following got it working for me (more or less):

Run the following command:

代碼: 選擇全部

sudo apt-get install php-pear php-dev
Now you can run the command pecl instead pecl7.2-sp - seems to work fine though:

代碼: 選擇全部

sudo pecl install geoip-beta
Hope that helps.
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS

文章 yehlu »

https://docs.microsoft.com/zh-tw/sql/co ... erver-2017
https://docs.microsoft.com/zh-tw/sql/co ... 4-and-1810

代碼: 選擇全部

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
#Ubuntu 18.04
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev
回覆文章

回到「PHP」