Using SQL server from Microsoft.
- Copy
docker-compose.sqlsrv.yaml
to your project's.ddev
directory. - Copy
Dockerfile
to your project's.devv/web-build
directory. - Copy the full post start hook commands to your project's
config.yaml
or add them toconfig.sqlsrv.yaml
. - (optional) For Drupal 9+ projects: copy
install-drupal-regex-function.sh
to your project's.ddev
directory.
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
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 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 1clr strict security
will be set to 0clr 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
- 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]
- See .ddev/config.yaml Options for additional notes.
Future enhancements (PR's welcome here) include:
- Provide custom commands.
- SQL Server docker hub
- Installing the ODBC driver for SQL Server
- Installing the ODBC driver for SQL Server Tutorial
- Installation tutorial for MS drivers for PHP
- The SQLCMD utility
- The SQL Server on Linux
- The password policy
- The SQL Server environment variables
- Beakerboy's Drupal Regex database function
- Drupal's module for the SQL Server
- Github MS drivers for PHP