Question
How to install PDO_SQLSRV to connect to a Microsoft SQL Server?
Answer
When connecting to a Microsoft SQL server, installing pdo_sqlsrv is necessary for PHP to communicate with this third-party SQL service. Several options exist to connect to SQL servers, but utilizing pdo_sqlsrv is the best option.
Note: PDO_SQLSRV requires PHP 8.0 or newer. Please note that this is a task that an administrator should perform to avoid conflicts and issues. Manually attempting to install any package or related functionality may result in a conflict that needs to be addressed by an administrator before a successful installation is achieved.
- Access the server's command line as the
rootuser via SSH or in WHM via Home /
Server Configuration / Terminal. -
Install the Microsoft SQL Driver using Microsoft's documentation.
Microsoft Docs: Installing the Microsoft SQL Driver for Linux
-
Install the following packages.
# dnf install gcc-c++ libtool-ltdl-devel unixODBC-devel -y
Note: If users need access to ODBC commands within CloudLinux CageFS, you must add the RPMs to CageFS.
-
Install the
sqlsrvpackage.Note: The exec function must not be disabled for the PHP version you are installing this on. If exec is present in the disable_functions setting you will need to remove it using the WHM MultiPHP Manager interface.
# /usr/bin/ea-php8#-pecl install sqlsrv
Note: Please replace "#" with the PHP version for which the package is being installed. Please note that for PHP 8.0,
sqlsrvmust be replaced withsqlsrv-5.11.0. -
Install the
pdo_sqlsrvPECL package.# /usr/bin/ea-php8#-pecl install pdo_sqlsrv
Note: Please replace "#" with the PHP version for which the package is being installed. Please note that for PHP 8.0,
pdo_sqlsrvmust be replaced withpdo_sqlsrv-5.11.0. -
Finally, you can check that the modules installed successfully with a command like this
# /usr/bin/ea-php8# -m | grep sqlsrv
- Access the server's command line as the
rootuser via SSH or in WHM via Home /
Server Configuration / Terminal. -
Install the Microsoft SQL Driver using Microsoft's documentation.
Microsoft Docs: Installing the Microsoft SQL Driver for Ubuntu
-
Install the following packages.
# apt install g++ libltdl-dev unixodbc-dev -y
Note: If users need access to ODBC commands within CloudLinux CageFS, you must add the RPMs to CageFS.
-
Install the
sqlsrvpackage.Note: The exec function must not be disabled for the PHP version you are installing this on. If exec is present in the disable_functions setting you will need to remove it using the WHM MultiPHP Manager interface.
# /usr/bin/ea-php8#-pecl install sqlsrv
Note: Please replace "#" with the PHP version for which the package is being installed. Please note that for PHP 8.0,
sqlsrvmust be replaced withsqlsrv-5.11.0. -
Install the
pdo_sqlsrvPECL package.# /usr/bin/ea-php8#-pecl install pdo_sqlsrv
Note: Please replace "#" with the PHP version for which the package is being installed. Please note that for PHP 8.0,
pdo_sqlsrvmust be replaced withpdo_sqlsrv-5.11.0. -
Finally, you can check that the modules installed successfully with a command like this
# /usr/bin/ea-php8# -m | grep sqlsrv
Additional resources
How to add a command or binary to CageFS for all users using addrpm
How to install PHP extensions using PECL using WHM
How To Enable A Particular PHP Extension For A Cloudlinux ALT-PHP## Installation?
Comments
0 comments
Article is closed for comments.