Update the installed packages.
apt update
Install the Ondřej PHP repository.
apt install software-properties-commonsudo
add-apt-repository ppa:ondrej/php
apt update
Check that the repositories are correctly installed.
grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/*
In this case, PHP 7.0 and 7.1 will be installed.
# PHP 7.0
apt-get install php7.0 php7.0-dev php7.0-cli
# PHP 7.1
apt-get install php7.1 php7.1-dev php7.1-cli
apt-get install php-pear
pecl channel-update pecl.php.net
Set which version to use when compiling the extensions.
# PHP 7.0
pear config-set php_bin "/usr/lib/cgi-bin/php7.0"
# PHP 7.1
pear config-set php_bin "/usr/lib/cgi-bin/php7.1"
Force an upgrade to save changes.
pear upgrade --force
# Debian
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version
#Debian 8
curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list
#Debian 9
curl https://packages.microsoft.com/config/debian/9/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
# Ubuntu
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version
#Ubuntu 14.04
curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
#Ubuntu 16.04
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
#Ubuntu 18.04
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
#Ubuntu 18.10
curl https://packages.microsoft.com/config/ubuntu/18.10/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
Use the following command to choose the PHP version to be used as an alternative.
update-alternatives --config php-config
pecl install pdo_sqlsrv
pecl install sqlsrv
Use the following command to find where the extension was installed.
pear config-show | grep ext_dir
If necessary, move the extension to the correct PHP extension folder and add the extension to the corresponding php.ini file.
extension=sqlsrv.so
extension=pdo_sqlsrv.so
# PHP 7.0
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.0/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.0/mods-available/pdo_sqlsrv.ini
phpenmod -v 7.0 sqlsrv pdo_sqlsrv
# PHP 7.1
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.1/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.1/mods-available/pdo_sqlsrv.ini
phpenmod -v 7.1 sqlsrv pdo_sqlsrv
/etc/init.d/apache2 reload