【问题标题】:Connect AWS EC2 instance to RDS MySQL through SSL using PHP使用 PHP 通过 SSL 将 AWS EC2 实例连接到 RDS MySQL
【发布时间】:2020-04-28 23:26:45
【问题描述】:

我无法让我的 AWS EC2 实例通过 SSL 连接到我的 RDS MySQL 数据库。

AWS EC2 Linux 2、Apache 2.4.39、PHP 7.3.10、MySQL 5.7.26。 为了让我驻留在 EC2 中的应用程序在传输过程中拥有安全连接,它必须使用 SSL/TLS。我的理解是,鉴于我的 PHP/MySQL 应用程序,我需要执行下面的代码。为了不影响我的数据库,我建立了一个测试数据库。新用户称为 new-user,有自己的密码。我从https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem 获得了捆绑的 PEM 文件 rds-combined-ca-bundle.pem,并按照该 AWS 页面的指示将其放置在 EC2 服务器上的浏览器可访问目录中。

任何想法为什么在输出中“无法设置私钥文件 `rds-combined-ca-bundle.pem'”?

**In AWS-test-ssl-script.php** ..

20 define ('MYSQLI', 'AWS-test-connect.php');

**In 'AWS-test-connect.php'** ..

12 $dbc=mysqli_init();
13 mysqli_ssl_set($dbc, NULL, "/dir/rds-combined-ca-bundle.pem", NULL, NULL, NULL);
14 mysqli_real_connect($dbc,"DB_server","new-user","password");

16 $res = mysqli_query($dbc, 'SHOW STATUS like "Ssl_cipher"');
17 print_r(mysqli_fetch_row($res));
18 mysqli_close($dbc);

**In AWS-test-ssl-script.php** ..

35 require(MYSQLI);

44 $sel = "CREATE USER IF NOT EXISTS 'new-user'@'%' IDENTIFIED BY 'password' REQUIRE SSL";
45 $sel_qry = mysqli_query($dbc, $sel);
46 mysqli_close($sel_qry);

48 $grant = "GRANT SELECT, INSERT, UPDATE, DELETE
49 ON testdb
50 TO new-user@%";
51 $grant_qry = mysqli_query($dbc, $grant);
52 mysqli_close($grant_qry);```

Output ..
Warning: mysqli_real_connect(): Unable to set private key file `rds-combined-ca-bundle.pem' in AWS-test-connect.php on line 14
Warning: mysqli_real_connect(): Cannot connect to MySQL by using SSL in AWS-test-connect.php on line 14
plus other warnings.



【问题讨论】:

  • 在这里您可以找到解决方案。 enter link description here
  • @Shohag Monzur 使用您引用的代码收到警告:警告:mysqli::real_connect():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14090086:SSL 例程:ssl3_get_server_certificate:certificate在第 14 行的 /path/AWS-test-connect.php 中验证失败

标签: php amazon-web-services ssl mysqli amazon-ec2


【解决方案1】:

PHP mysqli_real_connect() 错误报告找不到指定的 SSL 密钥。

该键在第 13 行的此语句中引用:

 mysqli_ssl_set($dbc, NULL, "/dir/rds-combined-ca-bundle.pem", NULL, NULL, NULL);

该消息表明密钥文件不存在,或者权限不正确。您能否确认该文件可在该目录中访问?

如果 SSL 不重要,您也可以关闭它,看看是否有效。

【讨论】:

  • SSL 关闭没有区别。我用 file_exists() 确认文件存在。我尝试了 660、770 和 664 的权限,组为 apache。您在那里看到任何权限问题吗?此外,pem 文件位置不可浏览器访问,它位于私有目录中。和同样的警告。
  • 你能显示ls -l /dir/rds-combined-ca-bundle.pem和ls -ld /dir的结果吗?
  • -rwxrwx--- 1 root apache 65484 Jan 2 22:12 /dir/rds-combined-ca-bundle.pem and drwxrws--- 11 ec2-user apache 4096 Jan 8 16:33 /dir
  • 我会将文件和目录都设置为 777,然后再试一次。
  • 相同的输出。 Warning: mysqli_real_connect(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /dir/AWS-test-connect.php on line 14
猜你喜欢
  • 1970-01-01
  • 2013-10-08
  • 2014-05-09
  • 2011-06-09
  • 1970-01-01
  • 2018-12-15
  • 2016-05-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多