当前位置:   article > 正文

CentOS 7 使用 Composer 配置 phpmyadmin 并管理多个mysql_centos7 composer

centos7 composer

phpMyAdmin 中文文档

准备工作

  1. CentOS 7 yum 方式安装 php
  2. CentOS 7 安装 Apache HTTP Server
  3. 安装Composer

安装 phpMyAdmin

  1. 按照官方文档 用Composer安装
    安装phpMyAdmin,只需运行:

    composer create-project phpmyadmin/phpmyadmin

  2. 建立网站配置文件

    网站文件按照惯例放在 /var/www/html/phpmyadmin ,如果前面 composer 的时候放在了其他目录,请 mv 到这里

    Apache HTTP Server 的 配置文件放在 /etc/httpd/conf.d ,在这里新建一个phpmyadmin.conf 文件

    ls

     autoindex.conf  php.conf  phpmyadmin.conf  README  test.conf  userdir.conf  welcome.conf
    
    • 1

    cat phpmyadmin.conf

     # 
     # This configuration file enables the default "Welcome" page if there
     # is no default index page present for the root URL.  To disable the
     # Welcome page, comment out all the lines below. 
     #
     # NOTE: if this file is removed, it will be restored on upgrades.
     #
     <LocationMatch "^/+$">
         Options -Indexes
         ErrorDocument 403 /.noindex.html
     </LocationMatch>
     
     <Directory /usr/share/httpd/noindex>
         AllowOverride None
         Require all granted
     </Directory>
     
     Alias /phpmyadmin /var/www/html/phpmyadmin
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
  3. 修改 phpmyadmin 的配置文件

    cd /var/www/html/phpmyadmin/
    cp config.sample.inc.php config.inc.php

    本次准备让 phpmyadmin 管理多个mysql ,使用, mysql 另外存放在其他服务器 ,因此,提前奢姿 mysql 允许其他 ip 访问

    phpmyadmin 网站 IP : 192.168.0.113
    mysql 数据库 IP :192.168.0.111

    简单抄录一下 mysql 操作

     mysql>  GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Password@123' WITH GRANT OPTION;
     Query OK, 0 rows affected, 1 warning (0.01 sec)
     
     mysql> FLUSH PRIVILEGES;
     Query OK, 0 rows affected (0.01 sec)
     
     mysql> select user,host from user;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  4. 配置多个 mysql
    本次简单重复 2 次 192.168.0.111 来模拟结果

按照官方文档 服务器连接设置

服务器连接设置
$cfg['Servers']
类型:	数组
默认值:	一个服务器数组,下面列出了设置

注释

注解

$cfg['Servers'] 数组由 $cfg[‘Servers’][1] 开始。请勿使用 $cfg[‘Servers’][0]。若您需要多个服务器,请复制(包含自增的 $i)多次。您不需要设置所有服务器数组,设置您要修改的值即可。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

网上许多文章建议改写成 $server_hosts = array… 方式,如果您管理的不是很多,就个位数的几台,简单复制代码似乎更简单易懂

vim config.inc.php

......

$cfg['blowfish_secret'] = 'WZH@20230310'; /* 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'] = '192.168.0.111'; //'localhost';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;

# add by wzh 20230310
/**
 * Second server
 */
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '192.168.0.111'; //'localhost';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;

......
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

测试一下

  1. 登录时直接选择哪一个服务器
    在这里插入图片描述

  2. 已经登录,切换服务器

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/428884
推荐阅读
相关标签
  

闽ICP备14008679号