In this section, you will get SQL Server 2017 running on Red Hat Enterprise Linux (RHEL). 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.
curl https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo | sudo tee /etc/yum.repos.d/mssql-server-2017.repo
Install SQL Server.
sudo yum update
sudo yum 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 RHEL machine! Check out the next section to continue installing prerequisites.
Step 1.2 Install PHP and other required packages
To install PHP on Red Hat 7, run the following:
To install PHP 7.2 or 7.3, replace remi-php74
with remi-php72
or remi-php73
respectively in the following commands.
sudo su
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
subscription-manager repos --enable=rhel-7-server-optional-rpms
yum install yum-utils
yum-config-manager --enable remi-php74
yum update
yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc
To install PHP on Red Hat 8, run the following:
To install PHP 7.2 or 7.3, replace remi-7.4
with remi-7.2
or remi-7.3
respectively in the following commands.
sudo su
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf install yum-utils
dnf module reset php
dnf module install php:remi-7.4
subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms
dnf update
dnf install php-pdo php-pear php-devel
You have successfully installed PHP on your RHEL machine!
SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to a database through
SELinux, run the following command:
sudo setsebool -P httpd_can_network_connect_db 1
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.
sudo su
#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version
#RedHat Enterprise Server 6
curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo
#RedHat Enterprise Server 7
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
#RedHat Enterprise Server 8 and Oracle Linux 8
curl https://packages.microsoft.com/config/rhel/8/prod.repo > /etc/yum.repos.d/mssql-release.repo
exit
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts
sudo ACCEPT_EULA=Y yum install msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y yum install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo yum 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 (Red Hat Enterprise Linux)
1 rows(s) returned
Executed in 1 ns
You have successfully installed SQL Server Command Line Utilities on your Red Hat machine!
What version of PHP comes with RHEL 7?
RHEL 7 comes with PHP 5.4.
Does Rhel 8 have PHP 8?
No translations currently exist.
Is RHEL 7 still supported?
RHEL 7.9 will be supported until June 30, 2024. This is the last RHEL 7 minor release as RHEL 7 enters the Maintenance Support 2 phase.
What version of PHP do I have RedHat 8?
Open a bash shell terminal and use the command “php –version” or “php -v” to get the version of PHP installed on the system.