✋✋✋✋Hello Everybody, welcome to Learn Tech Tips blogspot, nice to see you again,
I am Zidane (my chinese nick name is 雞蛋 🥚🥚🥚🥚🥚🥚🥚🥚)
This topic today is show you detail how to setup sql server driver php (using MAMP) on Window and MacOS environment.
How to setup SQL Server Driver php (XAMP/MAMP) on Window MacOS
Currently when working with PHP, already have many framework support connect with SQL Server Example: Cakephp, Laravel, .... Summary is use PHP connect with SQL Server.
For do that, we need to setup the SQL Server driver first
On this topic I will show you a way on 2 environments
Window
On Window environment will be simple than MACOS
- Step 1: just go inside below link and download the file setup it (current version is 5.10)
- Step 2: go copy extension from SQL Server driver to MAMP/php/ext or XAMP/php/ext
MacOS
When you tried to communicating with Microsoft SQL Server in PHP , you would have noticed it is a lot of a hassle, 👿
- Step 1: Install brew
If you don't have Brew installed, open terminal and run:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The above instruction would install Brew. next run:
brew tap
brew tap homebrew/core
- Step 2: Use MAMP's / XAMP's version of PHP instead of the default on OSX
ex: my version is 7.4.29
export PATH=/Applications/MAMP/bin/php/php7.4.29/bin:$PATH
In order to verify that operation was successfully, let's check the php version on the terminal by runnung the following comand
php -v
You should now see the sme php version on yout MAMP / XAMP on your terminal also.
- Step 3: Install prerequisites (my current version is Microsoft ODBC Driver 17 for SQL Server)
Next, we have to install the prerequsites for the driver by running the following code:
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
brew install msodbcsql17 mssql-tools
In addition, you may need to install the GNU make tools by running:
brew install autoconf automake libtool
-Step 4: Install the PHP drivers for Microsoft SQL Server
Next, we proceed to installing the PHP drivers ex: pdo_sqlsrv.so & sqlsrv.so:
First, we navigate to the php version file in mamp
cd /Applications/MAMP/bin/php/php7.4.29/bin
Next, we download the drivers by running:
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
After the download is complete, we then have to add the name of the newly installed driver extention to the php.ini file to complete the installation process.
* Copy the downloaded driver extension name on the terminal
* Navigate to /Applications/MAMP/bin/php/php7.4.29/config/ on finder.
* Open the php.ini file with any text editor.
* Use the keyboard shortcut command + F to search for the word extension.
* Paste the copied driver extension names below the listed extension.
* Finally restart the MAMP / XMAP in order to restart the Apache server.
In order to verify if the installation was successfull, Open the MAMP localhost page on the browser.
Click on the php info link to get to the phpinfo.php page.
Use the keyboard shortcut command + F to search for the word 'sqlsrv' you should now see the sqlsrv extentions pop up on the page. and you are done.
Reference:
https://stackoverflow.com/questions/4145667/how-to-override-the-path-of-php-to-use-the-mamp-path
https://www.youtube.com/watch?v=KrEIoTBeL70