Centos7安装Mariadb10.5以及PHP7.4

一、安装Mariadb

1、添加Mariadb的yum源

        最近需要使用Mariadb10.5以上版本,Centos7yum中只提供了5.5版本,这需要添加Mariadb的yum源。在官方找到想要安装的系统以及要安装的版本,根据官方的生成的配置文件进行修改

Download MariaDB Server - MariaDB.org

[root@db01 /]# vim /etc/yum.repos.d/MariaDB.repo

[mariadb]
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.5/centos/$releasever/$basearch
module_hotfixes = 1
gpgkey = https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

如果不想使用aliyun的话,可以将https://mirrors.aliyun.com/mariadb/yum(baseurl和gpgkey)换为别的源

https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum  #清华源

2、 安装Mariadb

[root@db01 ~]# yum clean all && yum update  #清除yum缓存并更新

[root@db01 ~]# yum install -y mariadb-server  #安装mariadb服务端

[root@db01 ~]# systemctl enable mariadb && systemctl start mariadb  #mariadb开机自启并运行服务

 3、初始使用Mariadb配置

[root@db01 ~]# mysql_secure_installation  #安全配置向导。仅仅刚安装的时候运行.仅首次运行即可。

 NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
 SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
 In order to log into MySQL to secure it, we'll need the current
 password for the root user. If you've just installed MySQL, 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):<–初次运行直接回车
OK, successfully used password, moving on…

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n  <–是否unix_socket身份验证,建议不要使用

Setting the root password ensures that nobody can log into the MySQL
 

root user without the proper authorisation.
 Set root password? [Y/n] Y<– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码

Password updated successfully!
 Reloading privilege tables..
… Success!
 
 By default, a MySQL installation has an anonymous user, allowing anyone
 to log into MySQL 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] Y<– 是否删除匿名用户,生产环境建议删除
… 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] Y<–-# 是否禁止root远程登录,根据自己的需求选择
… Success!
 
 By default, MySQL 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] Y<–-# 是否删除test数据库,直接回车
- 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]Y <–-# 是否重新加载权限表
… Success!
 
 Cleaning up…
All done! If you've completed all of the above steps, your MySQL
 installation should now be secure.
 Thanks for using MySQL!

PS:

如果配置完后直接[root@db01 /]# mysql就可以登录,不需要输入账号密码的话

MariaDB [(none)]> select * from mysql.global_priv \G

查看是否有unix_socke,如果有的话需要修改root的账号密码

MariaDB [(none)]>alter user 'root'@'localhost' identified by 'test123456';

MariaDB [(none)]> flush privileges;  #刷新缓存

二、安装PHP

Remi repository 是包含最新版本 PHP 和 MySQL 包的 Linux 源,由 Remi 提供维护。有个这个源之后,使用 YUM 安装或更新 PHP、MySQL、phpMyAdmin 等相关程序的时候就非常方便

#安装依赖

[root@db01 ~]# yum install -y epel-release 

[root@db01 ~]# yum install -y yum-utils

#配置安装源,找到自己所需要的系统版本

[root@db01 ~]# yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm 

Remi's RPM repository

#设置安装版本

[root@db01 ~]# ll /etc/yum.repos.d/remi-*  
-rw-r--r--. 1 root root  855 Nov 28  2023 /etc/yum.repos.d/remi-modular.repo
-rw-r--r--. 1 root root  456 Nov 28  2023 /etc/yum.repos.d/remi-php54.repo
-rw-r--r--. 1 root root 1314 Nov 28  2023 /etc/yum.repos.d/remi-php70.repo
-rw-r--r--. 1 root root 1314 Nov 28  2023 /etc/yum.repos.d/remi-php71.repo
-rw-r--r--. 1 root root 1314 Nov 28  2023 /etc/yum.repos.d/remi-php72.repo
-rw-r--r--. 1 root root 1314 Nov 28  2023 /etc/yum.repos.d/remi-php73.repo
-rw-r--r--. 1 root root 1314 Nov 28  2023 /etc/yum.repos.d/remi-php74.repo
-rw-r--r--. 1 root root 1314 Nov 28  2023 /etc/yum.repos.d/remi-php80.repo
-rw-r--r--. 1 root root 1314 Nov 28  2023 /etc/yum.repos.d/remi-php81.repo
-rw-r--r--. 1 root root 1314 Nov 28  2023 /etc/yum.repos.d/remi-php82.repo
-rw-r--r--. 1 root root 1314 Nov 28  2023 /etc/yum.repos.d/remi-php83.repo
-rw-r--r--. 1 root root  750 Nov 28  2023 /etc/yum.repos.d/remi-safe.repo
 

[root@db01 /]# yum-config-manager --enable remi-php74

#安装php及拓展包

[root@db01 /]# yum install -y php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis

#查看php安装版本

[root@db01 ~]# php -v
PHP 7.4.33 (cli) (built: Jun  5 2024 05:05:14) ( NTS )
 

#开机自启动并启动php

[root@db01 /]#  systemctl enable php-fpm  &&systemctl start php-fpm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值