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.
brew tap brew tap homebrew/dupes brew tap homebrew/versions brew tap homebrew/homebrew-php brew install php70 --with-pear --with-httpd24 --with-cgi echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
Install other required packages
brew install llvm --with-clang --with-clang-extra-tools brew install autoconf
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 HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=y brew install --no-sandbox msodbcsql 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!