Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

SQL Server (Microsoft)

Using SQL server from Microsoft.

Installation

  1. Copy docker-compose.sqlsrv.yaml to your project's .ddev directory.
  2. Copy Dockerfile to your project's .devv/web-build directory.
  3. Copy the full post start hook commands to your project's config.yaml or add them to config.sqlsrv.yaml.
  4. (optional) For Drupal 9+ projects: copy install-drupal-regex-function.sh to your project's .ddev directory.

Connection

Connect to sqlsrv host/db server from within the web container with:

Host: `ddev-projectname-sqlsrv`
User: sa
Password: password!
Database: master

Connect to sqlsrv host/db server from project directory:

ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P password! -S localhost -U sa -d master"

For external access, use the port used in your docker-compose.sqlsrv.yaml and 127.0.0.1 as host.

When using multiple databases in your project with SQL Server support, remember to update your docker-compose.sqlsrv.yaml to use different ports:

    ports:
      - <EXTERNAL_PORT>:1433

Installing the PHP extensions

The PHP extensions for SQL Server CANNOT be installed by adding them to the webimage_extra_packages setting. The problem is that they are not available as a Debian or any other distribution package. The 2 extensions (sqlsrv and pdo_sqlsrv) need to be compiled and this needs to be done after PHP is installed on the webimage. The following commands need to be copied to the end of the main config.yaml file:

hooks:
  post-start:
   - exec: echo export PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bashrc
   - exec: source ~/.bashrc

The minimum required PHP version the these extensions is PHP 7.3. For more information about these extension, see: MS SQL driver for PHP.

Drupal Notice

Drupal CMS needs the a database function installed that is mimicking the Regex function as Drupal requires. As a one-time setup for Drupal, install the database function by running the following command from your project's directory:

./install-drupal-regex-function.sh -u <username> -p <password> -d <database>

This script also changes the setting for the following database variables:

  • show advanced options will be set to 1
  • clr strict security will be set to 0
  • clr enable will be set to 1

Drupal also the module sqlsrv to be installed as it is providing the database driver for SQL Server. The module can be installed with composer with the following command:

$ php composer require drupal/sqlsrv

Disabling MySQL & MariaSQL

  • If your project only uses a SQL Server database, you can disable the MySql & MariaDb services.
  • Run the following command from your project root.
ddev config --omit-containers db
  • Alternatively, you can update your project's .ddev/config.yaml directly by updating the following line:
omit_containers: [db]

TODO

Future enhancements (PR's welcome here) include:

  • Provide custom commands.

Links with useful information