连接从PHP服务器的MySQL服务器在Amazon AWS [英] Connecting From PHP Server to MySQL Server on Amazon AWS
问题描述
我对亚马逊AWS两个服务器设置。一台服务器运行PHP和其他有MySQL的。我可以通过我的终端和MySQL查询浏览器连接到MySQL数据库。
I have two servers setup on Amazon AWS. One server is running PHP and the other has MySQL. I can connect to the MySQL database through my terminal and MySQL Query Browser.
我试图让PHP和MySQL服务器之间的连接。
I am trying to get a connection between the PHP and MySQL servers.
下面是我使用的PHP code(适用于localhost的数据库)
Here is the PHP Code that I am using (works for "localhost" databases)
$dbbase = 'mydb';
$dbuser = 'myuser'; // Your MySQL username
$dbpass = 'mypassword'; // ...and password
$dbhost = 'localhost:3306'; // Internal IP for MYSQL Server
// connect to database
$dblink = mysql_connect($dbhost, $dbuser, $dbpass)
or die ("System Down");
mysql_select_db($dbbase, $dblink)
or die ("Database Down");
这是我的理解,我应该能够这条路线内部的AWS业务,但在这一点上,我会采取任何工作,并建立从那里。
It is my understanding that I should be able to route this an internal AWS traffic, but at this point I will take anything that works and build from there.
下面是我做了什么:
-
增加了PHP服务器的IP安全组为MySQL(3306)的权限
Added the ip of the PHP server to the Security Group for MySQL(3306) permissions
试图使用内部,外部和私有IP地址/ MySQL服务器的DNSS为$ DBHOST变量
Tried to use the internal, external, and private IPs/DNSs of the MySQL Server as the $dbhost variable
创建为myuser @%(通配符)你的MySQL服务器
Created myuser@% (wildcard) on thy MySQL server
任何想法或提示将是非常美联社preciated。
Any ideas or tips would be much appreciated.
推荐答案
我已经得到了这个工作。
I've got this working.
我认为最大的诀窍是添加此规则的安全组:
I think the big trick was to add this rule to the Security Group:
类型:MySQL
来源:10.0.0.0/8
Source: 10.0.0.0/8
我的理解是,10.0.0.0/8涵盖了所有的内部IP地址亚马逊。我想你可以加强这件事,但它有可能为你的服务器改变的内部IP,这样就需要进行管理。
My understanding is that 10.0.0.0/8 covers all internal amazon IPs. I think you could tighten this up, but it is possible for the internal IP of your servers to change, so that would need to be managed.
然后在我的PHP脚本,我用我的MySQL服务器的私有DNS。它应该是这个样子: IP-10-10-100-100.ec2.internal:3306
Then in my PHP script I used the Private DNS of my MySQL Server. It should look something like this: ip-10-10-100-100.ec2.internal:3306
在最后,我认为那就是我所做的一切。
In the end, I think that is everything that I did.
这篇关于连接从PHP服务器的MySQL服务器在Amazon AWS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!