Remote connection to MongoDB server using Codeigniter - php

I am creating an API using MongoDB and Codeigniter. I want to connect to my database using an IP-address (not working) instead of using localhost (working fine). Because I need to have the MongoDB on a seperate server.
I tried to just change from localhost to the IP-address in the configuration file for the Codeigniter library but then I cannot connect.
I am using this Ci MongoDB library: https://github.com/alexbilbie/codeigniter-mongodb-library
How can I do this?

Perhaps you need more info to know what the problem is.
You may specify mongo_supress_connect_error CodeIgniter configuration variable to false to enable verbose output of connection problem error.

I am not a mongo db expert. But I could definitely say that you would need to use a host-name for the connections rather than using an ip-address.
The solution to the problem will be to add your remote server's ip address in the hosts file. In ubuntu, you could find it in /etc/hosts
edit like
10.xxx.xxx.xxx your-server-name
and save it
then you can always connect by replacing localhost with "your-server-name" (that you gave in hosts) in your syntax where you initiate your mongo db connection.
Guess this might not help you as you would have figured it out already. But might help someone who is searching for a similar question.

Related

connect webpack devserver (HMR) with PHP project running with virtual host

Currently, I developing a WordPress plugin with React frontend.
I tried to connect my backend (PHP) running on a virtual host with webpack devserver with hot module replacement (HMR).
Is there any config how to do it.
note: I tried with devserver proxy but cant figure it out.
Thanks in advance.
Getting HMR is always complicated for custom setup like these. Theoretically, this is pretty simple. You simply need to run the webpack-dev-server with the HMR module. On your PHP file, make sure it uses the JS file generated from webpack-dev-server. The code to refresh is bundled in the JS file so it should work.
However, the devil is in the details. You'll need to make sure the communication between your page and webpack-dev-server works without issue. Monitor your websocket network request and make sure they communicate as expected.
An issue you'll probably encounter is security since the websocket connection is expecting a different host. In this case, you can use config from the following answer: I am getting an "Invalid Host header" message when connecting to webpack-dev-server remotely
Another issue could be that the JS file tries to connect to the wrong location. Eg: It thinks that your host is where the websocket connection is. If this is the case, you can use the public setting. See here for documentation: https://webpack.js.org/configuration/dev-server/#devserverpublic
To me this is akin to running with a reverse proxy. You can see this discussion to understand the problem: https://github.com/webpack/webpack-dev-server/issues/804
There might be other problems. You just need to check the websocket connection and make sure they communicate without problems
How you refer to the generated js file is a separate problem. A simple example would be setting the port to 8081 and bundling the js file into bundle.js. Then in your php code, refer to it as http://localhost:8081/bundle.js

I want to use PHP to query my current domain SQL server

I have tried everything
Wamp and XAMPP only provide thier own local server and wont let me specify my own server
I have tried IIS and PHP but it doesnt work at all
I would like a simple way to get my SQL server to use PHP in my domain, i dont need it to be remote access yet
Appreciate some hand holding at this point :(
Thanks
Hi thanks for replying
I have explained below what everything meant by using xammp or want iis and php
The server I have is on the Microsoft SQL server management studio
All of the all in one installers will just user local Host and thier own server and database I want to use mine.
Whenever I try using MySQL connection it says it has activley refused connection.
I've added my credentials into the security section on the server. Allowed remote login and specified ports on the server manager program.
Why isn't there a simple step by step program to enable php use on my server and or connect it to my online site..

Can not connect to my mysql database

I have been recently using "localhost" as my mysql database, and now i want to update my website to web.
I took free hosting at "serversfree.com" and uploaded all my web files there.Now i have problem.I made mysql database on that website, and uploaded my mysql database from localhost.
I can go to that server and list all files i have in that mysql database, but when i want to connect my .php documents i don't know how.What to put under "hostname" (i was recently using only localhost).Do i need to put a link where my web mysql database is?
Or i need to put a link where my website is?
I tried both but didn't worked for me
Most web hosts I've used have MySQL running on the same box so I usually can keep localhost as the server.
Your host should have some documentation on where to point the server to.
Check if your database credentials, are from a valid user in that database..
What hostname did you use to upload your mysql database from localhost? It would be the same hostname. Probably mysql.serversfree.com. If their mysql server is on the same subdomain then you can use localhost as well. To connect your php scripts to a mysql server you need to use the hostname of the mysql server, not the hostname of your http server.
If your mysql is running in the same server then you can use localhost or 127.0.0.1 but if mysql is in another server probably you need remote connections

Configure database connection to run web application anywhere

Using phpmyadmin as my database software I have created mobile web app that uses php to contact the database. I am using phpmyadmin through the university server. My problem is I don't no how I would go about connecting this database to my web application from anywhere in the world. For example if I’m sending a picture to the database via my web application it doesn't have the right connection to phpmyadmin to work outside of the university environment. Can anybody shed some light on how I would go about this in terms of how to connect to phpmyadmin, does it need different credentials from when I’m using it in the university, and below is an example of how it is currently connecting:
$conn = mysql_connect('localhost','USERNAME','PASSWORD') ;
$db = mysql_select_db('B00556019');
Should I be contacting this database differently, like for example changing the localhost to something else? Also can PHP be used to contact the university phpmyadmin database and have my web application working from it? And sorry for the lack of knowledge and detail I'm very much below par with databases. If you need any more details to help understand better let me know. Thank you for your time.
Change your connection code as below :
$conn = mysql_connect('Server ip address','username','password') ;
$db = mysql_select_db('B00556019');
YOu need to change localhost with your server ip.
Note :
Most default installs of MySQL only listen to the local machine.
Look for the bind-address setting in my.cnf on the server, and make sure it's listening on the IP address you're targetting. You may also need to ensure skip-networking isn't switched on!
Alternatively (and less securely!) the following will set it up to listen on all addresses - local and remote:
bind-address = 0.0.0.0
Create a webservice and have your mobile app send data to that. Far more secure.
Then the webservice could write them to the database (which could then be on localhost). Webservice will just take queries write them to the database and provide responses over http back to your mobile app.
You also won't get firewall issues as it will all be over HTTP then.

How to connect a sqlite database in remote host

i have been in a problem to connect to a sqlite database in remote host. I have already gone through alot of research on this, it seems not possible, but using rest api (building web services) can solve this problem. I can't use web services to interact with DB for my application.
Additional details,
is it possible to use path as http://192.168.0.6/computer_a/computer_a.sqlite ?? I have tried this but not working
my code
$db = new SQLite3($comAdb) or die('Unable to open database');
$comAdb -> http://192.168.0.6/computer_a/computer_a.sqlite
Please help
Thanks
No. You have to give a path on a file system.
You could use cURL to download the database, save it locally and then access it.
Can you create a file system mapping to the remote directory, where the second database resides?
Then you can just use ATTACH

Categories