How to install PDO SQLSRV extension on RunCloud Nginx server | PHP 8.1

How to install PDO SQLSRV extension on RunCloud Nginx server | PHP 8.1

Installing PDO_SQLSRV Extension on a RunCloud Nginx Server with PHP 8.1

If you're running a RunCloud Nginx server with PHP 8.1 and need to install the latest stable version of the PDO_SQLSRV extension, this guide will walk you through the process step by step. It's important to note that in order for the extension to work properly, you'll also need to install the ODBC drivers. Let's get started!

For installing SQLSRV extension refer : Installing PHP SQLSRV Extension - RunCloud Nginx (linuxtutorialz.co.uk)

Prerequisites

Before we begin, for this tutorial we are using PHP81 and extension version as '5.9.0' however you can replace these as per your requirements. The "unixodbc-dev" package is for unixODBC development headers. Make sure you have the following packages installed on your server:

apt-get install autoconf libpcre3-dev apt-get install unixodbc-dev

Downloading the Extension

First, we need to download the PDO_SQLSRV extension. Execute the following commands to download and extract the extension:

MODULE_NAME="pdo_sqlsrv" 
MODULE_VERSION="5.10.0" 
wget https://pecl.php.net/get/$MODULE_NAME-$MODULE_VERSION.tgz 
tar -zxvf $MODULE_NAME-$MODULE_VERSION.tgz

Installing the Extension

Once the extension is downloaded, we can proceed with the installation. Change to the extracted extension directory by running:

cd $MODULE_NAME-$MODULE_VERSION

Next, clean the PHPize files and run PHPize to prepare the extension for installation:

/RunCloud/Packages/php81rc/bin/phpize --clean /RunCloud/Packages/php81rc/bin/phpize

Now, configure the extension with the appropriate options:

./configure --with-php-config=/RunCloud/Packages/php81rc/bin/php-config --with-libdir=lib64 CFLAGS='-O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wall -pedantic -fsigned-char -fno-strict-aliasing'

After configuring the extension, install it by executing:

make install

To enable the extension, create a new configuration file for PDO_SQLSRV:

echo "extension=$MODULE_NAME.so" > /etc/php81rc/conf.d/$MODULE_NAME.ini

Finally, restart the PHP-FPM service to apply the changes:

systemctl restart php81rc-fpm

Verifying the Installation

To verify if the PDO_SQLSRV extension is installed correctly, run the following command:

/RunCloud/Packages/php81rc/bin/php -m | grep pdo_sqlsrv

If the extension is installed successfully, you should see "pdo_sqlsrv" in the output.

Installing ODBC Drivers

In order for the PDO_SQLSRV extension to function properly, it requires the installation of ODBC drivers. Refer to the official Microsoft documentation for instructions on installing the ODBC driver for SQL Server on Linux:

Installing the Microsoft ODBC Driver for SQL Server

Follow the instructions provided in the documentation to install the ODBC driver on your server.

That's it! You have now successfully installed the latest stable version of the PDO_SQLSRV extension on your RunCloud Nginx server with PHP 8.1. Remember to install the ODBC drivers as well to ensure the extension works as expected. If you encounter any issues or have further questions, please refer to the official documentation or seek assistance from the RunCloud or Microsoft support channels.

Comments