To use Laravel 5 with SQL Server on a Linux platform, you need to follow these steps:
- Install the necessary requirements:
Install PHP and its required extensions using the package manager of your Linux distribution. For example, you can use apt package manager for Ubuntu or yum for CentOS.
Install the SQL Server driver for PHP. You can follow the official Microsoft documentation to install the necessary SQL Server driver for PHP on Linux: https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15
- Create a new Laravel 5 project:
Open your terminal and navigate to the directory where you want to create the Laravel project.
Run the following command to create a new Laravel 5 project: composer create-project --prefer-dist laravel/laravel project-name
- Configure the database connection:
Open the .env file in the root directory of your Laravel project.
Update the following database configuration variables:
- Install the SQL Server driver for Laravel:
Open config/database.php file in your Laravel project.
Under the connections array, add the following code for the SQL Server connection configuration:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
- Run Laravel migrations:
Open your terminal and navigate to the root directory of your Laravel project.
Run the following command to migrate the database tables: php artisan migrate
That's it! You have now set up Laravel 5 with SQL Server on a Linux platform. You can now start using Laravel's database functionalities with SQL Server.