Host my wordpress site locally using the server database - php

I have set up my wordpress site on my local machine and I would like it to talk to the live mysql database on the server. I accessed the wp-config.php file on my machine and changed the hostname to use the ip address instead of localhost, but it will not work.
What do I need to do?

It could be that your remote database is configured to accept connections only from localhost for security reasons. Most web providers set it up that way. In that case, you have no chance of making this work.
Anyway, even if you would get it to work, you will encounter two problems: It will be awfully slow, and the HTML served by the remote database will contain references to server URLs (as opposed to local ones).
If you need more detailed information, you will need to post any error messages you get from mySQL.

Alternatively, you can try running the mysql command-line utility to connect.
mysql -u username -h server -p wordpress_database
Make sure that works first before attempting to get Wordpress to connect.
My guess is you won't be able to connect due to firewall issues. MySql uses port 3306 by default, so if the server's firewall doesn't allow connections through that port, you'll either have to change the port mysql is using (probably a bad idea if other apps expect to see MySql on that port) or get that port opened on the server (make sure you only open it for local IPs, so someone else can't get to your MySql instance!)

Related

MySQL database access without hostname via PHP

I'm doing this for a couple of years now but I haven't faced anything like this. I'm renting a webserver which has MySQL storage. For security reasons the hosting company refused to give me a host name to connect to the MySQL server from a php script. The reason was that there is an IP filter on he server and one can only connect to it with a whitelisted ip. Is there any solution for this situation like a server sided proxy? Also I do have access to the MySQL server via phpMyadmin.
I did some research and I've found that Navicat has proxy support. Altough it's not free.
Based on your description, it sounds like you have a server with MySQL, PHP and phpMyAdmin all running on the same server. If that's the case then typically the hostname for MySQL will be "localhost", possibly with a port or other code added. It is quite common for web hosting companies to not allow remote MySQL access, though the good ones will have it off by default and let you turn it on either for specific IPs (best) or for "everywhere".
When you are logged into phpMyAdmin, take a look at the very top of the main window and you should see something like Server: localhost or Server: www.example.com:3306 - that is your hostname for any MySQL access, provided the PHP code is running on the same server as phpMyAdmin.
If you actually need to run a program on a different server and access that MySQL database then you are probably out of luck.

MySQL connection to external database using XAMPP

I've stored a web project (PHP, HTML and CSS). I'm working inside opt/lampp/htdocs XAMPP directory, so I can run the .php files using the web browser. One of those .php files tries to connect to an external server MySQL database, but, when run:
mysqli_connect($servername, $username, $userpassword);
it displays the following warning.
*mysqli_connect(): (HY000/2002): Connection refused*
I've tried to access the database with phpmyadmin and the corresponding credentials and it works fine.
So the question is: can I perform a msqli_connect to that external database using XAMPP or I should give up?
Thanks in advance!
Since I cannot comment because of my low points, I am answering here.
I had faced similar issues before, so sharing my experience. All of the comments have suggested valuable points. These are as follows:
Use IP address instead of server name (There may be some DNS cache issue, so it is safe to use IP address).
Make sure the IP address you are using is not being blocked by the server's firewall. If possible configure server's firewall to white-list your IP Address.
The default MySQL port is 3306. Make sure the firewall is configured for allowing outside connection to the port 3306.
Most importantly, make sure the MySQL server must be configured to accept connections externally. If all of the above settings are configured properly then you should grant external access and all privilege to your MySQL User.
GRANT ALL PRIVILEGES ON 'yourDatabase'.* TO 'yourUserName'#'%';
FLUSH PRIVILEGES;
Reference - Another SO Question.

MySQL connect via proxy php

I want to connect to a remote database from my localhost, but the remote DB only allows connections from whitelisted IPs.
Since I'm on a dynamic IP from my ISP, I can't have my home IP whitelisted, because it will just change again.
I have a VPS with full root access and a fixed IP, which is whitelisted.
What I want is to:
Run a php script from my local machine
Connect to the remote database via my VPS
Get the query results back to my local machine for handling
How do I do this?
Having a PHP proxy to execute arbitrary SQL statements from any IP address is really dangerous. I would suggest you abstract the SQL statements into an API, so rather than allowing any query through, you limit it to a specific set of queries to retrieve or update specific data. Your local machine could then just call that API to retrieve or update information.
The key problem you need to solve is finding a host with a static IP address you can add to the whitelist. You say that you have already solved that problem. However you have not mentioned what OS is running on the vps nor the client. If both are Linux, then you can do this with just iptables. If either or both are mswindows then you could use socat, but if it were me, I'd go with a stunnel link between the client and proxy (although if the whitelist on the server is only applied to the mysql connection, you could terminate the stunnel connection on the server and skip the proxy altogether) using client certificate authentication or an SSH tunnel.

connecting to firewalled MS-SQL server that requires Windows Authentication via proxy?

So I need to connect to a mssql server via Windows Authentication from a Unix server. Here are the obstacles:
The db admin created a service account but made it Windows-Auth only, meaning I can't pass the username and password directly to the server to connect.
The admin also added my host's server to the firewall so that it would only accept requests from my host machine.
My host server has mssql enabled via freetds/sybase-dblib, but has the default 'secure-connections: Off' still set.
I have a similar set up on my personal machine, but with secure-connections on, but I can't connect that way since I'm firewalled.
So I'm wondering if it's possible to set up a proxy of sorts on my host so that I can start the connection on my personal machine using my local freeTDS library, but have the request pass to the host which would (in my dream world) not require secure connections to be on but simply would pass the request along so that it came from my non-firewalled host but using the correct authentication method.
If anyone is not familiar with how Windows-Authentication works, it's a type of Kerberos authentication where the client machine makes the request to the remote server so that credentials are never actually sent (and thus can't be compromised by a man-in-the-middle). So I'm very doubtful that this can be done, since at some level my host machine has to do the actual work. But i thought I'd ask since I'm not totally clear on the deeper mechanics and because I really want to get this to happen.
I guess another way of looking at it is I want to use my host as a kind of VPN.
Also, I am working with my host admins to find a more long-term solution but I need to see the database as soon as possible so I can have something working when the problem gets fixed.
Why don't you try SSH port forwarding? Ie. you connect to your host server, and tell it to forward a local port to the sql server. Then you connect on your local machine using localhost:port and your connection will be tunneled over ssh through your host server.
If your local machine is a Windows machine then just download PuTTY and follow these instructions to set up port forwarding : http://www.cs.uu.nl/technical/services/ssh/putty/puttyfw.html.
The question is of course whether your Windows credentials will be passed, but in theory this should work :p.

mysql_connect() works fine on localhost but not when accessing seperate ip

I'm working with my University's Systems Administrators to get a LAMP stack setup for me. I'll need to access this server from several websites that I'm working on and I'm having some issues.
So to keep thing's clear:
LAMP Server URL = https://mysqlserver.edu
School URL = https://schoolsite.edu
When I run mysql_connect() on the LAMP Server it connects fine:
mysql_connect('localhost', 'user', 'password'); Works great!
However, when I run mysql_connect() on the School URL I can't connect:
mysql_connect('mysqlserver.edu', 'user', 'password');
Warning: mysql_connect(): Unknown MySQL server host 'mysqlserver.edu' (1) in /home/content/x/x/x/xxx/html/testconnect.php on line 3
Unknown MySQL server host 'mysqlserver.edu' (1)
What do I need to ask the System Administrator to do in order to give my PHP scripts on external sites access to the MySQL server?
Does the SSL complicate issues?
I appreciate any insight you might be able to provide.
Unknown MySQL server host probably means that your machine cannot resolve to hostname mysqlserver.edu, have you tried connecting via IP address?
After you make sure you are resolving the name, you have to overcome three further barriers:
firewalls as others have shown,
MySQL server configuration which has to allow remote connections and
a user able to connect remotely has to be setup.
MySQL user depends on the computer it is access from. 'root#localhost' is not the same root as 'root#192.168.0.156'. So you have to add the user from the computer you are going to access from. So let say the computer where php script is served is '192.168.156' you need to add a user 'user#192.168.0.156' to the MySQL server and don't forget to set the privilege for that user to access to the database needed.
Hope this helps
It's rare to make a MySQL connection over a public WAN. It's common to take a LAN hop or two but you usually can't cross a firewall for security reasons. That is, incoming TCP connections to port 3306 are being blocked by the firewall or gateway onto the local LAN where mysqlserver.edu is.
The canonical test for this is:
$ telnet mysqlserver.edu 3306
I can predict that this will not work. ("Work" means that it reports "Connected to..." and outputs some gibberish.) You have several choices:
run the database locally, or at least nearby. I mean, it's not a LAMP stack unless it has MySQL. :-) This is what approximately everyone does.
use a tunnel / VPN solution of some kind to get through the firewall and to port 3306
open up 3306 on the firewall. You probably will not get cooperation on this.
Is "skip-name-resolve" option enabled in your my.cnf?

Categories