开发者

Have a Heroku app's DATABASE_URL point to a Media Temple GS database

开发者 https://www.devze.com 2023-02-02 11:10 出处:网络
I wasn\'t sure where to post this so I thought this might be a good place. I would like to know if it\'s possible to have a Heroku app\'s DATABASE_URL point to a Media Temple GS database? I have alrea

I wasn't sure where to post this so I thought this might be a good place. I would like to know if it's possible to have a Heroku app's DATABASE_URL point to a Media Temple GS database? I have already tried setting up a connection to my mt database's external domain (while allowing heroku's ip addresses in mt's acceptable external ip addresses) using the command: "heroku config:add DATABASE_URL=mysql://username:password@host/databasename --app appname" and running "heroku rake db:migrate --app appname", but it doesn't seem to work. Any ideas? Here is what the error looks like:

rake aborted开发者_如何学C!

Can't connect to MySQL server on 'example.com' (111)


Connecting to a shared heroku database from machines outside of Heroku is not supported. but it is possible to connect to a dedicated heroku database using their pg:ingress feature.

This is essentially a security and resourcing feature in the heroku stack. If you need to connect to external data tiers you'd need to build an API for it and work via that.

Edit: Theres a nifty looking gem being worked on at https://github.com/nbudin/heroku_external_db


Connecting to a shared heroku database from machines outside of Heroku is not supported. but it is possible to connect to a dedicated heroku database using their pg:ingress feature.

This is essentially a security and resourcing feature in the heroku stack. If you need to connect to external data tiers you'd need to build an API for it and work via that.


The problem does not lie with Heroku, I've been able to successfully connect to external databases with my hosting provider in the past. You need to use this notation:

    $pdoconn = new PDO('mysql:host=' . $host . ';dbname=' . $db, $user, $pwd, array( PDO::ATTR_PERSISTENT => false));

Media temple on the other hand have a policy of only allowing specific IP addresses to connect to the mysql instance runninng in your Grid Server from an external location.

You can alter that list by following these steps:

Your Domain > Admin > Manage Databases > Users & Settings > External Databases > Add IP

The problem here relies mainly on determining your Heroku server's IP address exposed to MediaTemple, as address will change over time.

To determine your exposed IP you can create a new file ipcheck.php with contents as follows:

<?php
$homepage = file_get_contents('http://www.whatsmyip.org/');
echo $homepage;
?>

Then browse this page after deploying to your heroku instance, you will see that your IP is pretty much different with every request.

The only way around this is by provisioning a static IP through the Proximo addon or similar, then configuring MediaTemple to allow external connections from that IP.

Its probably cheaper to run a hostgator server for your mysql database (hostgator mysql database allows external connections from anywhere).

0

精彩评论

暂无评论...
验证码 换一张
取 消