When connecting to a Microsoft SQL (MSSQL) server from a cPanel server, installing pdo_sqlsrv on the cPanel server is necessary. Several options exist to connect to SQL servers, but utilizing pdo_sqlsrv is perhaps the best option and has few requirements.
PDO_SQLSRV is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to MS SQL Server (starting with SQL Server 2005) and SQL Azure databases.
Here we cover the steps to install the pdo_sqlsrv extension on your VPS or dedicated server.
Related Articles
How to SSH into VPS or Dedicated Servers
Log into Root WHM Using AMP
Create phpinfo Page
Install Required Packages
NOTE: This extension is not available on our shared hosting platforms.
IMPORTANT: This solution will require root access. If this needs to be obtained, follow the guide on requesting root access.
- Access the server via SSH as the root user or using the Terminal in Root WHM
- Run the following command to install the required ODBC packages
yum -y install unixODBC unixODBC-devel
- Next, you can install the PHP extension via command line or through WHM
Install pdo_sqlsrv Extension via Command Line
- Access the server via SSH as the root user or using the Terminal in Root WHM
- Run the following command to install the sqlsrv extension
/opt/cpanel/ea-php##/root/usr/bin/pecl install sqlsrv
REPLACE: ## with the PHP version you want to use, without the "."
EXAMPLE: To install the extension for PHP 7.4, the command would be as follows:/opt/cpanel/ea-php74/root/usr/bin/pecl install sqlsrv
NOTE: The PECL sqlsrv and pdo_sqlsrv packages require PHP 7.3 or above by default. See the section at the end of this article for further instructions if using PHP 7.2 or below. - Install the PDO component
/opt/cpanel/ea-php##/root/usr/bin/pecl install pdo_sqlsrv
REPLACE: ## with the PHP version you want to use, without the "."
EXAMPLE: To install the extension for PHP 7.4, the command would be as follows:/opt/cpanel/ea-php74/root/usr/bin/pecl install pdo_sqlsrv
- Once complete, you can confirm the extension was installed successfully by using a phpinfo page or by running the following command:
/opt/cpanel/ea-php##/root/usr/bin/php -m |grep "sqlsrv"
REPLACE: ## with the PHP version you installed the extension for, without the "."
EXAMPLE: For PHP 7.4, the command would be as follows:/opt/cpanel/ea-php74/root/usr/bin/php -m |grep "sqlsrv"
- The output should appear similar to the following
root@vps80575 [/]# /opt/cpanel/ea-php74/root/usr/bin/php -m |grep "sqlsrv"
pdo_sqlsrv
sqlsrv
- The output should appear similar to the following
Install pdo_sqlsrv Extension in WHM
- Log into Root WHM
- Navigate to Software -> Module Installers
- Click Manage next to PHP PECL
- Select the applicable PHP version from the drop-down and click the Apply button
NOTE: The PECL sqlsrv and pdo_sqlsrv packages require PHP 7.3 or above by default. See the section at the end of this article for further instructions if using PHP 7.2 or below. - Enter "sqlsrv" in the search box then click the Go button
- Click Install next to the sqlsrv line
- Once complete, click Go Back at the bottom of the page
- Enter "pdo_sqlsrv" in the search box then click the Go button
- Click Install
- Once complete, you can confirm the extension was installed successfully using a phpinfo page or by running the following command
/opt/cpanel/ea-php##/root/usr/bin/php -m |grep "sqlsrv"
REPLACE: ## with the PHP version you installed the extension for, without the ".". For example, for PHP 7.4, the command would be as follows/opt/cpanel/ea-php74/root/usr/bin/php -m |grep "sqlsrv"
- The output should appear similar to the following
user@domain.com [/]# /opt/cpanel/ea-php74/root/usr/bin/php -m |grep "sqlsrv"
pdo_sqlsrv
sqlsrv
- The output should appear similar to the following
Install for PHP 7.1 or 7.2
NOTE: The PECL sqlsrv and pdo_sqlsrv packages require PHP 7.3 or above by default. This will cause the installation to fail if you try installing with an older PHP version. To work around this, you will either need to use a newer PHP version or install an older version of the extension following the below steps. This will only work for PHP 7.1 or 7.2. PHP 7.0 and below should not be used.
- Access the server via SSH as the root user or using the Terminal in Root WHM
- Run the following command to install the sqlsrv extension
/opt/cpanel/ea-php72/root/usr/bin/pecl install sqlsrv-5.6.1
REPLACE: "ea-php72" with "ea-php71" if installing for PHP 7.1. - Install the PDO component
/opt/cpanel/ea-php72/root/usr/bin/pecl install sqlsrv-5.6.1
REPLACE: "ea-php72" with "ea-php71" if installing for PHP 7.1. - Once complete, you can confirm the extension was installed successfully using a phpinfo page or by running the following command
/opt/cpanel/ea-php72/root/usr/bin/php -m |grep "sqlsrv"
REPLACE: "ea-php72" with "ea-php71" if you installed the extension for PHP 7.1.- The output should appear similar to the following
user@domain.com [/]# /opt/cpanel/ea-php72/root/usr/bin/php -m |grep "sqlsrv"
pdo_sqlsrv
sqlsrv
- The output should appear similar to the following
Comments
0 comments
Please sign in to leave a comment.