I recently needed to access a SQL Server from PHP for a project I was working on, after some online research, I was able to get the extension up & running on the server.
These are the steps I took to get it setup:
First things first, I started by installing some default packages in addition to Apache2 and the latest PHP version available (in this case, it defaulted to PHP 7.2):
sudo apt-get install vim curl git zip unzip htop apache2 php libapache2-mod-php php-mysql
I then found this online tutorial, How to Install the PHP SQLSRV Extension, that got me started:
curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo bash -c "curl -s https://packages.microsoft.com/config/ubuntu/18.04/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
however, the pecl7.X-sp command didn’t worked, so after some more online research, found the way to make it work:
sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config
sudo apt-get install php-pear php-dev
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
at this point, I had the extension built and ready to go, I then proceeded to create the necessary .ini files so that PHP can pick it up:
sudo bash -c "echo extension=sqlsrv.so > /etc/php/7.2/mods-available/sqlsrv.ini"
sudo ln -s /etc/php/7.2/mods-available/sqlsrv.ini /etc/php/7.2/apache2/conf.d/sqlsrv.ini
sudo ln -s /etc/php/7.2/mods-available/sqlsrv.ini /etc/php/7.2/cli/conf.d/sqlsrv.ini
sudo bash -c "echo extension=pdo_sqlsrv.so > /etc/php/7.2/mods-available/pdo_sqlsrv.ini"
sudo ln -s /etc/php/7.2/mods-available/pdo_sqlsrv.ini /etc/php/7.2/apache2/conf.d/pdo_sqlsrv.ini
sudo ln -s /etc/php/7.2/mods-available/pdo_sqlsrv.ini /etc/php/7.2/cli/conf.d/pdo_sqlsrv.ini
and final step, was to restart Apache2:
sudo systemctl restart apache2
and we are good to go!



ismail says:
frm@frm-linux:~$ sudo pecl install sqlsrv
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Notice: Trying to access array offset on value of type null in Role.php on line 250
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 250
Notice: Trying to access array offset on value of type null in Role.php on line 251
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 251
Notice: Trying to access array offset on value of type null in Role.php on line 250
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 250
Notice: Trying to access array offset on value of type null in Role.php on line 251
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 251
Notice: Trying to access array offset on value of type null in Role.php on line 250
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 250
Notice: Trying to access array offset on value of type null in Role.php on line 251
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 251
Notice: Trying to access array offset on value of type null in Role.php on line 250
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 250
Notice: Trying to access array offset on value of type null in Role.php on line 251
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 251
Notice: Trying to access array offset on value of type null in Role.php on line 250
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 250
Notice: Trying to access array offset on value of type null in Role.php on line 251
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 251
Notice: Trying to access array offset on value of type null in Role.php on line 250
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 250
Notice: Trying to access array offset on value of type null in Role.php on line 251
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 251
Notice: Trying to access array offset on value of type null in Role.php on line 250
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 250
Notice: Trying to access array offset on value of type null in Role.php on line 251
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 251
Notice: Trying to access array offset on value of type null in Role.php on line 250
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 250
Notice: Trying to access array offset on value of type null in Role.php on line 251
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 251
Notice: Trying to access array offset on value of type null in Role.php on line 250
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 250
Notice: Trying to access array offset on value of type null in Role.php on line 251
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 251
Notice: Trying to access array offset on value of type null in Role.php on line 250
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 250
Notice: Trying to access array offset on value of type null in Role.php on line 251
PHP Notice: Trying to access array offset on value of type null in /usr/share/php/PEAR/Installer/Role.php on line 251
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
PHP Notice: Undefined index: honorsbaseinstall in /usr/share/php/PEAR/Installer/Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
PHP Notice: Undefined index: honorsbaseinstall in /usr/share/php/PEAR/Installer/Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
PHP Notice: Undefined index: honorsbaseinstall in /usr/share/php/PEAR/Installer/Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
PHP Notice: Undefined index: honorsbaseinstall in /usr/share/php/PEAR/Installer/Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
PHP Notice: Undefined index: honorsbaseinstall in /usr/share/php/PEAR/Installer/Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
PHP Notice: Undefined index: honorsbaseinstall in /usr/share/php/PEAR/Installer/Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
PHP Notice: Undefined index: honorsbaseinstall in /usr/share/php/PEAR/Installer/Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
PHP Notice: Undefined index: honorsbaseinstall in /usr/share/php/PEAR/Installer/Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
PHP Notice: Undefined index: honorsbaseinstall in /usr/share/php/PEAR/Installer/Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
PHP Notice: Undefined index: honorsbaseinstall in /usr/share/php/PEAR/Installer/Role.php on line 173
Notice: Undefined index: installable in Role.php on line 139
PHP Notice: Undefined index: installable in /usr/share/php/PEAR/Installer/Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
PHP Notice: Undefined index: installable in /usr/share/php/PEAR/Installer/Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
PHP Notice: Undefined index: installable in /usr/share/php/PEAR/Installer/Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
PHP Notice: Undefined index: installable in /usr/share/php/PEAR/Installer/Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
PHP Notice: Undefined index: installable in /usr/share/php/PEAR/Installer/Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
PHP Notice: Undefined index: installable in /usr/share/php/PEAR/Installer/Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
PHP Notice: Undefined index: installable in /usr/share/php/PEAR/Installer/Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
PHP Notice: Undefined index: installable in /usr/share/php/PEAR/Installer/Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
PHP Notice: Undefined index: installable in /usr/share/php/PEAR/Installer/Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
PHP Notice: Undefined index: installable in /usr/share/php/PEAR/Installer/Role.php on line 139
Notice: Undefined index: phpfile in Role.php on line 204
PHP Notice: Undefined index: phpfile in /usr/share/php/PEAR/Installer/Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
PHP Notice: Undefined index: phpfile in /usr/share/php/PEAR/Installer/Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
PHP Notice: Undefined index: phpfile in /usr/share/php/PEAR/Installer/Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
PHP Notice: Undefined index: phpfile in /usr/share/php/PEAR/Installer/Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
PHP Notice: Undefined index: phpfile in /usr/share/php/PEAR/Installer/Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
PHP Notice: Undefined index: phpfile in /usr/share/php/PEAR/Installer/Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
PHP Notice: Undefined index: phpfile in /usr/share/php/PEAR/Installer/Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
PHP Notice: Undefined index: phpfile in /usr/share/php/PEAR/Installer/Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
PHP Notice: Undefined index: phpfile in /usr/share/php/PEAR/Installer/Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
PHP Notice: Undefined index: phpfile in /usr/share/php/PEAR/Installer/Role.php on line 204
Notice: Undefined index: config_vars in Role.php on line 46
PHP Notice: Undefined index: config_vars in /usr/share/php/PEAR/Installer/Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
PHP Notice: Undefined index: config_vars in /usr/share/php/PEAR/Installer/Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
PHP Notice: Undefined index: config_vars in /usr/share/php/PEAR/Installer/Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
PHP Notice: Undefined index: config_vars in /usr/share/php/PEAR/Installer/Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
PHP Notice: Undefined index: config_vars in /usr/share/php/PEAR/Installer/Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
PHP Notice: Undefined index: config_vars in /usr/share/php/PEAR/Installer/Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
PHP Notice: Undefined index: config_vars in /usr/share/php/PEAR/Installer/Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
PHP Notice: Undefined index: config_vars in /usr/share/php/PEAR/Installer/Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
PHP Notice: Undefined index: config_vars in /usr/share/php/PEAR/Installer/Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
PHP Notice: Undefined index: config_vars in /usr/share/php/PEAR/Installer/Role.php on line 46
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
XML Extension not found
Bjoern says:
try this:
sudo apt-get install php7.2-xml
ckryger says:
Worked like a charm. Thank you for sharing this!
Abd Blr says:
I highly appreciate, this saved me a huge load of work!
confused programmer says:
thanks a lot