- 注册
- 选择 php 和 AWS US East 机房(目前只有这个机房能运行 af tunnel),给应用起个名字:myApp
- 在 Services 下添加 mysql, 数据库名选择 mydb
$ af login
Attempting login to [https://api.appfog.com]
Email: [email protected]
Password: ***********
$ af tunnel
1: mydb
Which service to tunnel to?: 1
Deploying tunnel application 'caldecott'.
Uploading Application:
Checking for available resources: OK
Packing application: OK
Uploading (1K): OK
Push Status: OK
Binding Service [eovent]: OK
Staging Application 'caldecott': OK
Starting Application 'caldecott': OK
Getting tunnel connection info: OK
Service connection info:
username : uo55VV5V5BT6H
password : pfdsfsafasfasfsa
name : ddfdsafdafdsarr3fdafwr3rfaf2r33rdfs
Starting tunnel to mydb on port 10000.
1: none
2: mysql
3: mysqldump
Which client would you like to start?:1
Open another shell to run command-line clients or
use a UI tool to connect using the displayed information.
Press Ctrl-C to exit...
上面那个窗口就不要动了,另开一个窗口,把 mysql 备份文件导入数据库,我在 Mac 下,用的 XAMPP,mysql 命令不在 PATH 中,所以用了全路径:
$ /Applications/XAMPP/xamppfiles/bin/mysql --protocol=TCP --host=localhost --port=10000 --user=uo55VV5V5BT6H --password=pfdsfsafasfasfsa ddfdsafdafdsarr3fdafwr3rfaf2r33rdfs < /tmp/mydata.sql
打开配置文件,加入前两行后,就可以用变量的方式代替数据库信息:
$services = getenv('VCAP_SERVICES');
$services_json = json_decode($services,true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"];
$host = $mysql_config["hostname"].':'.$mysql_config["port"]
$user = $mysql_config["username"];
$db = $mysql_config["name"];
$password = $mysql_config["password"];
如果用个 php 文件简单地把上面的信息 echo 出来,也可以不用变量,直接用下面的信息:
host: us33-user33.crfdasfsdytfds.us-east-1.rds.amazonaws.com
port: 3306
user: uo55VV5V5BT6H
password: pfdsfsafasfasfsa
db: ddfdsafdafdsarr3fdafwr3rfaf2r33rdfs
- 配置好 config.php 文件后,最后在代码文件夹 af update 就可以了