美文网首页centos6.9集合
centos6.9编译安装phpMyAdmin

centos6.9编译安装phpMyAdmin

作者: 马儿爱吃草 | 来源:发表于2017-12-02 23:10 被阅读85次

    获取root权限

    sudo -i
    

    进入下载目录

    cd /www/local/src
    #下载文件
    wget https://files.phpmyadmin.net/phpMyAdmin/4.7.7/phpMyAdmin-4.7.7-all-languages.tar.gz
    # 解压
    tar zxvf phpMyAdmin-4.7.7-all-languages.tar.gz
    # 移动目录
    mv phpMyAdmin-4.7.7-all-languages /www/server/phpMyAdmin
    

    安装 phpMyAdmin

    # 进入对应的安装目录
    cd /www/server/phpMyAdmin
    # 添加配置文件
    cp config.sample.inc.php config.inc.php
    

    编辑配置文件

    vim /www/server/phpMyAdmin/config.inc.php
    

    修改配置文件

    #加密
    $cfg['blowfish_secret'] = 'hh5987fsns08fdr3560s0f0fsfgvd6785'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
    
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
     */
    $i++;
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = '127.0.0.1';
    $cfg['Servers'][$i]['port'] = '3306';
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['AllowNoPassword'] = false;
    

    修改成上面那样

    配置phpMyAdmin

    phpMyAdmin已经安装完毕以后,还需要配置一下Nginx,使我们可以通过浏览器访问phpMyAdmin,新建一个名为phpMyAdmin.conf的配置文件

    vim /www/server/nginx/vhost/phpMyAdmin.conf
    

    内容如下:

    server {
        listen 8080; 
        location ~ \.php$ {
            root           /www/server/phpMyAdmin;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        location / {
            root           /www/server/phpMyAdmin;
            index          index.php;
        }
    }
    

    listen 8080 为端口;

    重载Nginx服务

    service nginx reload
    

    此时我们在浏览器中打开http://<your-ip>:8080就可以访问phpMyAdmin了,端口号为之前配置文件中设置的listen端口8080

    随后出现的身份验证中填入MySQL的账户和密码就可以了。

    安全加固
    MySQL的端口是外网不能访问的,但是安装了phpMyAdmin之后,就在外界暴漏了MySQL的入口,如果不做安全防护,很容易被恶意攻击盗取密码,那数据完全则无从保障。下面将介绍两种方式对phpMyAdmin进行安全加固。

    设置IP白名单

    我们可以通过修改Nginx配置,设置能够访问phpMyAdmin服务的IP,只允许自己电脑进行访问。
    首先通过访问http://www.ip138.com这个网站来得到你现在的公网地址。

    修改Nginx的配置文件

    vim /www/server/nginx/vhost/phpMyAdmin.conf
    

    location ~ \.php$一节增加一行:

    server {
        listen 8080; 
        location ~ \.php$ {
            root           /www/server/phpMyAdmin;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            # 这里填写你的自己电脑的公网地址
            allow          xxx.xxx.xxx.xxx;
        }
        location / {
            root           /www/server/phpMyAdmin;
            index          index.php;
        }
    }
    

    重载Nginx服务

    service nginx reload
    

    这样,除了使用你的电脑之外,其他人就不能访问你的phpMyAdmin了。
    当然,如果没有固定公网ip的就不要用这种方式了!切记!!!!

    使用Basic Auth认证来保护phpMyAdmin

    Nginx提供HTTPBasic Auth功能,配置了Basic Auth之后,需要输入正确的用户名和密码之后才能正确的访问网站。
    我们使用htpasswd来生成密码信息,首先我们先要安装httpd-tools,在httpd-tools中包含了htpasswd命令。

    yum install httpd-tools -y
    

    接下来我们就可以创建用户和密码了,例如创建一个mike的用户,执行命令:

    htpasswd -c /etc/nginx/.htpasswd mike
    

    按照提示输入两次密码之后就创建成功了,然后我们来再次修改Nginx的配置

    vim /www/server/nginx/vhost/phpMyAdmin.conf
    

    添加一下两句
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;

    内容如下:

    server {
        listen 8080; 
        location ~ \.php$ {
            root           /www/server/phpMyAdmin;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        location / {
            root           /www/server/phpMyAdmin;
            index          index.php;
        }
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }
    

    重载Nginx服务

    service nginx reload
    

    重新访问网址http://<your-ip>:8080,会提示输入密码。

    启用高级功能

    1. 本地下载phpMyAdmin-4.7.7-all-languages.tar.gz文件,解压
    2. 登录数据库后台管理,准备导入数据
    3. 找到解压文件夹sql,打开看到一份create_tables.sql文件,导入数据库

    编辑配置文件

    vim /www/server/phpMyAdmin/config.inc.php
    

    修改成如下

    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
     */
    $i++;
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = '127.0.0.1';
    $cfg['Servers'][$i]['port'] = '3306';
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['AllowNoPassword'] = false;
    
    /**
     * phpMyAdmin configuration storage settings.
     */
    
    /* User used to manipulate with storage */
    // $cfg['Servers'][$i]['controlhost'] = '';
    // $cfg['Servers'][$i]['controlport'] = '';
    // $cfg['Servers'][$i]['controluser'] = 'pma';
    // $cfg['Servers'][$i]['controlpass'] = 'pmapass';
    
    /* Storage database and tables */
     $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]['table_uiprefs'] = 'pma__table_uiprefs';
     $cfg['Servers'][$i]['tracking'] = 'pma__tracking';
     $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
     $cfg['Servers'][$i]['recent'] = 'pma__recent';
     $cfg['Servers'][$i]['favorite'] = 'pma__favorite';
     $cfg['Servers'][$i]['users'] = 'pma__users';
     $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
     $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
     $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
     $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
     $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
     $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
    

    重载Nginx服务

    service nginx reload
    

    数据库更换端口时需要重新设置端口

    # 对应的端口
    $cfg['Servers'][$i]['port'] = '3306';
    

    总结

    1. 本文介绍了如何在CentOS 6.9中安装phpMyAdmin,并且介绍了两种方法对phpMyAdmin进行安全加固。
    2. 再次提醒用户,MySQL中的数据如果特别敏感,不要使用phpMyAdmin以及类似的工具管理数据库,不要开放MySQL的端口到外网,而是直接在机器上使用命令行进行管理。

    相关文章

      网友评论

        本文标题:centos6.9编译安装phpMyAdmin

        本文链接:https://www.haomeiwen.com/subject/rddobxtx.html