2057

Centos8 安装 Nginx+PHP+MySQL+Redis

前言

本文针对之前Centos7的安装方法,在Centos8下安装有些变化,故重新整理一遍新的安装方法。本文实际操作系统为:Centos8.5

安装Nginx

centos8下的nginx版本比较新,直接安装即可

yum install -y nginx

安装PHP

通常安装remi源时会自动安装依赖epel源,也可手动安装

yum install https://mirrors.tuna.tsinghua.edu.cn/epel/epel-release-latest-8.noarch.rpm

安装remi源

yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-8.rpm

注意:如果Centos8版本为8.1~8.4,请安装remi-release-8.4.rpm

yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-8.4.rpm

查看php的安装流模块

yum module list php

重置php流模块

yum module reset php

指定需要安装的php版本对应的流模块

yum module enable php:remi-7.2

设置好流模块后如下

执行安装

yum install php php-fpm php-opcache php-mbstring php-cli php-xml php-pdo php-phalcon3 php-common php-json php-pecl-redis4 php-zip php-pecl-mysql

若要多个PHP版本共存,则在安装时,除了主版本以外,其他版本都需要指定版本号安装,例如:

在上面已经安装了php7.2作为主版本的情况下,额外再安装一个php8.0,则使用如下命令

yum install php80 php80-php-fpm php80-php-opcache php80-php-mbstring php80-php-cli php80-php-xml php80-php-pdo php80-php-common php80-php-json php80-php-zip php80-php-pecl-redis5 php80-php-pecl-mysql php80-php-phalcon5

⚠️注意:命令行使用时,也需要指定版本号使用

php80 -v

配置文件在/etc/opt/remi/php80/目录

安装MySQL

安装mysql源,此处直接安装centos7下的源

yum install http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

如果安装报错GPG公钥没有安装,可关闭gpgcheck

vi /etc/yum.repos.d/mysql-community.repo

#修改中mysql5.7的gpgcheck
gpgcheck=0

禁用默认mysql安装流模块

yum module disable mysql

执行安装

yum install mysql-community-server

启动mysql

systemctl start mysqld

查看mysql首次安装生成的密码

grep 'temporary password' /var/log/mysqld.log

设置root密码

mysql -uroot -p
alter user root@localhost identified by 'new password';

use mysql

#5.6
update user set password=password('you password') where user='root' and host='localhost';

#5.7
update user set authentication_string=password('you password') where user='root' and host='localhost';

#8.0
#从5.7.9以后,取消了password函数,authentication_string=password("you password")会报错,使用以下命令修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'you password';

开启远程连接

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'you password' WITH GRANT OPTION;

flush privileges;

mysql8.0

update user set host='%' where user='root';

flush privileges;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

安装Redis

直接yum安装即可,多实力配置参考之前的文章

yum install redis
文章作者:DOTATONG
发布日期:2022-03-01

评论

暂无

添加新评论