1

I've a Tomcat 7 application running on Openshift server, say myapp. I've also installed MySQL 5.5 cartridge and got the username and password say myUsername and myPassword respectively.

I tried to remotely connect to the database by writing a simple PHP script from my php localhost.

<?php

$link = mysql_connect('127.8.217.2:3306', 'myUsername', 'myPassword');

if (!$link) {
    die('Could not connect: ' . mysql_error());
}

echo 'Connected successfully';

mysql_select_db('myapp',$link) or die ("could not open db".mysql_error());

but the output shows

Could not connect: Access denied for user 'myUsername'@'localhost' (using password: YES)

I don't know what i am missing.

Now the question part.

1) Is it possible to remotely connect to the OpenShift MySQL database using PHP from either localhost or some other server ? If yes, How ?

If there's any question, shoot it into the comments.

EDIT

I've looked at port-forwarding with the help of this thread. but that's not i want.

6
  • 1
    Possible duplicate of Openshift: How to remote access MySQL? Commented Jul 13, 2016 at 6:23
  • though I don't really understand why do you even want to connect locally from php. You have an application with Tomcat 7 running on openshift, so what's the deal with local PHP? Allowing remote DB access for no real reason is usually not a very good idea. Commented Jul 13, 2016 at 6:25
  • @eis I really don't want to connect to the database from the localhost, but from a PHP script hosted in a different server. Commented Jul 13, 2016 at 6:29
  • but why? Why not just have an REST API or similar with your JBoss application and connect to that, like is usually done? Connecting directly to the database remotely is a security risk. Commented Jul 13, 2016 at 6:30
  • @eis stackoverflow.com/questions/28523566/… (this sounds similar to my problem, but it's an unanswered question). Commented Jul 13, 2016 at 6:30

1 Answer 1

1

Based on your explanation as having a need for a both Java and PHP application needing to connect to same server, your options are either

1) doing port forwarding or connecting through SSH, both explained in this link I offered as a duplicate of this, or

2) Trying something explained here and here to create a shared database using a scalable application - however, people in other similar threads, like this one, have claimed that it is "for Openshift/Redhat internet environments, not for regular customers of Openshift" (source). Don't know if it is so, but at least if you go this way, you should test from another openshift gear, not from local computer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.