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 https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
As root
, add the public key again, and load the dependency source:
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
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\nextension=sqlsrv.so\n" > /etc/php/7.4/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.4/mods-available/pdo_sqlsrv.ini
exit
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.
- Log into your Laravel Forge account
- Open the server with SQL Server installed
- Scroll to bottom of the page and click on the Restart menu button
- Click on the Restart PHP option
Sources: