Use MSSQL as Default Database with Drupal 10 (Windows)

27 / Mar / 2024 by Yogendra Pratap Singh 0 comments

By default MariaDB, MySQL/Percona, PostgreSQL and SQLite databases are available for Drupal. The purpose of this blog is to Use MSSQL as Default Database with Drupal 10 (Windows). 

Let’s start installing Xdebug 3 on MacOs

Step 1 :  First we need to install MSSQL database on Windows

Step 2: Click on setup file and follows all steps to install SQL server

Step 3: After installing Sql server, need to install Microsoft SQL Server Management Studio (GUI)

After installation of MSSQL database, check that PDO driver for SQL Server is installed or not by using below function:

<?php
     echo phpinfo();
?> 

If not installed, then follow below steps:

Step 1: Go to https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver16 and download zip archive

Step 2: Unzip the folder and choose the driver as per your PHP version and system configuration.

For e.g. For PHP 8.1 version, copied above highlighted files and paste into C:\xampp\php\ext  folder

Step 3: After installing the driver, you need to enable it in your php.ini file. You can do this by adding the following lines:

extension=php_pdo_sqlsrv_XX_ts.dll

extension=php_sqlsrv_XX_ts.dll

Replace `XX` with your PHP version. For example, if you’re using PHP 8.1, use `81`. And restart your server.

To download and install Drupal using composer

Step 1: Run composer create-project drupal/recommended-project my_site_name command in terminal.

Step2: Install sqlsrv module which will communicate Drupal with MSSQL composer require ‘drupal/sqlsrv:^4.4’

Step3: After installing above modules, SQL server options will be displayed under database types.

 

Step 4: After entering  all the information, click on the submit button or paste below code in settings.php file

$databases['default']['default'] = array (

  'database' => 'XXXX',

  'username' => XXX,

  'password' => 'XXXX',

  'prefix' => '',

  'host' => XXX,

  'port' => '1433',

  'schema' => 'dbo',

  'cache_schema' => 0,

  'autoload' => 'modules/contrib/sqlsrv/src/Driver/Database/sqlsrv/',

  'encrypt' => '1',

  'trust_server_certificate' => '1',

  'multi_subnet_failover' => 0,

  'namespace' => 'Drupal\\sqlsrv\\Driver\\Database\\sqlsrv',

  'driver' => 'sqlsrv',

);

Conclusion

Finally, MSSQL database setup with Drupal 10 completed successfully.

Let us know in case of any issues during the installation process, and please feel free to reach out via comments.

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *