有的时候我们的WEB服务器并不在本地服务器上,这就需要与远程数据库连接,今天我就说一下我是怎么让用famp5.1.0搭建的服务器与远程服务器连接的。

famp5.1.0安装好后是以网页形式管理服务器的,当然里面也包括的有PHPMYADMIN,所以famp5.1.0与远程服务器的连接不仅仅是fanp5.1.0,还包括了PHPMYADMIN与远程数据库的连接。所以在实现famp5.1.0与远程数据库连接的同时也要让PHPMYADMIN与远程数据库连接。

下面我正式开始说说我的做法:
因为mysql的默认用户root是不能远程控制的所以我们要先在远程数据库上面建立一个用户名为famp的用户,密码为famp_pw(当然你也可以自己改别的,这里我用的都是famp5.1.0默认用户名与密码)。命令如下:

mysql> GRANT ALL PRIVILEGES ON *.* TO ‘famp’@'localhost’ IDENTIFIED BY ‘famp_pw’ WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘famp’@'%’ IDENTIFIED BY ‘famp_pw’ WITH GRANT OPTION;

上面建立的是一个和root本地权限用户权限相同的用户,不过它可以远程控制数据库。
接着在建立一个名为sherry,密码为891028的用户用于数据库的远程控制。(当然你也可以直接用famp这个用户也行)

mysql> GRANT ALL PRIVILEGES ON *.* TO ’sherry’@'localhost’ IDENTIFIED BY ‘891028′ WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO ’sherry’@'%’ IDENTIFIED BY ‘891028′ WITH GRANT OPTION;

这个用户的权限和上面一个的相同。
先在我们在回到装famp5.1.0的服务器里。
首先要做的就是把本地数据库中的名为famp的数据库导出,因为后面要用到。
下来转到famp5.1.0的安装目录:

#cd /usr/loacl/famp/

编辑config.php文件

#ee config.php

内容如下:

<?php
/**
* 作者:爱洞特漏
* 说明:未经本人允许,不得将此软件用于任何商?用途!
*/
if(!defined(’IN_FAMP’)) exit(”Hi, Thank you for choose FAMP!”);

$dbhost = ‘192.168.56.103′;// 数据库服务器
$dbuser = ‘famp’;// 数据库用户?
$dbpw = “891028″;// 数据库苈
$dbname = ‘famp’;// 数据库?

$language = ‘chinese’;//语?

?>

把上面的localhost改成你的远程数据库服务器IP地址,如:
$dbhost = ‘202.112.56.90′;// 数据库服务器
下面的数据库用户名及密码就是刚才我们建立的数据库的用户名与密码,数据库名最好就不要改了,因为后面还要用到。
退出保存。
再转到phpMyAdmin目录下:

#cd cd /usr/loacl/famp/phpMyAdmin/

编辑config.inc.php文件

#ee config.inc.php

内容如下:

<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* phpMyAdmin sample configuration, you can use it as base for
* manual configuration. For easier setup you can use setup/
*
* All directives are explained in Documentation.html and on phpMyAdmin
* wiki .
*
* @version $Id: config.sample.inc.php 12304 2009-03-24 12:56:58Z nijel $
*/

/*
* This is needed for cookie based authentication to encrypt password in
* cookie
*/
$cfg['blowfish_secret'] = ‘cookies’; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! *

/*
* Servers configuration
*/
$i = 0;

/*
* First server
*/
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = ‘cookie’;
/* Server parameters */
$cfg['Servers'][$i]['host'] = ‘localhost’;
$cfg['Servers'][$i]['connect_type'] = ‘tcp’;
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = ‘mysql’;

/* rajk – for blobstreaming */
$cfg['Servers'][$i]['bs_garbage_threshold'] = 50;
$cfg['Servers'][$i]['bs_repository_threshold'] = ‘32M’;
$cfg['Servers'][$i]['bs_temp_blob_timeout'] = 600;
$cfg['Servers'][$i]['bs_temp_log_threshold'] = ‘32M’;

/* User for advanced features */
//$cfg['Servers'][$i]['controluser'] = ’sherry’;
//$cfg['Servers'][$i]['controlpass'] = ‘891028′;
/* Advanced phpMyAdmin features */
// $cfg['Servers'][$i]['pmadb'] = ‘phpmyadmin’;
// $cfg['Servers'][$i]['bookmarktable'] = ‘pma_bookmark’;
// $cfg['Servers'][$i]['relation'] = ‘pma_relation’;
// $cfg['Servers'][$i]['table_info'] = ‘pma_table_info’;
// $cfg['Servers'][$i]['table_coords'] = ‘pma_table_coords’;
// $cfg['Servers'][$i]['pdf_pages'] = ‘pma_pdf_pages’;
// $cfg['Servers'][$i]['column_info'] = ‘pma_column_info’;
// $cfg['Servers'][$i]['history'] = ‘pma_history’;
// $cfg['Servers'][$i]['designer_coords'] = ‘pma_designer_coords’;
/* Contrib / Swekey authentication */
// $cfg['Servers'][$i]['auth_swekey_config'] = ‘/etc/swekey-pma.conf’;

/*
* End of servers configuration
*/

/*
* Directories for saving/loading files from server
*/
$cfg['UploadDir'] = ”;
$cfg['SaveDir'] = ”;

?>

把上面的localhost改成你的数据库服务器IP地址就行了。
现在我们就可以用phpMyAdmin打开你的数据库了。
在浏览器地址栏输入你装famp5.1.0的服务器地址加端口号8888和phpMyAdmin的目录phpMyAdmin,即:
http://你的IP地址:8888/phpMyAdmin/
现在到了数据库的登录界面,输入刚才建立的sherry用户名与密码进入数据库管理界面,然后导入刚才导出的famp数据库,导入成功后就可以使用famp5.1.0了。
在浏览器地址栏输入你装famp5.1.0的服务器地址加端口号8888,即:
http://你的IP地址:8888/
现在就可以使用famp了,里面的数据库连接也可以使用。
至此,让famp5.1.0与远程数据库连接就做好了。

标签: none

添加新评论