I'm trying to run my application on my local pc. Everything looks perfectly fine on the cloud, it works and connects to MongoDB with the code below:
$services_json = json_decode(getenv("VCAP_SERVICES"),true);
$mongo_config = $services_json["mongodb-1.8"][0]["credentials"];
// Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = $mongo_config["hostname"];
// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = $mongo_config["port"];
// The database you want to work from (required)
$config['mongo_db'] = $mongo_config["db"];
// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = $mongo_config["username"];
$config['mongo_pass'] = $mongo_config["password"];
But since I cannot get the vcap_services from my local pc, I'm using constant values for the connection to connect my app to the remote mongo server on appfog:
// Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = "***";
// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = "***";
// The database you want to work from (required)
$config['mongo_db'] = "db";
// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = "***";
$config['mongo_pass'] = "***";
But when I try to execute the app through http://localhost/my-app, it gave me this error:
Unable to connect to MongoDB: Failed to connect to: ***: Connection timed out
What can be the problem?
* values are deleted for the privacy.
Did you try connecting without the VCAP variables not on localhost but the actual server? AppFog may not give authorization to connect without VCAP variables or something may be wrong on the values you manually get.
I believe this is an authorization problem. Try another cloud service if you cannot handle with it. This is not the only solution.
Related
I have never worked on an oracle database, however, now I need to use php (executed on a different server) to log into the oracle database, but it seems that there is some missing data.
what I have:
Ip address of the server and the port 1521 (ping OK from the server running my php)
data base's name
user with all privileges
the server is perfectly working (another application that is totally relying on the oracle server is perfectly working)
what I don't have:
Service Name
The used Oracle version (more likely 11g but not sure)
any kind of access to the server's system
I tried some guessed service names but I get:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
I tried some other alternatives such using SID but still the same error with SID this time instead of service:
ORA-12505: TNS:listener does not currently know of SID given in connect descriptor
All the other solutions I found require an access to the server to run some scripts or commands, but this is impossible for my case.
The code I use :
$user = 'myUser';
$password = 'myPassword';
$database = 'MY_DB';
$conn=oci_connect($user,$password,
'(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.l.l00)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = someName)
)
)');
if ($conn) {
echo "connected";
}
else
{
echo "not connected";
}
with the error message followed by "not connected" as a result on my browser.
So, is it possible to somehow log into the database? or is it impossible?
the DBA gave me the missing information
I have 2 sql servers. One is for locally, and one is for remote. To connect to my local server I have a .env.php file with my credentials and this is how my code look.
include('./.env.php');
$database = getenv('DB');
$host = getenv('DB_HOST');
$conn = new PDO("mysql:host=$host;dbname=$database", getenv('DB_USER'), getenv('DB_PASS'));
It all works fine as its supposed to. However, I have to also use Heroku and make an app there. I set my variables in Heroku to so it should connect to the remote server and access the other database, however when I open the app with heroku, I just get a http 500 error. I'm not sure what is going on and any help would be appreciated!
I am using XAMPP on my computer. My website is running fine on it. Now I uploaded my files to server using scp. Now I tried to change my connection parameter. I change it
<?php
$host ="104.236.227.173";
$username = "****";
$password = "******";
$database = "****";
#session_start();
?>
The host is the server on which my website is running.
Mysite
But online I am unable to connect to database.
I installed Lamp online.
I have changed settings in my.conf. But it does not work.
I have used the following command too
GRANT ALL ON `database`.* TO username#'%' IDENTIFIED BY 'password';
Please help me to solve this.
As shared using 'localhost' instead the IP address should do the trick. You're accessing the mysql on the same server as the php script is running. Unless the mysql server is configured to be available via IP address, 'localhost' is default behaviour. Glad it helped!
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.
I am trying to get a connection between the PHP and MySQL servers.
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");
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.
Here is what I have done:
Added the ip of the PHP server to the Security Group for MySQL(3306) permissions
Tried to use the internal, external, and private IPs/DNSs of the MySQL Server as the $dbhost variable
Created myuser#% (wildcard) on thy MySQL server
Any ideas or tips would be much appreciated.
I had the same issue - turns out MySQL extension for PHP is NO longer included in PHP5!
"In PHP 5 (updated PHP 5.0.4), the following changes exist. Built in: DOM, LibXML, Iconv, SimpleXML, SPL and SQLite. And the following are no longer built in: MySQL and Overload."
Source: http://php.net/manual/en/install.windows.extensions.php
I've got this working.
I think the big trick was to add this rule to the Security Group:
Type: MySQL
Source: 10.0.0.0/8
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.
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.
I have created three EC2 instances, two of instances are web servers and one instance is a MySQL server. I would like to connect to the MySQL server and retrieve data. I was wondering how I can send a SQL query to the MySQL server.
<?php
$server = "localhost";
$username = "username";
$password = "password";
$database_name = "dbname";
$dbconnect = mysql_connect($server, $username, $password);
if(!$dbconnect)
{
//connection failed to the host
echo "-1";
exit;
}
if(!mysql_select_db($database_name))
{
//cannot connect to database
echo "-2";
exit;
}
?>
I used this php script to connect to the local mysql server. If I want to connect to the remote MySQL server on EC2 instance then do I just simply replace the server address to the IP address (elastic IP address) of the EC2 instance that running MySQL server?
Instead of using the Elastic IP address, use the DNS name associated with the Elastic IP address. It will resolve to the internal IP address associated with the current instance mapped to the Elastic IP address. This saves you in latency and cost.
Here's an article I wrote that describes this approach:
Using Elastic IP to Identify Internal Instances on Amazon EC2
http://alestic.com/2009/06/ec2-elastic-ip-internal
You'll also need to make sure that your MySQL database is listening on 0.0.0.0 instead of 127.0.0.1. Check that your MySQL database server is not accessible from the Internet.
not sure what programming language you want to use, but here is a Getting Started Guide for PHP, but it is just a matter of setting the IP