Create PHP apps using SQL Server on SLES
In this section, you will get SQL Server 2017 running on SUSE Linux Enterprise Server (SLES). After that you will install the necessary dependencies to create PHP apps with SQL Server
Step 1.1 Install SQL Server
Note: To ensure optimal performance of SQL Server, your machine should have at least 4 GB of memory.
Register the Microsoft Linux repository and add they keys.
sudo zypper addrepo -fc https://packages.microsoft.com/config/sles/12/mssql-server-2017.repo sudo zypper --gpg-auto-import-keys refresh
Install SQL Server.
sudo zypper update sudo zypper install mssql-server
Setup your SQL Server.
sudo /opt/mssql/bin/mssql-conf setup
Microsoft(R) SQL Server(R) Setup To abort setup at anytime, press Ctrl-C. The license terms for this product can be downloaded from http://go.microsoft.com/fwlink/?LinkId=746388 and found in /usr/share/doc/mssql-server/LICENSE.TXT. Do you accept the license terms? If so, please type YES: Please enter a password for the system administrator (SA) account: Please confirm the password for the system administrator (SA) account:
You now have SQL Server running locally on your SLES machine! Check out the next section to continue installing prerequisites.
Step 1.2 Install PHP and other required packages
In the following instructions, replace
with your version of Suse - if you are using Suse Enterprise Linux 15, it will be SLE_15 or SLE_15_SP1, and similarly for other versions. Not all versions of PHP are available for all versions of Suse Linux - please refer to `http://download.opensuse.org/repositories/devel:/languages:/php` to see which versions of Suse have the default version PHP available, or to `http://download.opensuse.org/repositories/devel:/languages:/php:/` to see which other versions of PHP are available for which versions of Suse.
Packages for PHP 7.3 are not available for Suse 12. To install PHP 7.1, replace the repository URL below with the following URL:
https://download.opensuse.org/repositories/devel:/languages:/php:/php71/<SuseVersion>/devel:languages:php:php71.repo. To install PHP 7.2, replace the repository URL below with the following URL:
sudo su zypper -n ar -f https://download.opensuse.org/repositories/devel:languages:php/<SuseVersion>/devel:languages:php.repo zypper --gpg-auto-import-keys refresh zypper -n install php7 php7-pear php7-devel php7-openssl
You have successfully installed PHP on your SLES machine!
Step 1.3 Install the ODBC Driver and SQL Command Line Utility for SQL Server
SQLCMD is a command line tool that enables you to connect to SQL Server and run queries.
The repository URL below is for both Suse 12 and 15.
sudo zypper ar https://packages.microsoft.com/config/sles/12/prod.repo sudo zypper update sudo ACCEPT_EULA=Y zypper install msodbcsql17 mssql-tools echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc sudo zypper install unixODBC-devel
After installing SQLCMD, you can connect to SQL Server using the following command:
sqlcmd -S localhost -U sa -P yourpassword 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 localhost -U sa -P yourpassword -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 (SUSE Linux Enterprise Server 12 SP2) 1 rows(s) returned Executed in 1 ns
You have successfully installed SQL Server Command Line Utilities on your SLES machine!
You have successfully installed the PHP Driver for SQL Server on your SLES machine. You now have everything you need to start writing PHP apps with SQL Server!