PHP 7.4 安裝 PHP SQL Server 2008 驅動指南

      在〈PHP 7.4 安裝 PHP SQL Server 2008 驅動指南〉中尚無留言

參考來源 : https://docs.microsoft.com/zh-tw/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15

系統環境:

– Ubuntu 18.04

– SQL SQL Server 2008 Express

– PHP 7.4

安裝 ODBC 套件

sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17
# optional: for unixODBC development headers
sudo apt-get install -y unixodbc-dev

安裝 PHP DEV 套件

sudo apt install php7.4-dev
sudo apt install php7.4-xml

安裝 php 驅動

版本來源: https://github.com/Microsoft/msphpsql/releases

sudo pecl install sqlsrv-5.7.1preview
sudo pecl install pdo_sqlsrv-5.7.1preview
sudo su
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.4/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.4/mods-available/pdo_sqlsrv.ini
exit
sudo phpenmod -v 7.4 sqlsrv pdo_sqlsrv

Docker 的 Dockerfile 檔案 (Nginx + PHP-FPM)

FROM --platform=linux/amd64 ubuntu:18.04

## 基本時區設定
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Taipei
RUN apt-get update

## 安裝 nginx
RUN apt-get install -y lsb-release
RUN apt-get install -y nginx

## 安裝 php
RUN apt-get install -y curl apt-transport-https
RUN apt-get -y install software-properties-common
RUN add-apt-repository ppa:ondrej/php
RUN apt-get update
RUN apt-get install -y php7.4 php7.4-fpm php7.4-dev php7.4-xml php7.4-intl php7.4-dev

## 安裝 ODBC
RUN apt-get install -y gnupg2
RUN apt-get install -y curl apt-transport-https wget
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17

## 安裝 php pdo 驅動
RUN apt-get install -y unixodbc-dev
RUN pecl install sqlsrv-5.7.1preview
RUN pecl install pdo_sqlsrv-5.7.1preview
RUN printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.4/mods-available/sqlsrv.ini
RUN printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.4/mods-available/pdo_sqlsrv.ini
RUN phpenmod -v 7.4 sqlsrv pdo_sqlsrv

## 設定 nginx
COPY ./entrypoints/nginx-php-entrypoint.sh /etc/entrypoint.sh

RUN chmod +x /etc/entrypoint.sh

EXPOSE 80

ENTRYPOINT ["/etc/entrypoint.sh"]

entrypoint.sh 內容

#!/bin/bash
service nginx start
/etc/init.d/php7.4-fpm
tail -f /dev/null

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *