您的位置:首页 > 编程语言 > PHP开发

使用phpMyAdmin管理MySQL数据库

2015-12-19 18:02 537 查看
一、关闭SELINUX
[root@CentOS ~]# vi /etc/selinux/config
#SELINUX=enforcing        #注释掉
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
#SELINUXTYPE=targeted     #注释掉
SELINUX=disabled          #增加
##关闭iptables
[root@CentOS ~]# service iptables stop
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
[root@CentOS ~]# chkconfig iptables off
[root@CentOS ~]# shutdown -r now  #重启系统

二、编译安装Apache
##检查是否安装apache
# rpm -qa | grep  httpd

##如果有显示任何软件包,则使用rpm –e删除
# rpm -e 软件包名称 --nodeps

##编译安装Apache
[root@CentOS tmp]# ll httpd-2.2.9.tar.gz
-rw-r--r-- 1 root root 6396996 12月 19 18:15 httpd-2.2.9.tar.gz
[root@CentOS tmp]# tar zxf httpd-2.2.9.tar.gz
[root@CentOS tmp]# cd httpd-2.2.9
[root@CentOS httpd-2.2.9]# ./configure
[root@CentOS httpd-2.2.9]# make
[root@CentOS httpd-2.2.9]# make install

##实际上会安装到/usr/local/apache2目录
##配置Apache
[root@CentOS conf]# vi /usr/local/apache2/conf/httpd.conf
ServerAdmin root@localhost                   ##这里可以填实际邮箱,这里不改它
DocumentRoot "/usr/local/apache2/htdocs"     ##这里是放www服务的地方,后面phpMyAdmin就放里面,这里不改它
在#ServerName www.example.com:80后面添加一行:ServerName 192.168.1.109:80
找到DirectoryIndex index.html改为:DirectoryIndex index.html index.php

##设置开机启动
[root@CentOS bin]# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
[root@CentOS bin]# chmod 777 /etc/rc.d/init.d/httpd
[root@CentOS init.d]# vi /etc/rc.d/init.d/httpd
#!/bin/bash
#chkconfig:345 61 61
#description:Apache httpd
[root@CentOS init.d]# chkconfig --add httpd
[root@CentOS init.d]# chkconfig httpd on
##访问http://192.168.1.109/可以看见“It works!”,说明httpd配置没有问题。

三、安装PHP
##注意:php的版本和phpMyAdmin的版本就有关联的。这里我使用phpMyAdmin-4.5就至少需要php5.5以上。
##检查是否安装php
# rpm -qa | grep  php

##如果有显示任何软件包,则使用rpm –e删除
# rpm -e 软件包名称 --nodeps

##安装前.先安装些软件和库文件不然后面会报很多这样,那样的错误!
[root@CentOS php-5.6.16]# yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
[root@CentOS tmp]# yum install php-mysqli

##常见错误
##首先得安装这个东西,不然后面会报:configure: error: xml2-config not found. Please check your libxml2 installation.
[root@CentOS php-5.6.16]# yum install libxml2 libxml2-devel curl-devel

##还得安装openssl,不然会报:configure: error: Cannot find OpenSSL's <evp.h>
[root@CentOS tmp]# yum install openssl openssl-devel
[root@CentOS tmp]# ln -s /usr/lib64/libssl.so /usr/lib/   ##64bit机器做
[root@CentOS tmp]# ll /usr/lib64/libssl.so                ##我32bit的虚拟机,所有根本没有这个目录
ls: 无法访问/usr/lib64/libssl.so: 没有那个文件或目录
[root@CentOS tmp]# ll /usr/lib/libssl.so
lrwxrwxrwx 1 root root 16 12月 19 19:49 /usr/lib/libssl.so -> libssl.so.1.0.1e

##安装libpng,不然后面会报:configure: error: png.h not found.
[root@CentOS php-5.6.16]# yum -y install libpng-devel

##安装libpng,不然后面会报:configure: error: freetype-config not found.
[root@CentOS tmp]# yum install freetype freetype-devel

##编译安装php
[root@CentOS tmp]# ll php-5.6.16.tar.gz
-rw-r--r-- 1 root root 18319620 12月 19 18:15 php-5.6.16.tar.gz
[root@CentOS tmp]# tar zxf php-5.6.16.tar.gz
[root@CentOS tmp]# cd php-5.6.16
[root@CentOS php-5.6.16]# ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-gd \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--enable-xml \
--enable-mbstring \
--with-xmlrpc \
--with-openssl \
--enable-short-tags \
--enable-sockets \
--enable-soap \
--enable-static \
--enable-zend-multibyte \
--with-ttf \
--enable-libfreetype \
--with-curl
[root@CentOS php-5.6.16]# make
[root@CentOS php-5.6.16]# make install
[root@CentOS php-5.6.16]# cp php.ini-development /usr/local/php/etc/php.ini
[root@CentOS bin]# vi /etc/profile
export PATH=/usr/local/php/bin:$PATH
[root@CentOS bin]# . /etc/profile
[root@CentOS bin]# php -v
PHP 5.6.16 (cli) (built: Dec 19 2015 21:41:53)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

##php与Apache整合
[root@CentOS conf]# vi /usr/local/apache2/conf/httpd.conf
找到:AddType application/x-gzip .gz .tgz
在后面添加:AddType application/x-httpd-php .php

四、安装配置PHPMyAdmin
[root@CentOS tmp]# ll phpMyAdmin-4.5.2-all-languages.tar.gz
-rw-r--r-- 1 root root 9670017 12月 18 04:18 phpMyAdmin-4.5.2-all-languages.tar.gz
[root@CentOS tmp]# tar zxf phpMyAdmin-4.5.2-all-languages.tar.gz
[root@CentOS tmp]# mv phpMyAdmin-4.5.2-all-languages /usr/local/apache2/htdocs
[root@CentOS tmp]# cd /usr/local/apache2/htdocs
[root@CentOS html]# mv phpMyAdmin-4.5.2-all-languages phpMyAdmin

##配置phpMyAdmin
[root@CentOS html]# vi phpMyAdmin/libraries/config.default.php
$cfg['PmaAbsoluteUri'] = 'http://192.168.1.109/phpMyAdmin';   //phpMyAdmin所在的地址
$cfg['Servers'][$i]['host'] = '192.168.1.109';   //设定mysql所在的主机名或IP地址,此处通常保持默认的localhost即可
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['user'] = 'root';   //设定mysql的用户名
$cfg['Servers'][$i]['password'] = '123';   //设定mysql的用户密码
$cfg['DefaultLang'] = 'zh-utf-8';   //设定默认语言
##以上参数设置完成后保存退出,重启web服务器。开启浏览器,在地址栏输入http://192.168.1.109/phpMyAdmin/测试一下吧。

五、phpMyAdmin管理多个mysql服务器
方法一,修改phpMyAdmin/libraries/config.default.php
$cfg['AllowArbitraryServer'] = true;
##服务器那里输入:IP:PORT。比如:192.168.1.109:3307
修改前,服务器这个输入框是不存在的,变成true后就显示了,就可以连接多个不同的数据库了。
但是这样修改有一个缺点,如果在多个数据库之间切换,要先退出,重新登录,这样挺烦人,看下面的这个方法。

方法二,同时管理多个mysql服务器。
1,将phpMyAdmin根目录下的config.sample.inc.php,重命名为config.inc.php
[root@CentOS phpMyAdmin]# cp config.sample.inc.php config.inc.php
2,修改config.inc.php文件,写入如下代码:
<?php
//3306
$i=1;
$cfg['Servers'][$i]['host']          = '192.168.1.109';
$cfg['Servers'][$i]['port']          = '3306';
$cfg['Servers'][$i]['user']          = 'root';
$cfg['Servers'][$i]['password']      = '123';

//3307
$i++;
$cfg['Servers'][$i]['host']          = '192.168.1.109';
$cfg['Servers'][$i]['port']          = '3307';
$cfg['Servers'][$i]['user']          = 'root';
$cfg['Servers'][$i]['password']      = '123';

?>

总结:虽然phpMyAdmin能够打开了,但是php的安装还有一些问题。导致phpMyAdmin打开有一些警告提示。
实际上要使用phpMyAdmin管理mysql数据库并不需要这么麻烦,只需要安装XAMPP就可以了。
XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的建 XAMPP 软件站集成软件包。
这个软件包原来的名字是 LAMPP,但是为了避免误解,最新的几个版本就改名为 XAMPP 了。
它可以在Windows、Linux、Solaris、Mac OS X 等多种操作系统下安装使用,支持多语言:英文、简体中文、繁体中文、韩文、俄文、日文等。
许多人通过他们自己的经验认识到安装 Apache 服务器是件不容易的事儿。如果您想添加 MySQL、PHP 和 Perl,那就更难了。
XAMPP 是一个易于安装且包含 MySQL、PHP 和 Perl 的 Apache 发行版。XAMPP 的确非常容易安装和使用:只需下载,解压缩,启动即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: