To resolve the issue with MSSQL not working after updating PHP on Laravel Herd, you need to ensure that the Microsoft ODBC Driver for SQL Server is correctly installed and configured for your PHP version. Here are the steps you can follow:
-
Verify ODBC Driver Installation: Make sure that the ODBC driver is installed correctly. You can check the installed ODBC drivers by running the following command in your terminal:
odbcinst -q -dLook for entries like
ODBC Driver 18 for SQL Server. If it's not listed, you may need to reinstall the driver. -
Reinstall the ODBC Driver: If the driver is not installed, or if you suspect it might be corrupted, reinstall it using Homebrew:
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release brew update brew install --no-sandbox msodbcsql18 -
Check PHP Configuration: Ensure that the
pdo_sqlsrvandsqlsrvextensions are enabled in your PHP configuration. You can check this by running:php -m | grep sqlsrvIf they are not listed, you need to enable them. You can do this by adding the following lines to your
php.inifile:extension=pdo_sqlsrv extension=sqlsrv -
Verify PHP-FPM Configuration: If you are using PHP-FPM, make sure to restart it after making changes to the
php.inifile:brew services restart php -
Check for Compatibility: Ensure that the versions of the ODBC driver and the PHP extensions are compatible with your PHP version. Sometimes, updating PHP can lead to compatibility issues with existing extensions.
-
Test the Connection: Create a simple PHP script to test the connection to your MSSQL database:
<?php $serverName = "your_server_name"; $connectionOptions = [ "Database" => "your_database", "Uid" => "your_username", "PWD" => "your_password" ]; //Establishes the connection $conn = sqlsrv_connect($serverName, $connectionOptions); if ($conn) { echo "Connection established."; } else { echo "Connection could not be established."; die(print_r(sqlsrv_errors(), true)); }Run this script to see if the connection is successful.
By following these steps, you should be able to resolve the issue with MSSQL not working after your PHP update on Laravel Herd. If the problem persists, consider checking the Laravel Herd and PHP logs for more detailed error messages.