Adding Microsoft SQL Server Support to Laravel Forge

We recently had to setup an existing Laravel Forge project to connect to a Microsoft SQL Server, and it was a struggle with all of the differing guides. We have combined all of the steps that worked for us into this helpful guide.

There are few key pieces of information you need to set up SQL Server on Laravel Forge:

  • Sudo password: This was provided to you once the server was provisioned.
  • Server IP address: This can be found in your Forge dashboard

Connect to Your Forge Server via SSH

Log into your Forge server with the following command in your terminal:

ssh forge@[your-server-ip-address]

Installing the Microsoft SQL Server Dependencies

Run the following commands after connecting to your server via SSH.

Add Microsoft’s public key to your server:

curl | sudo apt-key add -

As root, add the public key again, and load the dependency source:

sudo su
curl | apt-key add -
curl > /etc/apt/sources.list.d/mssql-release.list

Install the dependencies:

sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17
sudo apt-get install unixodbc-dev
sudo pecl install sqlsrv pdo_sqlsrv

Activate the dependencies as root:

sudo su
printf "; priority=20\\n" > /etc/php/7.4/mods-available/sqlsrv.ini
printf "; priority=30\\n" > /etc/php/7.4/mods-available/pdo_sqlsrv.ini

As now as the forge user:

sudo phpenmod -v 7.4 sqlsrv pdo_sqlsrv

Restart PHP in Laravel Forge

Then in Forge, open the server you installed SQL Server on and restart PHP.

  1. Log into your Laravel Forge account
  2. Open the server with SQL Server installed
  3. Scroll to bottom of the page and click on the Restart menu button
  4. Click on the Restart PHP option