zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

Centos7安装配置Apache+PHP+Mysql+phpmyadmin

2023-09-11 14:19:58 时间


前言

本篇文章主要介绍了在Linux上安装和使用phpMyAdmin
环境:Centos7.6

在这里插入图片描述


内容

流程配置

  • 进入linux后先进入到root
sudo -i

在这里插入图片描述

  • 安装Apache
yum install httpd
  • 安装MariaDB (MySQL的一个开源分支)
yum install mariadb mariadb-server
  • 启动MariaDB
systemctl start mariadb 
  • 设置mysql root账户密码:设置完成后一路Y就可以了
mysql_secure_installation

在这里插入图片描述

  • 重启MariaDB
systemctl restart mariadb.service

在这里插入图片描述

  • 安装PHP以及PHP拓展
yum install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
  • 重启Apache服务器
systemctl restart httpd.service
  • 测试PHP安装结果
# 打开index.php文件
vi /var/www/html/index.php 

# 输入一下内容然后保存, 
<?php
  phpinfo();
?>

#  在浏览器中输入Linux的公网IP,可以看到一下PHP的相关版本信息,就成功了

在这里插入图片描述
在这里插入图片描述

  • 安装phpmyadmin
yum install phpmyadmin php-mcrypt
  • 修改phpMyAdmin的配置,使远端可以访问,修改方式如下
vi /etc/httpd/conf.d/phpMyAdmin.conf 
<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
   </IfModule>
</Directory>

<Directory /usr/share/phpMyAdmin/setup/>
   <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
   </IfModule>
</Directory>

在这里插入图片描述

  • 重启Apache服务器
systemctl restart httpd
  • 访问phpMyAdmin
http://服务器ip地址/phpmyadmin

以上全部走完后,输入地址就可以看到phpMyAdmin的页面了,账号root,密码就是刚才设置的数据库的密码,进来后可以看到mySql里的数据了

在这里插入图片描述
在这里插入图片描述

数据库内容添加和查看

  • 重启MariaDB
systemctl restart mariadb.service
  • root方式登录数据库
mysql -uroot -p

在这里插入图片描述

  • 创建新的数据库
CREATE DATABASE Sun_Database;

在这里插入图片描述

  • 使用新的数据库
use Sun_Database;

在这里插入图片描述

  • 创建新的表
CREATE TABLE Sun_Tbl(runoob_id INT NOT NULL AUTO_INCREMENT,runoob_title VARCHAR(100) NOT NULL,PRIMARY KEY ( runoob_id ))ENGINE=InnoDB DEFAULT CHARSET=utf8;

在这里插入图片描述

  • 插入数据
INSERT INTO Sun_Tbl ( runoob_id, runoob_tittle) VALUES ( 10001, "abcdefg");

在这里插入图片描述

  • 查看数据

数据添加完成后,刷新phpMyAdmin的页面就可以直接看到新添加的数据库和表数据了

在这里插入图片描述


推送

Github:https://github.com/KingSun5


结语

希望看到最后的同学有所收获,若是觉得博主的文章写的不错,不妨关注一下博主,点赞一下博文,另博主能力有限,若文中有出现什么错误的地方,欢迎各位评论指摘。
QQ交流群:806091680(Chinar)
该群为CSDN博主Chinar所创,推荐一下!我也在群里!
本文属于原创文章,转载请著名作者出处并置顶!!!!