English 中文(简体)
Connect to external server by using phpMyAdmin
原标题:

I have phpMyAdmin installed on my local machine. How can I make it connect to an external server?

问题回答

In the config file, change the "host" variable to point to the external server. The config file is called config.inc.php and it will be in the main phpMyAdmin folder. There should be a line like this:

$cfg[ Servers ][$i][ host ] =  localhost ;

Just change localhost to your server s IP address.

Note: you may have to configure the external server to allow remote connections, but I ve done this several times on shared hosting so it should be fine.

To set up an external DB and still use your local DB, you need to edit the config.inc.php file:

On Ubuntu: sudo gedit /etc/phpmyadmin/config.inc.php

The file is roughly set up like this:

if (!empty($dbname)) {

    //Your local db setup

     $i++;
}

What you need to do is duplicate the "your local db setup" by copying and pasting it outside of the IF statement I ve shown in the code below, and change the host to you external IP. Mine for example is:

$cfg[ Servers ][$i][ host ] =  10.10.1.90:23306 ;

You can leave the defaults (unless you know you need to change them)

Save and refresh your PHPMYADMIN login page and a new dropdown should appear. You should be good to go.


EDIT: if you want to give the server a name to select at login page, rather than having just the IP address to select, add this to the server setup:

$cfg[ Servers ][$i][ verbose ] =  Name to show when selecting your server ; 

It s good if you have multiple server configs.

using PhpMyAdmin version 4.5.4.1deb2ubuntu2, you can set the variables in /etc/phpmyadmin/config-db.php

so set $dbserver to your server name, e.g. $dbserver= mysql.example.com ;

<?php
##
## database access settings in php format
## automatically generated from /etc/dbconfig-common/phpmyadmin.conf
## by /usr/sbin/dbconfig-generate-include
##
## by default this file is managed via ucf, so you shouldn t have to
## worry about manual changes being silently discarded.  *however*,
## you ll probably also want to edit the configuration file mentioned
## above too.
##
$dbuser= phpmyadmin ;
$dbpass= P@55w0rd ;
$basepath=  ;
$dbname= phpmyadmin ;
$dbserver= localhost ;
$dbport=  ;
$dbtype= mysql ;

at version 4.0 or above, we need to create one config.inc.php or rename the config.sample.inc.php to config.inc.php ;

In my case, I also work with one mysql server for each environment (dev and production):

/* others code*/  
$whoIam = gethostname();
switch($whoIam) {
    case  devHost :
        $cfg[ Servers ][$i][ host ] =  localhost ;
        break;
    case  MasterServer :
        $cfg[ Servers ][$i][ host ] =  masterMysqlServer ;
        break;
} /* others code*/ 

You can use the phpmyadmin setup page (./phpmyadmin/setup) to generate a new config file (config.inc.php) for you. This file is found at the root of the phpMyAdmin directory.

Just create the config folder as prompted in setup page, add your servers, then click the Save button. This will create a new config file in the config folder you just created.

You now have only to move the config.inc.php file to the main phpMyAdmin folder, or just copy the lines concerning the servers if you got some old configuration done already you d like to keep.

Don t forget to delete the config folder afterwards.

in the config.inc.php, remove all lines with "$cfg[ Servers ]" , and keep ONLY the "$cfg[ Servers ][$i][ host ]"





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签