How to connect AWS ELB to RDS running MS SQL?

萝らか妹 提交于 2019-12-09 23:45:17

问题


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.

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

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

Here's a classic error report:

--> 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

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


回答1:


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

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

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.

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.)

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

packages: 
  yum:
    php-mssql: []

Beware: Indentation counts in this file.

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.

This is the result of 2 days work, shared here as this info does not seem to exist anywhere.



来源:https://stackoverflow.com/questions/35984661/how-to-connect-aws-elb-to-rds-running-ms-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!