Installing PHP SQLSRV Extension - RunCloud Nginx

Installing PHP SQLSRV Extension - RunCloud Nginx

Installing PHP SQLSRV Extension - RunCloud Nginx


Hello everyone! Today, we're going to talk about installing the PHP SQLSRV extension on a RunCloud Nginx server. If you're a PHP developer working with Microsoft SQL Server databases, you might find yourself needing to install this extension in order to interact with your databases from your PHP code.

For installing PDO SQLSRV refer : How to install PDO SQLSRV extension on RunCloud Nginx server | PHP 8.1 (linuxtutorialz.co.uk)


Introduction

The PHP SQLSRV extension provides a way to access data stored in Microsoft SQL Server databases from a PHP application. It supports all of the latest features of SQL Server, including the latest versions of SQL Server, and provides a fast, reliable, and easy-to-use API for accessing your data.

In this blog post, we'll go over the steps required to install the PHP SQLSRV extension on a RunCloud Nginx server. We'll be covering everything from downloading the extension to configuring it in your PHP environment. Whether you're a beginner or an experienced PHP developer, this guide will help you get up and running with the PHP SQLSRV extension quickly and easily.


Step1: Installing dependencies.

For this example, we are assuming our PHP version that require SQLSRV extension is PHP80, you can replace commands with your own version according to your requirement. Before jump into installation steps, first make sure below packages are installed on your server, you can just run the following commands.

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

"autoconf" is a tool for generating configure scripts for building, installing, and deploying software packages on various operating systems. It creates scripts that can automatically determine the installation environment and configure the software to run on that environment.

"libpcre3-dev" is the development library for PCRE (Perl Compatible Regular Expressions), a library for working with regular expressions. The "dev" suffix indicates that this package provides the headers and libraries necessary for development, allowing other software to be built against it.

"unixodbc-dev" is a development package for UnixODBC, which is a software library that provides a standard API for accessing databases on Unix-based systems. The "unixodbc-dev" package contains the headers and libraries necessary for developing applications that use UnixODBC. By using UnixODBC, developers can write database-independent applications that can work with different database management systems, making it easier to develop, deploy, and maintain database applications on Unix-based systems.

Step 2: Downloading extension.

Once the dependencies are installed, we can download the extension.

First, we are setting up shell variables in your server by assigning the extension name and required version number. To get the version number and check it's requirement, just go to PECL :: The PHP Extension Community Library and search for 'sqlsrv' in their search options, It will provide that extension details.

Note
Highly recommended to use stable version to avoid bugs.

Once we locate the version, just run following commands, Make sure to update 'MODULE_VERSION' with your required version. I have used the latest available stable version of day of writing this blog.

MODULE_NAME="sqlsrv"
MODULE_VERSION="5.10.1"

Now, we can download the extension package using wget command.
Once the file is downloaded, we can extract the files using tar command.
tar -zxvf $MODULE_NAME-$MODULE_VERSION.tgz

Step3: Install the extension.

We can now install the extension by running below commands. Make sure to replace PHP version with your required one.
cd $MODULE_NAME-$MODULE_VERSION
make clean
/RunCloud/Packages/php80rc/bin/phpize --clean
/RunCloud/Packages/php80rc/bin/phpize
./configure
 --with-php-config=/RunCloud/Packages/php80rc/bin/php-config 
--with-libdir=lib64 CFLAGS='-O2 -fPIE -fstack-protector-strong -Wformat 
-Werror=format-security -Wall -pedantic -fsigned-char 
-fno-strict-aliasing'
make install

Please note, last command may take sometime to finish. Please run below command to finish the process.
echo "extension=$MODULE_NAME.so" > /etc/php80rc/conf.d/$MODULE_NAME.ini

Step 4: Restart the service.

Now, we can restart the php service to reflect the changes.
systemctl restart php80rc-fpm

Step 5: Verify the extension is installed correctly.

We can check installed extensions and check whether the sqlsrv is being listed there. Please run following command.
/RunCloud/Packages/php80rc/bin/php -m | grep sqlsrv

conclusion

In conclusion, the PHP SQLSRV extension is an essential tool for PHP developers working with Microsoft SQL Server databases. With its support for the latest SQL Server features and its easy-to-use API, it makes it simple to access and interact with your data. By following the steps outlined in this blog post, you can successfully install the PHP SQLSRV extension on your RunCloud Nginx server and start working with your Microsoft SQL Server databases in no time. Whether you're just starting out or you're an experienced PHP developer, this guide will help you get up and running with the PHP SQLSRV extension with ease.

Comments