Create PHP apps using SQL Server on macOS
In this section, you will get SQL Server 2017 running on Docker. After that you will install the necessary dependencies to create PHP apps with SQL Server
Step 1.1 Install SQL Server
- In order to run SQL Server on your Mac, we are going to use the SQL Server on Linux Docker Image. For this, you need to install Docker for Mac.
- Configure at least 4GB of memory for your Docker environment, also consider adding multiple cores if you want to evaluate performance. You can do this in the Preferences - Advanced option on the menu bar.
- Next, start a new Terminal prompt and use the following commands to download and start the SQL Server on Linux Docker image. Make sure to use a strong password with special characters.
sudo docker pull microsoft/mssql-server-linux:2017-latest docker run -e 'HOMEBREW_NO_ENV_FILTERING=1' -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux
You now have SQL Server running locally in Docker! Check out the next section to continue installing prerequisites.
Step 1.2 Install Homebrew, PHP and other required packages
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Restart the terminal session.
To install 7.1, or 7.2, replace
email@example.com in the following commands.
brew tap brew tap homebrew/core brew install firstname.lastname@example.org
PHP should now be in your path – run
php -v to verify that you are running the correct version of PHP. If PHP is not in your path or it is not the correct version, run the following:
brew link --force --overwrite email@example.com
- Install other required packages.
brew install autoconf automake libtool
You have successfully installed PHP on your macOS!
Step 1.3 Install the ODBC Driver and SQL Command Line Utility for SQL Server
SQLCMD for Mac is a command line utility that enables you to connect to SQL Server and run queries.
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release brew update brew install --no-sandbox msodbcsql17 mssql-tools
After installing SQLCMD, you can connect to SQL Server using the following command:
sqlcmd -S 127.0.0.1 -U sa -P your_password 1> # You're connected! Type your T-SQL statements here. Use the keyword 'GO' to execute each batch of statements.
This how to run a basic inline query. The results will be printed to the STDOUT.
sqlcmd -S 127.0.0.1 -U sa -P your_password -Q "SELECT @@VERSION"
-------------------------------------------------------- Microsoft SQL Server vNext (CTP2.0) - 14.0.500.272 (X64) Apr 13 2017 11:44:40 Copyright (c) Microsoft Corporation on Linux (Ubuntu 16.04) 1 rows(s) returned Executed in 1 ns
You have successfully installed SQL Server Command Line Utilities on your macOS!