How to Install sqlsrv PHP extension via PECL for cPanel/Cyberpanel

In this guide, we will show you how to rapidly install sqlsrv PECL PHP Extension for PHP7.x series for cPanel and Cyberpanel.

Installing sqlsrv on PHP 7.0, 7.1, 7.2, 7.3 can be done via the below commands for cPanel Servers. It is a very similar process for Cyberpanel so skip to the bottom to see that process.

This is the all in one command set to do this for cPanel

yum -y install unixODBC unixODBC-devel ea-php*-php-odbc;
 yum install -y epel-release; sed -i "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel.repo; yum --disablerepo="*" --enablerepo="epel" install -y freetds
 for version in $(ls /opt/cpanel|grep ea-php); do /opt/cpanel/${version}/root/usr/bin/pecl channel-update pecl.php.net; done;
 for PHP in $(ls -h /opt/cpanel |grep ea-php); do printf '\n' |/opt/cpanel/$PHP/root/usr/bin/pecl install sqlsvr; done
 printf '\n' | /opt/cpanel/ea-php70/root/usr/bin/pecl install channel://pecl.php.net/sqlsrv-4.3.0
 printf '\n' | /opt/cpanel/ea-php71/root/usr/bin/pecl install channel://pecl.php.net/sqlsrv-4.3.0

If no errors you will want to restart the HTTP service after modules are installed to activate them.

systemctl restart httpd||service httpd restart 

This is the Guide for Cyberpanel

Here is how we can install the PECL extension for all 7.x versions for Cyberpanel lsphp.

yum -y install unixODBC unixODBC-devel freetds
for version in $(ls /usr/local/lsws|grep lsphp); do /usr/local/lsws/${version}/bin/pecl channel-update pecl.php.net; done
Extension="sqlsrv";for version in $(ls /usr/local/lsws|grep lsphp); do printf '\n' |/usr/local/lsws/${version}/bin/pecl install ${Extension} && echo "extension=${Extension}.so" >> /usr/local/lsws/${version}/etc/php.d/zzzzzzz-pecl.ini; done; printf '\n' |/usr/local/lsws/lsphp70/bin/pecl install channel://pecl.php.net/sqlsrv-4.3.0 && echo "extension=${Extension}.so" >> /usr/local/lsws/lsphp70/etc/php.d/zzzzzzz-pecl.ini;printf '\n' |/usr/local/lsws/lsphp71/bin/pecl install channel://pecl.php.net/sqlsrv-4.3.0 && echo "extension=${Extension}.so" >> /usr/local/lsws/lsphp71/etc/php.d/zzzzzzz-pecl.ini;systemctl restart lsws||service lsws restart; systemctl status lsws||service lsws status;

Please note the beauty of the above command is that it automatically adds the PHP extension to the ini file for each version for to its “zzzzzzz-pecl.ini”. The warning about the “You should add “extension=oauth.so” to php.ini” can be ignored. As this script handles it for you. If you do it manually without this script then that would be applicable.

Pecl update all Versions

for version in $(ls /usr/local/lsws|grep lsphp); do /usr/local/lsws/${version}/bin/pecl channel-update pecl.php.net; done
[root@server ~]# for version in $(ls /usr/local/lsws|grep lsphp); do /usr/local/lsws/${version}/bin/pecl channel-update pecl.php.net; done
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
[root@server ~]#

This command lets you check to see if all PHP versions show the module is installed.

for phpver in $(ls -1 /usr/local/lsws/ |grep lsphp | sed 's/lsphp//g') ; do echo ""; echo "LSPHP $phpver" ; /usr/local/lsws/lsphp$phpver/bin/php -m | grep -i sqlsrv; done
[root@server:~]# for phpver in $(ls -1 /usr/local/lsws/ |grep lsphp | sed 's/lsphp//g') ; do echo ""; echo "LSPHP $phpver" ; /usr/local/lsws/lsphp$phpver/bin/php -m | grep -i sqlsrv; done

LSPHP 70
sqlsrv

LSPHP 71
sqlsrv

LSPHP 72
sqlsrv

LSPHP 73
sqlsrv

LSPHP 74
sqlsrv
[root@server:~]#

Some screenshots of this on the Cyberpanel Server installation process.