Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The process of linking Laravel 7 with Microsoft SQL Server involves the following steps:

  1. Install the PHP SQL Server driver by running the following command:

    sudo apt-get install php7.4-sybase
    
  2. Configure the database connection settings in the .env file. An example configuration for Microsoft SQL Server is:

    DB_CONNECTION=sqlsrv
    DB_HOST=127.0.0.1
    DB_PORT=1433
    DB_DATABASE=mydatabase
    DB_USERNAME=myusername
    DB_PASSWORD=mypassword
    
  3. Install the microsoft/mssql-server-linux package via Composer by running the following command:

    composer require microsoft/mssql-server-linux
    
  4. Add the following line in the config/database.php file under 'default' => env('DB_CONNECTION', 'mysql'),:

    'sqlsrv' => [
       'driver' => 'sqlsrv',
       'host' => env('DB_HOST', '127.0.0.1'),
       'port' => env('DB_PORT', '1433'),
       'database' => env('DB_DATABASE', ''),
       'username' => env('DB_USERNAME', ''),
       'password' => env('DB_PASSWORD', ''),
       'prefix' => '',
    ],
    
  5. Run php artisan migrate command to migrate the database tables.

  6. Run the application and the database configuration should be working correctly with Microsoft SQL Server.

Note: Ensure that the SQL Server driver is enabled in your php.ini file.