From bf46cc96f0732403fd90db03f54d3fe7eb8a472b Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 16 Oct 2021 11:34:16 +0200 Subject: [PATCH 01/30] Update README.md with link to SQL Server service --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 072ca85d..cdd1f3a7 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ General information on how to do additional services and some additional example * [Solr 7 Integration (Drupal-focused)](docker-compose-services/solr-7) * [Solr Cloud (Drupal-focused)](docker-compose-services/solr-cloud) * [Solr Integration (TYPO3-focused)](docker-compose-services/typo3-solr) +* [SQL Server (Microsoft)](docker-compose-services/sqlsrv) * [Varnish](docker-compose-services/varnish) ## .ddev/web-build/Dockerfile examples to customize web container From 2d88144200a44bd7caee88ac8f88716ff6db6c9c Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 16 Oct 2021 11:35:39 +0200 Subject: [PATCH 02/30] The new service for SQL Server --- sqlsrv/README.md | 136 ++++++++++++++++++++++++ sqlsrv/docker-compose.sqlsrv.yaml | 55 ++++++++++ sqlsrv/install-drupal-regex-function.sh | 54 ++++++++++ 3 files changed, 245 insertions(+) create mode 100644 sqlsrv/README.md create mode 100644 sqlsrv/docker-compose.sqlsrv.yaml create mode 100644 sqlsrv/install-drupal-regex-function.sh diff --git a/sqlsrv/README.md b/sqlsrv/README.md new file mode 100644 index 00000000..4ff6fdc5 --- /dev/null +++ b/sqlsrv/README.md @@ -0,0 +1,136 @@ +# SQL Server (Microsoft) + +Using SQL server from Microsoft. + +## Installation + +1. Copy `docker-compose.sqlsrv.yaml` to your project's `.ddev` directory. +2. Copy the full post start hook command to your project's `config.yaml`. +3. *(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: sqlsrv +User: sa +Password: password! +Database: master +``` + +Connect to `sqlsrv` host/db server from project directory: + +```bash +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: + +```yaml + ports: + - :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: + +```yaml +hooks: + post-start: + - exec: "curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -" + + # For the next line: change the Debian version number to the one that DDEV is + # using. For DDEV v1.17.7 is it Debian version 10. Run the following command + # to get the information: "ddev exec lsb_release -a". You shall probably need + # to remove the post startup hooks to make the webserver boot in order to run + # the command. + - exec: sudo bash -c 'curl -s https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list' + + - exec: sudo apt-get -y update + - exec: sudo apt-get -y install dialog apt-utils + - exec: sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools + - exec: echo 'export PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bashrc' + - exec: source ~/.bashrc + - exec: sudo apt-get -y install unixodbc-dev + - exec: sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config + - exec: sudo apt-get -y install php-pear php-dev + - exec: sudo pecl channel-update pecl.php.net + - exec: sudo pecl install sqlsrv + - exec: sudo pecl install pdo_sqlsrv + + # For the next 3 lines: change the PHP version number to the one set in + # the variable: "php_version". The currently used PHP version is "8.0". + - exec: "echo 'extension=sqlsrv.so' | sudo tee /etc/php/8.0/mods-available/sqlsrv.ini" + - exec: "echo 'extension=pdo_sqlsrv.so' | sudo tee /etc/php/8.0/mods-available/pdo_sqlsrv.ini" + - exec: sudo phpenmod -v 8.0 sqlsrv pdo_sqlsrv + + # For the next line: change the word "nginx" to "apache2" when the variable + # "webserver_type" is set to "apache-fpm". + - exec: killall -USR2 nginx php-fpm + + # Test that the installation of the PHP extensions for the SQL Server were + # successful. + - exec: "echo 'When the installation was succesful, the following strings: \"pdo_sqlsrv\" and \"sqlsrv\" should appear. Each on its own line.'" + - exec: "php -m | grep 'sqlsrv'" +``` + +The minimum required PHP version the these extensions is PHP 7.3. For more information about these extension, see: [MS SQL driver for PHP](https://github.com/microsoft/msphpsql). + + +## Drupal Notice + +Drupal CMS needs the a database function installed that is mimicking the Regex function as Drupal requires. To install such a database function run the following command from your project's directory: + +```bash +./install-drupal-regex-function.sh -u -p -d +``` + +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: + +```bash +$ 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. + +```bash +ddev config --omit-containers db +``` + +* Alternatively, you can update your project's `.ddev/config.yaml` directly by updating the following line: + +```yaml +omit_containers: [db] +``` + +* See [.ddev/config.yaml Options]() for additional notes. + +## TODO + +Future enhancements (PR's welcome here) include: + +* Provide custom commands. + +## Links with useful information + +* [SQL Server docker hub](https://hub.docker.com/_/microsoft-mssql-server) +* [Installing the ODBC driver for SQL Server](https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15) +* [Installing the ODBC driver for SQL Server Tutorial](https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15) +* [The SQLCMD utility](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15) +* [The SQL Server on Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-overview?view=sql-server-ver15) +* [The password policy](https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15) +* [The SQL Server environment variables](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver15) +* [Beakerboy's Drupal Regex database function](https://github.com/Beakerboy/drupal-sqlsrv-regex) +* [Drupal's module for the SQL Server](https://www.drupal.org/project/sqlsrv) diff --git a/sqlsrv/docker-compose.sqlsrv.yaml b/sqlsrv/docker-compose.sqlsrv.yaml new file mode 100644 index 00000000..70a181d3 --- /dev/null +++ b/sqlsrv/docker-compose.sqlsrv.yaml @@ -0,0 +1,55 @@ +version: '3.6' + +services: + sqlsrv: + container_name: ddev-${DDEV_SITENAME}-sqlsrv + hostname: ddev-${DDEV_SITENAME}-sqlsrv + + # For possible options: https://hub.docker.com/_/microsoft-mssql-server. + image: mcr.microsoft.com/mssql/server:2019-CU12-ubuntu-20.04 + + user: root + volumes: + - sqlsystem:/var/opt/mssql/ + - sqldata:/var/opt/sqlserver/data + - sqllog:/var/opt/sqlserver/log + - sqlbackup:/var/opt/sqlserver/backup + restart: "no" + ports: + - "1433:1433" + labels: + com.ddev.site-name: ${DDEV_SITENAME} + com.ddev.approot: $DDEV_APPROOT + environment: + + # With the following setting you agree with Microsoft's end user license + # agreement. + - 'ACCEPT_EULA=Y' + + # The SQL Server enforces password complexity. Trying to set a password + # that is not sufficiently complex will result in the password not be set. + # As a result you cannot login with the "SA" user account. + # The password for the SA account needs to follow the following policy: + # https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15 + - 'SA_PASSWORD=Password12!' + + # The following setting is for selecting the SQL Server edition or product + # key. For possible options: + # https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver15 + - 'MSSQL_PID=Evaluation' + + # Sets the default collation for SQL Server. This setting is optional. + - 'MSSQL_COLLATION=LATIN1_GENERAL_100_CI_AS_SC_UTF8' + + # For more possible environment variables that can be set, see: + # https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15 + + web: + links: + - sqlsrv:sqlsrv + +volumes: + sqlsystem: + sqldata: + sqllog: + sqlbackup: diff --git a/sqlsrv/install-drupal-regex-function.sh b/sqlsrv/install-drupal-regex-function.sh new file mode 100644 index 00000000..16eb2849 --- /dev/null +++ b/sqlsrv/install-drupal-regex-function.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# Installs the Regex database function for compatibility with Drupal version 9 or higher. +# This script only needs to be run once for a database. + +usage() { echo "./install-drupal-regex-function.sh -u -p -d " 1>&2; exit 1; } + +# The password for the database defaults to "" +password="" + +# The username for the database defaults to "SA" +username="SA" + +# The database name defaults to "master" +database="master" + +while getopts ":u:p:d:h:" arg; do + case $arg in + u) + username=${OPTARG} + ;; + p) + password=${OPTARG} + ;; + d) + database=${OPTARG} + ;; + h) + usage + ;; + *) + usage + ;; + esac +done + +if [ -z $password ] +then + echo "The parameter -p for the password is not set." + exit 1 +fi + +if ! ddev exec -s sqlsrv test -e "/var/opt/mssql/data/RegEx.dll" &>/dev/null; +then + # Download the Regex.dll file and copy it to the right location. + ddev exec -s sqlsrv wget https://github.com/Beakerboy/drupal-sqlsrv-regex/releases/download/1.0/RegEx.dll + ddev exec -s sqlsrv sudo mv RegEx.dll /var/opt/mssql/data/ +fi + +# Set the following variables: "show advanced options", "clr strict security" and "clr enable". +ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'EXEC sp_configure \"show advanced options\", 1; RECONFIGURE; EXEC sp_configure \"clr strict security\", 0; RECONFIGURE; EXEC sp_configure \"clr enable\", 1; RECONFIGURE;'" + +# Create the assambly and the function for the Regex helper. +ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE ASSEMBLY Regex from \"/var/opt/mssql/data/RegEx.dll\" WITH PERMISSION_SET = SAFE'" +ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE FUNCTION dbo.REGEXP(@pattern NVARCHAR(100), @matchString NVARCHAR(100)) RETURNS bit EXTERNAL NAME Regex.RegExCompiled.RegExCompiledMatch'" From 0090956f9f1a6a65616b12f12c18ebcd0ae19602 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 16 Oct 2021 11:43:41 +0200 Subject: [PATCH 03/30] Create docker-compose.sqlsrv.yaml --- .../sqlsrv/docker-compose.sqlsrv.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml diff --git a/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml b/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml new file mode 100644 index 00000000..70a181d3 --- /dev/null +++ b/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml @@ -0,0 +1,55 @@ +version: '3.6' + +services: + sqlsrv: + container_name: ddev-${DDEV_SITENAME}-sqlsrv + hostname: ddev-${DDEV_SITENAME}-sqlsrv + + # For possible options: https://hub.docker.com/_/microsoft-mssql-server. + image: mcr.microsoft.com/mssql/server:2019-CU12-ubuntu-20.04 + + user: root + volumes: + - sqlsystem:/var/opt/mssql/ + - sqldata:/var/opt/sqlserver/data + - sqllog:/var/opt/sqlserver/log + - sqlbackup:/var/opt/sqlserver/backup + restart: "no" + ports: + - "1433:1433" + labels: + com.ddev.site-name: ${DDEV_SITENAME} + com.ddev.approot: $DDEV_APPROOT + environment: + + # With the following setting you agree with Microsoft's end user license + # agreement. + - 'ACCEPT_EULA=Y' + + # The SQL Server enforces password complexity. Trying to set a password + # that is not sufficiently complex will result in the password not be set. + # As a result you cannot login with the "SA" user account. + # The password for the SA account needs to follow the following policy: + # https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15 + - 'SA_PASSWORD=Password12!' + + # The following setting is for selecting the SQL Server edition or product + # key. For possible options: + # https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver15 + - 'MSSQL_PID=Evaluation' + + # Sets the default collation for SQL Server. This setting is optional. + - 'MSSQL_COLLATION=LATIN1_GENERAL_100_CI_AS_SC_UTF8' + + # For more possible environment variables that can be set, see: + # https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15 + + web: + links: + - sqlsrv:sqlsrv + +volumes: + sqlsystem: + sqldata: + sqllog: + sqlbackup: From ca54dcd1e46d8c7fef0853c1a4b8fd6f81e43108 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 16 Oct 2021 11:44:55 +0200 Subject: [PATCH 04/30] Create install-drupal-regex-function.sh --- .../sqlsrv/install-drupal-regex-function.sh | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 docker-compose-services/sqlsrv/install-drupal-regex-function.sh diff --git a/docker-compose-services/sqlsrv/install-drupal-regex-function.sh b/docker-compose-services/sqlsrv/install-drupal-regex-function.sh new file mode 100644 index 00000000..16eb2849 --- /dev/null +++ b/docker-compose-services/sqlsrv/install-drupal-regex-function.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# Installs the Regex database function for compatibility with Drupal version 9 or higher. +# This script only needs to be run once for a database. + +usage() { echo "./install-drupal-regex-function.sh -u -p -d " 1>&2; exit 1; } + +# The password for the database defaults to "" +password="" + +# The username for the database defaults to "SA" +username="SA" + +# The database name defaults to "master" +database="master" + +while getopts ":u:p:d:h:" arg; do + case $arg in + u) + username=${OPTARG} + ;; + p) + password=${OPTARG} + ;; + d) + database=${OPTARG} + ;; + h) + usage + ;; + *) + usage + ;; + esac +done + +if [ -z $password ] +then + echo "The parameter -p for the password is not set." + exit 1 +fi + +if ! ddev exec -s sqlsrv test -e "/var/opt/mssql/data/RegEx.dll" &>/dev/null; +then + # Download the Regex.dll file and copy it to the right location. + ddev exec -s sqlsrv wget https://github.com/Beakerboy/drupal-sqlsrv-regex/releases/download/1.0/RegEx.dll + ddev exec -s sqlsrv sudo mv RegEx.dll /var/opt/mssql/data/ +fi + +# Set the following variables: "show advanced options", "clr strict security" and "clr enable". +ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'EXEC sp_configure \"show advanced options\", 1; RECONFIGURE; EXEC sp_configure \"clr strict security\", 0; RECONFIGURE; EXEC sp_configure \"clr enable\", 1; RECONFIGURE;'" + +# Create the assambly and the function for the Regex helper. +ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE ASSEMBLY Regex from \"/var/opt/mssql/data/RegEx.dll\" WITH PERMISSION_SET = SAFE'" +ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE FUNCTION dbo.REGEXP(@pattern NVARCHAR(100), @matchString NVARCHAR(100)) RETURNS bit EXTERNAL NAME Regex.RegExCompiled.RegExCompiledMatch'" From 5af58de7e1ce60d9c9cd8610937019be33aed67d Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 16 Oct 2021 11:45:32 +0200 Subject: [PATCH 05/30] Create README.md --- docker-compose-services/sqlsrv/README.md | 136 +++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 docker-compose-services/sqlsrv/README.md diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md new file mode 100644 index 00000000..4ff6fdc5 --- /dev/null +++ b/docker-compose-services/sqlsrv/README.md @@ -0,0 +1,136 @@ +# SQL Server (Microsoft) + +Using SQL server from Microsoft. + +## Installation + +1. Copy `docker-compose.sqlsrv.yaml` to your project's `.ddev` directory. +2. Copy the full post start hook command to your project's `config.yaml`. +3. *(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: sqlsrv +User: sa +Password: password! +Database: master +``` + +Connect to `sqlsrv` host/db server from project directory: + +```bash +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: + +```yaml + ports: + - :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: + +```yaml +hooks: + post-start: + - exec: "curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -" + + # For the next line: change the Debian version number to the one that DDEV is + # using. For DDEV v1.17.7 is it Debian version 10. Run the following command + # to get the information: "ddev exec lsb_release -a". You shall probably need + # to remove the post startup hooks to make the webserver boot in order to run + # the command. + - exec: sudo bash -c 'curl -s https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list' + + - exec: sudo apt-get -y update + - exec: sudo apt-get -y install dialog apt-utils + - exec: sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools + - exec: echo 'export PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bashrc' + - exec: source ~/.bashrc + - exec: sudo apt-get -y install unixodbc-dev + - exec: sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config + - exec: sudo apt-get -y install php-pear php-dev + - exec: sudo pecl channel-update pecl.php.net + - exec: sudo pecl install sqlsrv + - exec: sudo pecl install pdo_sqlsrv + + # For the next 3 lines: change the PHP version number to the one set in + # the variable: "php_version". The currently used PHP version is "8.0". + - exec: "echo 'extension=sqlsrv.so' | sudo tee /etc/php/8.0/mods-available/sqlsrv.ini" + - exec: "echo 'extension=pdo_sqlsrv.so' | sudo tee /etc/php/8.0/mods-available/pdo_sqlsrv.ini" + - exec: sudo phpenmod -v 8.0 sqlsrv pdo_sqlsrv + + # For the next line: change the word "nginx" to "apache2" when the variable + # "webserver_type" is set to "apache-fpm". + - exec: killall -USR2 nginx php-fpm + + # Test that the installation of the PHP extensions for the SQL Server were + # successful. + - exec: "echo 'When the installation was succesful, the following strings: \"pdo_sqlsrv\" and \"sqlsrv\" should appear. Each on its own line.'" + - exec: "php -m | grep 'sqlsrv'" +``` + +The minimum required PHP version the these extensions is PHP 7.3. For more information about these extension, see: [MS SQL driver for PHP](https://github.com/microsoft/msphpsql). + + +## Drupal Notice + +Drupal CMS needs the a database function installed that is mimicking the Regex function as Drupal requires. To install such a database function run the following command from your project's directory: + +```bash +./install-drupal-regex-function.sh -u -p -d +``` + +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: + +```bash +$ 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. + +```bash +ddev config --omit-containers db +``` + +* Alternatively, you can update your project's `.ddev/config.yaml` directly by updating the following line: + +```yaml +omit_containers: [db] +``` + +* See [.ddev/config.yaml Options]() for additional notes. + +## TODO + +Future enhancements (PR's welcome here) include: + +* Provide custom commands. + +## Links with useful information + +* [SQL Server docker hub](https://hub.docker.com/_/microsoft-mssql-server) +* [Installing the ODBC driver for SQL Server](https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15) +* [Installing the ODBC driver for SQL Server Tutorial](https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15) +* [The SQLCMD utility](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15) +* [The SQL Server on Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-overview?view=sql-server-ver15) +* [The password policy](https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15) +* [The SQL Server environment variables](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver15) +* [Beakerboy's Drupal Regex database function](https://github.com/Beakerboy/drupal-sqlsrv-regex) +* [Drupal's module for the SQL Server](https://www.drupal.org/project/sqlsrv) From 953c6c8f1023b69d5ce56676864b0670eccff6a9 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 16 Oct 2021 11:46:11 +0200 Subject: [PATCH 06/30] Fixed typo in README.md --- docker-compose-services/sqlsrv/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index 4ff6fdc5..48ff0827 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -5,7 +5,7 @@ Using SQL server from Microsoft. ## Installation 1. Copy `docker-compose.sqlsrv.yaml` to your project's `.ddev` directory. -2. Copy the full post start hook command to your project's `config.yaml`. +2. Copy the full post start hook commands to your project's `config.yaml`. 3. *(optional)* For Drupal 9+ projects: copy `install-drupal-regex-function.sh` to your project's `.ddev` directory. ## Connection From 51fe2e5333630ce319dd29070836f9bf679553b6 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 16 Oct 2021 11:47:26 +0200 Subject: [PATCH 07/30] Delete README.md because it was in the wrong directory --- sqlsrv/README.md | 136 ----------------------------------------------- 1 file changed, 136 deletions(-) delete mode 100644 sqlsrv/README.md diff --git a/sqlsrv/README.md b/sqlsrv/README.md deleted file mode 100644 index 4ff6fdc5..00000000 --- a/sqlsrv/README.md +++ /dev/null @@ -1,136 +0,0 @@ -# SQL Server (Microsoft) - -Using SQL server from Microsoft. - -## Installation - -1. Copy `docker-compose.sqlsrv.yaml` to your project's `.ddev` directory. -2. Copy the full post start hook command to your project's `config.yaml`. -3. *(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: sqlsrv -User: sa -Password: password! -Database: master -``` - -Connect to `sqlsrv` host/db server from project directory: - -```bash -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: - -```yaml - ports: - - :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: - -```yaml -hooks: - post-start: - - exec: "curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -" - - # For the next line: change the Debian version number to the one that DDEV is - # using. For DDEV v1.17.7 is it Debian version 10. Run the following command - # to get the information: "ddev exec lsb_release -a". You shall probably need - # to remove the post startup hooks to make the webserver boot in order to run - # the command. - - exec: sudo bash -c 'curl -s https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list' - - - exec: sudo apt-get -y update - - exec: sudo apt-get -y install dialog apt-utils - - exec: sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools - - exec: echo 'export PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bashrc' - - exec: source ~/.bashrc - - exec: sudo apt-get -y install unixodbc-dev - - exec: sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config - - exec: sudo apt-get -y install php-pear php-dev - - exec: sudo pecl channel-update pecl.php.net - - exec: sudo pecl install sqlsrv - - exec: sudo pecl install pdo_sqlsrv - - # For the next 3 lines: change the PHP version number to the one set in - # the variable: "php_version". The currently used PHP version is "8.0". - - exec: "echo 'extension=sqlsrv.so' | sudo tee /etc/php/8.0/mods-available/sqlsrv.ini" - - exec: "echo 'extension=pdo_sqlsrv.so' | sudo tee /etc/php/8.0/mods-available/pdo_sqlsrv.ini" - - exec: sudo phpenmod -v 8.0 sqlsrv pdo_sqlsrv - - # For the next line: change the word "nginx" to "apache2" when the variable - # "webserver_type" is set to "apache-fpm". - - exec: killall -USR2 nginx php-fpm - - # Test that the installation of the PHP extensions for the SQL Server were - # successful. - - exec: "echo 'When the installation was succesful, the following strings: \"pdo_sqlsrv\" and \"sqlsrv\" should appear. Each on its own line.'" - - exec: "php -m | grep 'sqlsrv'" -``` - -The minimum required PHP version the these extensions is PHP 7.3. For more information about these extension, see: [MS SQL driver for PHP](https://github.com/microsoft/msphpsql). - - -## Drupal Notice - -Drupal CMS needs the a database function installed that is mimicking the Regex function as Drupal requires. To install such a database function run the following command from your project's directory: - -```bash -./install-drupal-regex-function.sh -u -p -d -``` - -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: - -```bash -$ 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. - -```bash -ddev config --omit-containers db -``` - -* Alternatively, you can update your project's `.ddev/config.yaml` directly by updating the following line: - -```yaml -omit_containers: [db] -``` - -* See [.ddev/config.yaml Options]() for additional notes. - -## TODO - -Future enhancements (PR's welcome here) include: - -* Provide custom commands. - -## Links with useful information - -* [SQL Server docker hub](https://hub.docker.com/_/microsoft-mssql-server) -* [Installing the ODBC driver for SQL Server](https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15) -* [Installing the ODBC driver for SQL Server Tutorial](https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15) -* [The SQLCMD utility](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15) -* [The SQL Server on Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-overview?view=sql-server-ver15) -* [The password policy](https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15) -* [The SQL Server environment variables](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver15) -* [Beakerboy's Drupal Regex database function](https://github.com/Beakerboy/drupal-sqlsrv-regex) -* [Drupal's module for the SQL Server](https://www.drupal.org/project/sqlsrv) From 7d325d918cdc4595a261ac1cea3ef1250723015f Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 16 Oct 2021 11:47:49 +0200 Subject: [PATCH 08/30] Delete docker-compose.sqlsrv.yaml because it was in the wrong directory --- sqlsrv/docker-compose.sqlsrv.yaml | 55 ------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 sqlsrv/docker-compose.sqlsrv.yaml diff --git a/sqlsrv/docker-compose.sqlsrv.yaml b/sqlsrv/docker-compose.sqlsrv.yaml deleted file mode 100644 index 70a181d3..00000000 --- a/sqlsrv/docker-compose.sqlsrv.yaml +++ /dev/null @@ -1,55 +0,0 @@ -version: '3.6' - -services: - sqlsrv: - container_name: ddev-${DDEV_SITENAME}-sqlsrv - hostname: ddev-${DDEV_SITENAME}-sqlsrv - - # For possible options: https://hub.docker.com/_/microsoft-mssql-server. - image: mcr.microsoft.com/mssql/server:2019-CU12-ubuntu-20.04 - - user: root - volumes: - - sqlsystem:/var/opt/mssql/ - - sqldata:/var/opt/sqlserver/data - - sqllog:/var/opt/sqlserver/log - - sqlbackup:/var/opt/sqlserver/backup - restart: "no" - ports: - - "1433:1433" - labels: - com.ddev.site-name: ${DDEV_SITENAME} - com.ddev.approot: $DDEV_APPROOT - environment: - - # With the following setting you agree with Microsoft's end user license - # agreement. - - 'ACCEPT_EULA=Y' - - # The SQL Server enforces password complexity. Trying to set a password - # that is not sufficiently complex will result in the password not be set. - # As a result you cannot login with the "SA" user account. - # The password for the SA account needs to follow the following policy: - # https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15 - - 'SA_PASSWORD=Password12!' - - # The following setting is for selecting the SQL Server edition or product - # key. For possible options: - # https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver15 - - 'MSSQL_PID=Evaluation' - - # Sets the default collation for SQL Server. This setting is optional. - - 'MSSQL_COLLATION=LATIN1_GENERAL_100_CI_AS_SC_UTF8' - - # For more possible environment variables that can be set, see: - # https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15 - - web: - links: - - sqlsrv:sqlsrv - -volumes: - sqlsystem: - sqldata: - sqllog: - sqlbackup: From a583d23f08e78a72919aae152eb3ef53862bce48 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 16 Oct 2021 11:48:37 +0200 Subject: [PATCH 09/30] Delete install-drupal-regex-function.sh because it was in the wrong directory --- sqlsrv/install-drupal-regex-function.sh | 54 ------------------------- 1 file changed, 54 deletions(-) delete mode 100644 sqlsrv/install-drupal-regex-function.sh diff --git a/sqlsrv/install-drupal-regex-function.sh b/sqlsrv/install-drupal-regex-function.sh deleted file mode 100644 index 16eb2849..00000000 --- a/sqlsrv/install-drupal-regex-function.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash -# Installs the Regex database function for compatibility with Drupal version 9 or higher. -# This script only needs to be run once for a database. - -usage() { echo "./install-drupal-regex-function.sh -u -p -d " 1>&2; exit 1; } - -# The password for the database defaults to "" -password="" - -# The username for the database defaults to "SA" -username="SA" - -# The database name defaults to "master" -database="master" - -while getopts ":u:p:d:h:" arg; do - case $arg in - u) - username=${OPTARG} - ;; - p) - password=${OPTARG} - ;; - d) - database=${OPTARG} - ;; - h) - usage - ;; - *) - usage - ;; - esac -done - -if [ -z $password ] -then - echo "The parameter -p for the password is not set." - exit 1 -fi - -if ! ddev exec -s sqlsrv test -e "/var/opt/mssql/data/RegEx.dll" &>/dev/null; -then - # Download the Regex.dll file and copy it to the right location. - ddev exec -s sqlsrv wget https://github.com/Beakerboy/drupal-sqlsrv-regex/releases/download/1.0/RegEx.dll - ddev exec -s sqlsrv sudo mv RegEx.dll /var/opt/mssql/data/ -fi - -# Set the following variables: "show advanced options", "clr strict security" and "clr enable". -ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'EXEC sp_configure \"show advanced options\", 1; RECONFIGURE; EXEC sp_configure \"clr strict security\", 0; RECONFIGURE; EXEC sp_configure \"clr enable\", 1; RECONFIGURE;'" - -# Create the assambly and the function for the Regex helper. -ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE ASSEMBLY Regex from \"/var/opt/mssql/data/RegEx.dll\" WITH PERMISSION_SET = SAFE'" -ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE FUNCTION dbo.REGEXP(@pattern NVARCHAR(100), @matchString NVARCHAR(100)) RETURNS bit EXTERNAL NAME Regex.RegExCompiled.RegExCompiledMatch'" From 9dc60a4be4739b417d5c9057a2075cab6f9135bf Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 16 Oct 2021 11:52:45 +0200 Subject: [PATCH 10/30] Update README.md wrong link for installing the ODBC driver --- docker-compose-services/sqlsrv/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index 48ff0827..a1b80074 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -126,7 +126,7 @@ Future enhancements (PR's welcome here) include: ## Links with useful information * [SQL Server docker hub](https://hub.docker.com/_/microsoft-mssql-server) -* [Installing the ODBC driver for SQL Server](https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15) +* [Installing the ODBC driver for SQL Server](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15) * [Installing the ODBC driver for SQL Server Tutorial](https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15) * [The SQLCMD utility](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15) * [The SQL Server on Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-overview?view=sql-server-ver15) From 975b485f66b6a826b45a23cca44373efc802d355 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Tue, 19 Oct 2021 09:24:45 +0200 Subject: [PATCH 11/30] Updated the default setting for the SQL Server collation. --- docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml b/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml index 70a181d3..513359a6 100644 --- a/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml +++ b/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml @@ -38,7 +38,9 @@ services: # https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver15 - 'MSSQL_PID=Evaluation' - # Sets the default collation for SQL Server. This setting is optional. + # Sets the default collation for SQL Server. This setting is optional. The + # current setting is best for Drupal projects. For more information, see: + # https://docs.microsoft.com/en-us/sql/relational-databases/collations/collation-and-unicode-support?view=sql-server-ver15 - 'MSSQL_COLLATION=LATIN1_GENERAL_100_CI_AS_SC_UTF8' # For more possible environment variables that can be set, see: From 822cce120f20483259fef60875883a754bbcb3f2 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Tue, 19 Oct 2021 09:27:42 +0200 Subject: [PATCH 12/30] Updated the comment for why the settings are changed. --- docker-compose-services/sqlsrv/install-drupal-regex-function.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-services/sqlsrv/install-drupal-regex-function.sh b/docker-compose-services/sqlsrv/install-drupal-regex-function.sh index 16eb2849..8798908c 100644 --- a/docker-compose-services/sqlsrv/install-drupal-regex-function.sh +++ b/docker-compose-services/sqlsrv/install-drupal-regex-function.sh @@ -46,7 +46,7 @@ then ddev exec -s sqlsrv sudo mv RegEx.dll /var/opt/mssql/data/ fi -# Set the following variables: "show advanced options", "clr strict security" and "clr enable". +# The following are changed to allow the installation and execution of the user provided database function. ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'EXEC sp_configure \"show advanced options\", 1; RECONFIGURE; EXEC sp_configure \"clr strict security\", 0; RECONFIGURE; EXEC sp_configure \"clr enable\", 1; RECONFIGURE;'" # Create the assambly and the function for the Regex helper. From b5bd7fdff9ffbf3d28255c4c186d0804a9801b48 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Mon, 25 Oct 2021 10:59:17 +0200 Subject: [PATCH 13/30] Updated README.md for problems with uploadgrogress. --- docker-compose-services/sqlsrv/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index a1b80074..5f24609d 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -68,6 +68,12 @@ hooks: - exec: "echo 'extension=pdo_sqlsrv.so' | sudo tee /etc/php/8.0/mods-available/pdo_sqlsrv.ini" - exec: sudo phpenmod -v 8.0 sqlsrv pdo_sqlsrv + # When you get warnings or errors that there is something wrong with + # uploadgrogress, then please uncomment the following lines. + #- exec: sudo pecl install uploadprogress + #- exec: "echo 'extension=uploadprogress.so' | sudo tee /etc/php/8.0/mods-available/uploadprogress.ini" + #- exec: sudo phpenmod -v 8.0 uploadprogress + # For the next line: change the word "nginx" to "apache2" when the variable # "webserver_type" is set to "apache-fpm". - exec: killall -USR2 nginx php-fpm From ef449443a3b725da0a44ad15d71a6f3e92bedeaa Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Mon, 25 Oct 2021 11:01:38 +0200 Subject: [PATCH 14/30] Updated README.md for problems with multiarch. --- docker-compose-services/sqlsrv/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index 5f24609d..1c406a38 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -51,6 +51,12 @@ hooks: - exec: sudo bash -c 'curl -s https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list' - exec: sudo apt-get -y update + + # When you have warnings or errors with multiarch, then please uncomment the + # following lines. + #- exec: wget http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/multiarch-support_2.27-3ubuntu1.4_amd64.deb + #- exec: sudo apt-get install ./multiarch-support_2.27-3ubuntu1.4_amd64.deb + - exec: sudo apt-get -y install dialog apt-utils - exec: sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools - exec: echo 'export PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bashrc' From 1bc6f710733cf0d06cf0411f085e4100da538b47 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Mon, 25 Oct 2021 11:12:36 +0200 Subject: [PATCH 15/30] Update docker-compose-services/sqlsrv/README.md Co-authored-by: Randy Fay --- docker-compose-services/sqlsrv/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index 1c406a38..cff1f451 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -127,7 +127,7 @@ ddev config --omit-containers db omit_containers: [db] ``` -* See [.ddev/config.yaml Options]() for additional notes. +* See [.ddev/config.yaml Options](https://ddev.readthedocs.io/en/stable/users/extend/config_yaml/) for additional notes. ## TODO From 9cb697954c97b69b4b56f6cf720534aed7db217b Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Mon, 25 Oct 2021 11:21:11 +0200 Subject: [PATCH 16/30] Update docker-compose-services/sqlsrv/README.md Co-authored-by: Randy Fay --- docker-compose-services/sqlsrv/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index cff1f451..cca90ad1 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -13,7 +13,7 @@ Using SQL server from Microsoft. Connect to `sqlsrv` host/db server from within the web container with: ``` -Host: sqlsrv +Host: `ddev-projectname-sqlsrv` User: sa Password: password! Database: master From de6f70859c1e06633ddbf02e23e636bf8402f05f Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Mon, 25 Oct 2021 11:22:36 +0200 Subject: [PATCH 17/30] Update docker-compose-services/sqlsrv/install-drupal-regex-function.sh Co-authored-by: Randy Fay --- docker-compose-services/sqlsrv/install-drupal-regex-function.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose-services/sqlsrv/install-drupal-regex-function.sh b/docker-compose-services/sqlsrv/install-drupal-regex-function.sh index 8798908c..3ce96767 100644 --- a/docker-compose-services/sqlsrv/install-drupal-regex-function.sh +++ b/docker-compose-services/sqlsrv/install-drupal-regex-function.sh @@ -52,3 +52,5 @@ ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $u # Create the assambly and the function for the Regex helper. ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE ASSEMBLY Regex from \"/var/opt/mssql/data/RegEx.dll\" WITH PERMISSION_SET = SAFE'" ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE FUNCTION dbo.REGEXP(@pattern NVARCHAR(100), @matchString NVARCHAR(100)) RETURNS bit EXTERNAL NAME Regex.RegExCompiled.RegExCompiledMatch'" + +**Contributed by [@drupal-daffie](https://github.com/drupal-daffie)** From 00f4d9cf00c85fc24bd14e5497db0d08da20b650 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Mon, 25 Oct 2021 11:24:22 +0200 Subject: [PATCH 18/30] Update docker-compose-services/sqlsrv/README.md Co-authored-by: Randy Fay --- docker-compose-services/sqlsrv/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index cca90ad1..eafd95cd 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -5,7 +5,7 @@ Using SQL server from Microsoft. ## Installation 1. Copy `docker-compose.sqlsrv.yaml` to your project's `.ddev` directory. -2. Copy the full post start hook commands to your project's `config.yaml`. +2. Copy the full post start hook commands to your project's `config.yaml` or add them to `config.sqlsrv.yaml`. 3. *(optional)* For Drupal 9+ projects: copy `install-drupal-regex-function.sh` to your project's `.ddev` directory. ## Connection From b380cf5dfcc78c9791a842fe15e3b0e7c01f3f2a Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Mon, 25 Oct 2021 20:31:20 +0200 Subject: [PATCH 19/30] Update docker-compose-services/sqlsrv/README.md Co-authored-by: Randy Fay --- docker-compose-services/sqlsrv/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index eafd95cd..75e36d34 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -95,7 +95,7 @@ The minimum required PHP version the these extensions is PHP 7.3. For more infor ## Drupal Notice -Drupal CMS needs the a database function installed that is mimicking the Regex function as Drupal requires. To install such a database function run the following command from your project's directory: +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: ```bash ./install-drupal-regex-function.sh -u -p -d From 9878984ea6313d14cf957c0ee3d1ec3a44e646e9 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Tue, 26 Oct 2021 13:21:20 +0200 Subject: [PATCH 20/30] Updating install-drupal-regex-function.sh for removing the sqlsystem volume on the SQL Server. --- .../sqlsrv/install-drupal-regex-function.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docker-compose-services/sqlsrv/install-drupal-regex-function.sh b/docker-compose-services/sqlsrv/install-drupal-regex-function.sh index 3ce96767..632183df 100644 --- a/docker-compose-services/sqlsrv/install-drupal-regex-function.sh +++ b/docker-compose-services/sqlsrv/install-drupal-regex-function.sh @@ -39,18 +39,17 @@ then exit 1 fi -if ! ddev exec -s sqlsrv test -e "/var/opt/mssql/data/RegEx.dll" &>/dev/null; +if ! ddev exec -s sqlsrv test -e "/RegEx.dll" &>/dev/null; then # Download the Regex.dll file and copy it to the right location. ddev exec -s sqlsrv wget https://github.com/Beakerboy/drupal-sqlsrv-regex/releases/download/1.0/RegEx.dll - ddev exec -s sqlsrv sudo mv RegEx.dll /var/opt/mssql/data/ fi # The following are changed to allow the installation and execution of the user provided database function. ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'EXEC sp_configure \"show advanced options\", 1; RECONFIGURE; EXEC sp_configure \"clr strict security\", 0; RECONFIGURE; EXEC sp_configure \"clr enable\", 1; RECONFIGURE;'" # Create the assambly and the function for the Regex helper. -ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE ASSEMBLY Regex from \"/var/opt/mssql/data/RegEx.dll\" WITH PERMISSION_SET = SAFE'" +ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE ASSEMBLY Regex from \"/RegEx.dll\" WITH PERMISSION_SET = SAFE'" ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE FUNCTION dbo.REGEXP(@pattern NVARCHAR(100), @matchString NVARCHAR(100)) RETURNS bit EXTERNAL NAME Regex.RegExCompiled.RegExCompiledMatch'" **Contributed by [@drupal-daffie](https://github.com/drupal-daffie)** From 9cc679224180a1bf03763850e6c4aa650776f0c6 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Tue, 26 Oct 2021 13:22:44 +0200 Subject: [PATCH 21/30] Updating docker-compose.sqlsrv.yml for removing the volumes: sqlsystem, sqllog and sqlbackup. --- docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml b/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml index 513359a6..ffa8176b 100644 --- a/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml +++ b/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml @@ -10,10 +10,7 @@ services: user: root volumes: - - sqlsystem:/var/opt/mssql/ - sqldata:/var/opt/sqlserver/data - - sqllog:/var/opt/sqlserver/log - - sqlbackup:/var/opt/sqlserver/backup restart: "no" ports: - "1433:1433" @@ -51,7 +48,4 @@ services: - sqlsrv:sqlsrv volumes: - sqlsystem: sqldata: - sqllog: - sqlbackup: From 65f62e26a766730aedb18a922cca6a06d66c4d59 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Wed, 27 Oct 2021 16:23:18 +0200 Subject: [PATCH 22/30] Updated the docker-compose.sqlsrv.yml file for the wrong volume. --- docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml b/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml index ffa8176b..aebfaba7 100644 --- a/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml +++ b/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml @@ -10,7 +10,7 @@ services: user: root volumes: - - sqldata:/var/opt/sqlserver/data + - sqlsystem:/var/opt/mssql/ restart: "no" ports: - "1433:1433" @@ -48,4 +48,4 @@ services: - sqlsrv:sqlsrv volumes: - sqldata: + sqlsystem: From 33cf0c198e1c68589870d311e8c751b08ace0a48 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sun, 16 Jan 2022 15:21:12 +0100 Subject: [PATCH 23/30] Updated docker-compose.sqlsrv.yaml with comment about Apple M1. Updated docker-compose.sqlsrv.yaml with comment aboutthe fact that the image does not work on Apple M1 hardware. See: https://github.com/microsoft/mssql-docker/issues/734. --- docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml b/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml index aebfaba7..c4ee7af4 100644 --- a/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml +++ b/docker-compose-services/sqlsrv/docker-compose.sqlsrv.yaml @@ -6,6 +6,7 @@ services: hostname: ddev-${DDEV_SITENAME}-sqlsrv # For possible options: https://hub.docker.com/_/microsoft-mssql-server. + # This does not yet work with Apple M1. See: https://github.com/microsoft/mssql-docker/issues/734 image: mcr.microsoft.com/mssql/server:2019-CU12-ubuntu-20.04 user: root From 1f0f77aab1dbfbbaba6319bc80cce4f084308a6f Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 26 Feb 2022 13:30:21 +0100 Subject: [PATCH 24/30] Added the web-build Dockerfile --- docker-compose-services/sqlsrv/Dockerfile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 docker-compose-services/sqlsrv/Dockerfile diff --git a/docker-compose-services/sqlsrv/Dockerfile b/docker-compose-services/sqlsrv/Dockerfile new file mode 100644 index 00000000..a8c3bab3 --- /dev/null +++ b/docker-compose-services/sqlsrv/Dockerfile @@ -0,0 +1,21 @@ +ARG BASE_IMAGE +FROM $BASE_IMAGE + +ENV PATH="${PATH}:/opt/mssql-tools/bin" +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests apt-utils curl gnupg2 ca-certificates + +RUN curl -sSL -O https://packages.microsoft.com/keys/microsoft.asc +RUN apt-key add > "/etc/php/${v}/mods-available/sqlsrv.ini"; \ + echo 'extension=pdo_sqlsrv.so' >> "/etc/php/${v}/mods-available/pdo_sqlsrv.ini" ; \ +done +RUN phpenmod sqlsrv pdo_sqlsrv From d9877e6e3a35a34bc03ac707708a09952d44d8c7 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sat, 26 Feb 2022 13:32:25 +0100 Subject: [PATCH 25/30] Removed a number of post start command from README.md --- docker-compose-services/sqlsrv/README.md | 42 +----------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index 75e36d34..9c1832db 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -41,48 +41,8 @@ The PHP extensions for SQL Server CANNOT be installed by adding them to the `web ```yaml hooks: post-start: - - exec: "curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -" - - # For the next line: change the Debian version number to the one that DDEV is - # using. For DDEV v1.17.7 is it Debian version 10. Run the following command - # to get the information: "ddev exec lsb_release -a". You shall probably need - # to remove the post startup hooks to make the webserver boot in order to run - # the command. - - exec: sudo bash -c 'curl -s https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list' - - - exec: sudo apt-get -y update - - # When you have warnings or errors with multiarch, then please uncomment the - # following lines. - #- exec: wget http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/multiarch-support_2.27-3ubuntu1.4_amd64.deb - #- exec: sudo apt-get install ./multiarch-support_2.27-3ubuntu1.4_amd64.deb - - - exec: sudo apt-get -y install dialog apt-utils - - exec: sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools - - exec: echo 'export PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bashrc' + - exec: echo export PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bashrc - exec: source ~/.bashrc - - exec: sudo apt-get -y install unixodbc-dev - - exec: sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config - - exec: sudo apt-get -y install php-pear php-dev - - exec: sudo pecl channel-update pecl.php.net - - exec: sudo pecl install sqlsrv - - exec: sudo pecl install pdo_sqlsrv - - # For the next 3 lines: change the PHP version number to the one set in - # the variable: "php_version". The currently used PHP version is "8.0". - - exec: "echo 'extension=sqlsrv.so' | sudo tee /etc/php/8.0/mods-available/sqlsrv.ini" - - exec: "echo 'extension=pdo_sqlsrv.so' | sudo tee /etc/php/8.0/mods-available/pdo_sqlsrv.ini" - - exec: sudo phpenmod -v 8.0 sqlsrv pdo_sqlsrv - - # When you get warnings or errors that there is something wrong with - # uploadgrogress, then please uncomment the following lines. - #- exec: sudo pecl install uploadprogress - #- exec: "echo 'extension=uploadprogress.so' | sudo tee /etc/php/8.0/mods-available/uploadprogress.ini" - #- exec: sudo phpenmod -v 8.0 uploadprogress - - # For the next line: change the word "nginx" to "apache2" when the variable - # "webserver_type" is set to "apache-fpm". - - exec: killall -USR2 nginx php-fpm # Test that the installation of the PHP extensions for the SQL Server were # successful. From 06cb20088481fba50d2bc1a28b1e37e0287d8a3b Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sun, 27 Feb 2022 10:32:34 +0100 Subject: [PATCH 26/30] Added the copying of the Dockerfile to .ddev/web-build --- docker-compose-services/sqlsrv/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index 9c1832db..b9ceae6a 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -5,8 +5,9 @@ Using SQL server from Microsoft. ## Installation 1. Copy `docker-compose.sqlsrv.yaml` to your project's `.ddev` directory. -2. Copy the full post start hook commands to your project's `config.yaml` or add them to `config.sqlsrv.yaml`. -3. *(optional)* For Drupal 9+ projects: copy `install-drupal-regex-function.sh` 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 From 4d12974e324158ce499e4cb492a1b307f40e49af Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sun, 27 Feb 2022 11:05:14 +0100 Subject: [PATCH 27/30] Commented out the last line of install-drupal-regex-function.sh --- docker-compose-services/sqlsrv/install-drupal-regex-function.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-services/sqlsrv/install-drupal-regex-function.sh b/docker-compose-services/sqlsrv/install-drupal-regex-function.sh index 632183df..2ed5baa9 100644 --- a/docker-compose-services/sqlsrv/install-drupal-regex-function.sh +++ b/docker-compose-services/sqlsrv/install-drupal-regex-function.sh @@ -52,4 +52,4 @@ ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $u ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE ASSEMBLY Regex from \"/RegEx.dll\" WITH PERMISSION_SET = SAFE'" ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE FUNCTION dbo.REGEXP(@pattern NVARCHAR(100), @matchString NVARCHAR(100)) RETURNS bit EXTERNAL NAME Regex.RegExCompiled.RegExCompiledMatch'" -**Contributed by [@drupal-daffie](https://github.com/drupal-daffie)** +# **Contributed by [@drupal-daffie](https://github.com/drupal-daffie)** From 824508f5594f00443812c0e81ba53a824612ab1f Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Sun, 27 Feb 2022 11:58:32 +0100 Subject: [PATCH 28/30] Remove check for working sqlsrv and pdo_sqlsrv PHP extensions --- docker-compose-services/sqlsrv/README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index b9ceae6a..e76a4089 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -44,11 +44,6 @@ hooks: post-start: - exec: echo export PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bashrc - exec: source ~/.bashrc - - # Test that the installation of the PHP extensions for the SQL Server were - # successful. - - exec: "echo 'When the installation was succesful, the following strings: \"pdo_sqlsrv\" and \"sqlsrv\" should appear. Each on its own line.'" - - exec: "php -m | grep 'sqlsrv'" ``` The minimum required PHP version the these extensions is PHP 7.3. For more information about these extension, see: [MS SQL driver for PHP](https://github.com/microsoft/msphpsql). From fb161d8b76d7d5194b8aa168dae3c565c9abfde4 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Mon, 28 Feb 2022 22:22:58 +0100 Subject: [PATCH 29/30] Added 2 links for MS driver for PHP --- docker-compose-services/sqlsrv/README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docker-compose-services/sqlsrv/README.md b/docker-compose-services/sqlsrv/README.md index e76a4089..c3117d10 100644 --- a/docker-compose-services/sqlsrv/README.md +++ b/docker-compose-services/sqlsrv/README.md @@ -94,11 +94,13 @@ Future enhancements (PR's welcome here) include: ## Links with useful information * [SQL Server docker hub](https://hub.docker.com/_/microsoft-mssql-server) -* [Installing the ODBC driver for SQL Server](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15) -* [Installing the ODBC driver for SQL Server Tutorial](https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15) -* [The SQLCMD utility](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15) -* [The SQL Server on Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-overview?view=sql-server-ver15) -* [The password policy](https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver15) -* [The SQL Server environment variables](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver15) +* [Installing the ODBC driver for SQL Server](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server) +* [Installing the ODBC driver for SQL Server Tutorial](https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac) +* [Installation tutorial for MS drivers for PHP](https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac) +* [The SQLCMD utility](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility) +* [The SQL Server on Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-overview) +* [The password policy](https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy) +* [The SQL Server environment variables](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables) * [Beakerboy's Drupal Regex database function](https://github.com/Beakerboy/drupal-sqlsrv-regex) * [Drupal's module for the SQL Server](https://www.drupal.org/project/sqlsrv) +* [Github MS drivers for PHP](https://github.com/microsoft/msphpsql) From d7e87ebb30891f8b40c0aa3b0c3b476b48787103 Mon Sep 17 00:00:00 2001 From: drupal-daffie Date: Tue, 10 May 2022 13:01:16 +0200 Subject: [PATCH 30/30] Updated Dockerfile for setting the PHP version. --- docker-compose-services/sqlsrv/Dockerfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docker-compose-services/sqlsrv/Dockerfile b/docker-compose-services/sqlsrv/Dockerfile index a8c3bab3..bbc5f8f3 100644 --- a/docker-compose-services/sqlsrv/Dockerfile +++ b/docker-compose-services/sqlsrv/Dockerfile @@ -12,10 +12,12 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg: RUN ACCEPT_EULA=Y DEBIAN_FRONTEND=noninteractive apt-get install -y msodbcsql18 mssql-tools -RUN pecl channel-update pecl.php.net && pecl install sqlsrv && pecl install pdo_sqlsrv +# Change the PHP version to what you want. It is currently set to version 8.0. +RUN pecl channel-update pecl.php.net +RUN pecl -d php_suffix=8.0 install sqlsrv +RUN pecl -d php_suffix=8.0 install pdo_sqlsrv + +RUN echo 'extension=sqlsrv.so' >> "/etc/php/8.0/mods-available/sqlsrv.ini" +RUN echo 'extension=pdo_sqlsrv.so' >> "/etc/php/8.0/mods-available/pdo_sqlsrv.ini" -RUN for v in 7.4 8.0 8.1; do \ - echo 'extension=sqlsrv.so' >> "/etc/php/${v}/mods-available/sqlsrv.ini"; \ - echo 'extension=pdo_sqlsrv.so' >> "/etc/php/${v}/mods-available/pdo_sqlsrv.ini" ; \ -done RUN phpenmod sqlsrv pdo_sqlsrv