搭建MySQL可视化Web界面服务器

利用Apache搭建MySQL可视化Web界面服务器

1. 前言

LAMP环境就是Linux+Apache+Mysql+PHP。甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险。MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。因此目前Mysql被MariaDB所代替。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

Linux系统我选择Centos 7,Centos 7是比较稳定的。

2. 安装Apache Web服务器

Apache服务器是目前最流行的Web服务器。运行以下命令安装:


sudo yum install httpd

# 安装完成之后我们就可以运行以下命令启动Apache服务器了:
sudo systemctl start httpd.service

# 之后我们就可以在浏览器中打开http://your_server_IP_address/ 我们新安装的网站,检查一下Apache是否安装成功,正常运行。
# 有时候我们可能打不开,原因是防火墙限制了外包访问,我们开启再试试看防火墙:
sudo iptables -I INPUT -p TCP --dport 80 -j ACCEPT

# 或者这样,防火墙放行http和https协议:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

# 这次可以正常访问了(看见Apache的欢迎页面)
# 如果想以后重启服务器之后自动启动Apache服务器,可以运行以下命令:
sudo systemctl enable httpd.service

# Apache服务器的网站文件默认在/var/www目录。

3. 安装Mysql(MariaDB)数据库

运行以下命令安装MariaDB数据库:

sudo yum install mariadb-server mariadb

# 完成之后启动数据库:
sudo systemctl start mariadb

# 然后安装一个数据库安全脚本,去掉一些危险的默认设置:
sudo mysql_secure_installation

# 然后会提示你输入数据库的root账号密码,如果是新安装的则输入空格,如下所示:
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):

# 然后我们输入空格,继续设置root密码:
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]
 ... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n]
 \- Dropping test database...
 ... Success!
 \- Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

# 同样的,设置开机自动启动MariaDB数据库:
sudo systemctl enable mariadb.service

4. 安装PHP

运行以下命令安装PHP:

sudo yum install php php-mysql
 
# 安装完成,重启以下Apache服务器:
sudo systemctl restart httpd.service

# PHP安全完成之后,我们可以在网站目录下面建立一个info.php的文件来查看php的安装情况我们在/var/www/html目录创建一个info.php的文件:
sudo vi /var/www/html/info.php

# 其info.php内容如下:
<?php phpinfo(); ?>

# 我们我们安装PHP成功,浏览器打开http://your_server_IP_address/info.php 将会看到PHP-version信息

5. 安装phpMyAdmin

phpMyAdmin是个管理MariaDB数据库的Web界面程序。


# 我们首先安装EPEL库,这个库提供很多额外的软件包:
sudo yum install epel-release

# 完成之后直接安装phpMyAdmin:
sudo yum install phpmyadmin

# 完成之后,我们设置phpMyAdmin的httpd设置/etc/httpd/conf.d/phpMyAdmin.conf:
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   <IfModule mod_authz_core.c>
​     \# Apache 2.4
​     <RequireAny>
​       Require ip 127.0.0.1
​       Require ip ::1
​     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
​     \# Apache 2.2
​     Order Deny,Allow
​     Deny from All
​     Allow from 127.0.0.1
​     Allow from ::1
   </IfModule>
</Directory>

#从配置中可以看出,可以用http://192.168.232.131/phpmyadmin 去访问phpMyAdmin。实际上我们在浏览里打开这个地址是403 Forbidden,这是因为还有权限控制,我们更改一下权限:
<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   <IfModule mod_authz_core.c>
​     \# Apache 2.4
​     <RequireAny>
​       \#Require ip 127.0.0.1
​       \#Require ip ::1
​        Require all granted
​     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
​     \# Apache 2.2
​     Order Deny,Allow
​    \# Deny from All
​    \# Allow from 127.0.0.1
​    \# Allow from ::1
​      Allow from All
   </IfModule>
</Directory>
# 然后再重启以下Apache服务器:
sudo systemctl restart httpd.service

在浏览器输入http://server_domain_or_IP/phpMyAdmin ,可以看到:

用户名设置为root,密码设置为123456

然后可以使用数据的

root

密码登录了。

你可能感兴趣的:(MySQL,linux,mysql,php,数据库)