如何将AWS ELB连接到运行MS SQL的RDS? [英] How to connect AWS ELB to RDS running MS SQL?

查看:80
本文介绍了如何将AWS ELB连接到运行MS SQL的RDS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AWS在此处和<一个href ="https://forums.aws.amazon.com/thread.jspa?messageID=584121" rel ="nofollow">问与答,说它可以使用PHP实例连接到MS SQL服务器在Elastic Beanstalk上.

AWS clearly states here and in the Q&A that one can connect to an MS SQL server using a PHP instance on the Elastic Beanstalk.

但是,似乎没有办法安装MSSQL驱动程序.

However, there seems to be no way to install the MSSQL drivers.

例如,从ELB命令行安装yum php-mssql会产生错误,指出所需依赖项的版本太高.

For example, installing yum php-mssql from the ELB command line, generates errors stating that the versions of the dependencies needed are too high.

这是经典的错误报告:

->运行事务检查
--->将安装软件包php-common.x86_64 0:5.3.29-1.8.amzn1
->处理冲突:php54-common-5.4.45-1.75.amzn1.x86_64冲突php-common< 5.4.45-1.75.amzn1
->处理冲突:php54-pdo-5.4.45-1.75.amzn1.x86_64冲突php-pdo< 5.4.45-1.75.amzn1
->完成的依赖关系解决方案
错误:php54-pdo与php-pdo-5.3.29-1.8.amzn1.x86_64冲突
错误:php54常见与php-common-5.3.29-1.8.amzn1.x86_64冲突
您可以尝试使用--skip-broken解决此问题
您可以尝试运行:rpm -Va --nofiles --nodigest

--> Running transaction check
---> Package php-common.x86_64 0:5.3.29-1.8.amzn1 will be installed
--> Processing Conflict: php54-common-5.4.45-1.75.amzn1.x86_64 conflicts php-common < 5.4.45-1.75.amzn1
--> Processing Conflict: php54-pdo-5.4.45-1.75.amzn1.x86_64 conflicts php-pdo < 5.4.45-1.75.amzn1
--> Finished Dependency Resolution
Error: php54-pdo conflicts with php-pdo-5.3.29-1.8.amzn1.x86_64
Error: php54-common conflicts with php-common-5.3.29-1.8.amzn1.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest

那么如何在AWS ELB上使用PHP连接到MS-SQL?

So how does one connect to MS-SQL with PHP on AWS ELB?

推荐答案

解决方案是在创建beantalk应用程序时选择Amazon Linux 版本5.3 .

The solution is to choose Amazon Linux version 5.3 when creating your beanstalk application.

环境类型屏幕上选择 PHP 后,下一行显示:

After choosing PHP on the Environment Type screen, the next line says:

AWS Elastic Beanstalk将在64位Amazon Linux 2015.09 v2.0.8上创建一个运行PHP 5.6的环境. 更改平台版本.

AWS Elastic Beanstalk will create an environment running PHP 5.6 on 64bit Amazon Linux 2015.09 v2.0.8. Change platform version.

点击链接更改平台版本,您将会得到一个可能的版本的下拉列表.

Click the link Change platform version and you will be given a drop-down of possible versions.

似乎唯一可用的版本是列表中的最后一个版本:在64位Amazon Linux上为5.3 (我没有尝试32位,可能它也可以工作.)

The only version that seems to work is the last one on the list: 5.3 on 64bit Amazon Linux (I did not try 32bit, bit it probably also works.)

然后创建一个 01.config 文件,该文件位于 .ebextensions 文件夹中,并确保它包含:

Then create a 01.config file that resides in the .ebextensions folder and make sure it includes:

packages: 
  yum:
    php-mssql: []

当心:此文件中的缩进计数.

您现在可以使用如下代码进行连接:

You can now use code like this to connect:

<?php
// connect to database server
$db_conn = mssql_connect("your.rds.amazonaws.com","user","passw0rd")
   or die( "<strong>ERROR: Connection to MYSERVER failed</strong>" );

// select database - only if we want to query another database than the default one
mssql_select_db( "database1", $db_conn )
   or die( "<strong>ERROR: Selecting database failed</strong>" );

// query the database
$query_result = mssql_query( "SELECT * FROM table1", $db_conn )
   or die( "<strong>ERROR: Query failed</strong>" );
$row = mssql_fetch_array($query_result);
echo $row[0];
?>

现在它可以正常工作了.

Now it works as expected.

这是2天工作的结果,在此共享,因为此信息似乎在任何地方都不存在.

这篇关于如何将AWS ELB连接到运行MS SQL的RDS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆