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.

Community
  • 1
  • 1
theapache64
  • 10,926
  • 9
  • 65
  • 108
  • 1
    Possible duplicate of [Openshift: How to remote access MySQL?](http://stackoverflow.com/questions/19749599/openshift-how-to-remote-access-mysql) – eis Jul 13 '16 at 06: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. – eis Jul 13 '16 at 06: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. – theapache64 Jul 13 '16 at 06: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. – eis Jul 13 '16 at 06:30
  • @eis http://stackoverflow.com/questions/28523566/access-remote-mysql-serveropenshift-via-codeigniter (this sounds similar to my problem, but it's an unanswered question). – theapache64 Jul 13 '16 at 06:30
  • @eis The problem is I've an application that has a `REST API` written in `Java` and an admin panel written in `PHP`. I think both the `PHP` and `Java` can't work on the same OpenShift server. So that's why we hosted the adminp panel on a different `PHP` server. Now that server needs to access the data that exists in the `OpenShift` server. – theapache64 Jul 13 '16 at 06:34

1 Answers1

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.

Community
  • 1
  • 1
eis
  • 51,991
  • 13
  • 150
  • 199