一,服务器中配置基础的服务

本篇文章安装:nginx/1.20.1,mysql 5.6,PHP 7.2.34

一,安装Nginx

1,配置 EPEL源

sudo yum install -y epel-release
sudo yum -y update

2,安装Nginx

sudo yum install -y nginx
安装成功后,默认的网站目录为:/usr/share/nginx/html
默认的配置文件为:/etc/nginx/nginx.conf
自定义配置文件目录为: /etc/nginx/conf.d/

3,开启端口80和443

如果你的服务器打开了防火墙,你需要运行下面的命令,打开80和443端口。

sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https 
sudo firewall-cmd --reload

或者直接关闭防火墙

停止:systemctl stop firewalld.service
重启:systemctl restart firewalld.service
关闭开机自启:systemctl disable firewalld.service
开启开机自启:systemctl enable firewalld.service
状态:systemctl status firewalld.service
添加进站规则:firewall-cmd --zone=public --add-port=端口号/协议 --permanent
删除入战规则:firewall-cmd --zone=public --remove-port=端口号/协议 --permanent
查看入战规则:firewall-cmd --permanent --list-ports

另外还要看控制台中防火墙是否开启相应端口
服务器->管理->网络信息
image.png
规则配置如下:

image.png

二,安装php7

1,rpm 安装 Php7 相应的 yum源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2,安装PHP

yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysql php72w-intl php72w-mbstring

安装php fpm依次执行下面命令:

yum install php72w-fpm
systemctl start php-fpm.service //启动php
systemctl enable php-fpm.service//设置开机自启动
systemctl restart httpd //重新启动apache服务

三,安装mysql

1、检查系统中是否已安装 MySQL
rpm -qa | grep mysql
如果返回空值的话,就说明没有安装 MySQL 。
2、查看已安装的 Mariadb 数据库版本
rpm -qa|grep -i mariadb
![image.png](https://img-blog.csdnimg.cn/img_convert/d9257b6d7ca305ed8c84f8b16851c251.png#clientId=u7b40b058-b793-4&from=paste&height=41&id=u325caf33&margin=[object Object]&name=image.png&originHeight=82&originWidth=719&originalType=binary&ratio=1&size=10262&status=done&style=none&taskId=u81c93a48-94cf-4d3b-852f-e751818c21e&width=359.5)
3、卸载已安装的 Mariadb 数据库
rpm -qa|grep mariadb|xargs rpm -e --nodeps
4、再次查看已安装的 Mariadb 数据库版本,确认是否卸载完成返回空则卸载完成。
5、下载mysql安装包文件
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
6、安装mysql-community-release-el7-5.noarch.rpm包
rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装完成之后,会在 /etc/yum.repos.d/ 目录下新增 mysql-community.repo 、mysql-community-source.repo 两个 yum 源文件
7、安装mysql
yum install mysql-server
中间会让输入:y
image.png
8、检查mysql是否安装成功
rpm -qa | grep mysql
image.png
9、启动 mysql 服务并设置开机启动

启动 mysql:
systemctl start mysqld.service

设置 mysql 开机启动:
systemctl enable mysqld.servic

下面常用命令:

重启 mysql
systemctl restart mysqld.service

停止 mysql
systemctl stop mysqld.service

mysql常用文件路径

/etc/my.cnf   这是mysql的主配置文件
/var/lib/mysql   mysql数据库的数据库文件存放位置
/var/logs/mysqld.log  数据库的日志输出存放位置

10、设置密码 并 为root用户添加远程登录能力
mysql5.6 安装完成后,它的 root 用户的密码默认是空的,我们需要及时用 mysql 的 root 用户登录(第一次直接回车,不用输入密码),并修改密码。

依次输入下列命令:

mysql -u root -p
回车

选择数据库

use mysql;

修改密码

update user set password=PASSWORD("这里输入root用户密码") where User='root';

让配置生效

flush privileges;

为root 用户添加远程登录的能力

GRANT ALL PRIVILEGES ON *.* TO 'your username'@'%' IDENTIFIED BY 'your password'WITH GRANT OPTION;#创建远程连接
GRANT ALL PRIVILEGES ON *.* TO root@'localhost' IDENTIFIED BY 'your password' WITH GRANT OPTION;#本地连接,否则无法访问mysql数据库                                                                   
 flush privileges;#使配置生效

image.png
注意:若使用root登录后执行不了grant命令,并显示下面的提示时:
这样登录:mysql -u root -p -h 127.0.0.1
image.png
退出mysql后重新启动mysql
systemctl restart mysqld.service
mysql转载自:https://blog.csdn.net/m0_45234510/article/details/117600152

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虚无-缥缈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值