如何在 Elastic Beanstalk 上安装适用于 SQL Server 的 Microsoft ODBC 驱动程序

发布于 2025-01-16 23:41:29 字数 4045 浏览 4 评论 0原文

我是这个云服务的新手,最近我尝试在 Elastic Beanstalk 上使用 Microsoft SQL Server 部署我的 PHP 项目。当我运行它时,它说:

此扩展需要 Microsoft ODBC Driver for SQL Server。访问以下 URL 以下载适用于 x64 的 SQL Server 的 ODBC 驱动程序:https://go。 microsoft.com/fwlink/?LinkId=163712

我已经尝试使用放在 .ebextensions/pdo_sqlsrv.config 中的配置来安装 ODBC。

###################################################################################################
#### Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#### 
#### Permission is hereby granted, free of charge, to any person obtaining a copy of this
#### software and associated documentation files (the "Software"), to deal in the Software
#### without restriction, including without limitation the rights to use, copy, modify,
#### merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
#### permit persons to whom the Software is furnished to do so.
###################################################################################################

###################################################################################################
#### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
#### INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
#### PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#### HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
#### OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
#### SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
###################################################################################################

commands:
  install_mssql:
    command: |
      #!/bin/bash

      # 0. EXIT if pdo_sqlsrv is already installed
      if php -m | grep -q 'pdo_sqlsrv'
      then
        echo 'pdo_sqlsrv is already installed'
      else
        # 1. Register the Microsoft Linux repository
        wget https://packages.microsoft.com/config/rhel/8/prod.repo -O /etc/yum.repos.d/msprod.repo

        # 2. Install MSSQL and tools
        ACCEPT_EULA=N yum install mssql-tools msodbcsql17 unixODBC-devel -y --disablerepo=amzn*
        sudo yum install unixODBC-utf16
        # The license terms for this product can be downloaded from http://go.microsoft.com/fwlink/?LinkId=746949 and found in /usr/share/doc/mssql-tools/LICENSE.txt . By changing "ACCEPT_EULA=N" to "ACCEPT_EULA=Y", you indicate that you accept the license terms.
        echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
        echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
        source ~/.bashrc

        # 3. Install SQLSRV and its PDO extension, and stop pecl/pecl7 from overwriting php.ini
        cp -f "/etc/php.ini" "/tmp/php.ini.bk"
        pecl7 install sqlsrv pdo_sqlsrv || pecl install sqlsrv pdo_sqlsrv
        cp -f "/tmp/php.ini.bk" "/etc/php.ini"

        # 4. Manually add the extensions to the proper php.ini.d file and fix parameters
        sqlvar=$(php -r "echo ini_get('extension_dir');") && chmod 0755 $sqlvar/sqlsrv.so && chmod 0755 $sqlvar/pdo_sqlsrv.so
        echo extension=pdo_sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini
        echo extension=sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/20-sqlsrv.ini
      fi
      curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/msprod.repo1
      sudo yum remove unixODBC-utf16 unixODBC-utf16-devel
      sudo yum info unixODBC*
      sudo yum install mssql-tools unixODBC-devel
      echo 'export PATH="$PATH:/opt/mssql-tools/bin"' | tee -a ~/.bash_profile && source ~/.bash_profile
      

我一直在搜索并尝试任何命令来安装 ODBC,但仍然不起作用。有没有办法在 Elastic Beanstalk 上安装 ODBC for SQL Server?

I'm new to this cloud services and recently I'm trying to deploy my PHP project using Microsoft SQL Server on Elastic Beanstalk. When I run it, it says :

This extension requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712

I already tried to install ODBC with config that I put at .ebextensions/pdo_sqlsrv.config.

###################################################################################################
#### Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#### 
#### Permission is hereby granted, free of charge, to any person obtaining a copy of this
#### software and associated documentation files (the "Software"), to deal in the Software
#### without restriction, including without limitation the rights to use, copy, modify,
#### merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
#### permit persons to whom the Software is furnished to do so.
###################################################################################################

###################################################################################################
#### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
#### INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
#### PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#### HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
#### OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
#### SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
###################################################################################################

commands:
  install_mssql:
    command: |
      #!/bin/bash

      # 0. EXIT if pdo_sqlsrv is already installed
      if php -m | grep -q 'pdo_sqlsrv'
      then
        echo 'pdo_sqlsrv is already installed'
      else
        # 1. Register the Microsoft Linux repository
        wget https://packages.microsoft.com/config/rhel/8/prod.repo -O /etc/yum.repos.d/msprod.repo

        # 2. Install MSSQL and tools
        ACCEPT_EULA=N yum install mssql-tools msodbcsql17 unixODBC-devel -y --disablerepo=amzn*
        sudo yum install unixODBC-utf16
        # The license terms for this product can be downloaded from http://go.microsoft.com/fwlink/?LinkId=746949 and found in /usr/share/doc/mssql-tools/LICENSE.txt . By changing "ACCEPT_EULA=N" to "ACCEPT_EULA=Y", you indicate that you accept the license terms.
        echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
        echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
        source ~/.bashrc

        # 3. Install SQLSRV and its PDO extension, and stop pecl/pecl7 from overwriting php.ini
        cp -f "/etc/php.ini" "/tmp/php.ini.bk"
        pecl7 install sqlsrv pdo_sqlsrv || pecl install sqlsrv pdo_sqlsrv
        cp -f "/tmp/php.ini.bk" "/etc/php.ini"

        # 4. Manually add the extensions to the proper php.ini.d file and fix parameters
        sqlvar=$(php -r "echo ini_get('extension_dir');") && chmod 0755 $sqlvar/sqlsrv.so && chmod 0755 $sqlvar/pdo_sqlsrv.so
        echo extension=pdo_sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini
        echo extension=sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/20-sqlsrv.ini
      fi
      curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/msprod.repo1
      sudo yum remove unixODBC-utf16 unixODBC-utf16-devel
      sudo yum info unixODBC*
      sudo yum install mssql-tools unixODBC-devel
      echo 'export PATH="$PATH:/opt/mssql-tools/bin"' | tee -a ~/.bash_profile && source ~/.bash_profile
      

I've been searching and trying any command to install the ODBC, but still not working. Is there any way to install ODBC for SQL Server on Elastic Beanstalk?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

下壹個目標 2025-01-23 23:41:29

感谢@Marcin,我可以解决这个问题。

为了解决这个问题,我只需要 ssh 实例并手动执行配置中的命令即可。

Thanks to @Marcin, I can solve this.

To solve this problem, I just need to ssh the instance and execute the command in the config manually.

冰雪之触 2025-01-23 23:41:29

我有同样的问题,手动运行。不幸的是,如果AWS建立了一个新服务器,这将不会被保存,所以仍然试图找出如何自动化它,因为“配置”文件不起作用

sudo su

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#RHEL 7 and Oracle Linux 7
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo

#RHEL 8 and Oracle Linux 8
curl https://packages.microsoft.com/config/rhel/8/prod.repo > /etc/yum.repos.d/mssql-release.repo

#RHEL 9
curl https://packages.microsoft.com/config/rhel/9.0/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 -y msodbcsql18
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y yum install -y mssql-tools18
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo yum install -y unixODBC-devel

I had the same issue, ran this manually. Unfortunately this wont be saved if AWS stands up a new server so still trying to figure out how to automate it as a "config" file doesn't work

sudo su

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#RHEL 7 and Oracle Linux 7
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo

#RHEL 8 and Oracle Linux 8
curl https://packages.microsoft.com/config/rhel/8/prod.repo > /etc/yum.repos.d/mssql-release.repo

#RHEL 9
curl https://packages.microsoft.com/config/rhel/9.0/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 -y msodbcsql18
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y yum install -y mssql-tools18
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo yum install -y unixODBC-devel
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文