当前位置: 移动技术网 > 网络运营>服务器>Linux > CentOS7服务器中apache、php7以及mysql5.7的安装配置代码

CentOS7服务器中apache、php7以及mysql5.7的安装配置代码

2019年04月22日  | 移动技术网网络运营  | 我要评论

centos7服务器中apache、php7以及mysql5.7的配置代码如下所示:

yum upgrade
yum install net-tools

安装apache

关闭selinux
编辑器打开 etc/selinux/config 文件,找到 selinux=enforcing 字段,将其改成 selinux=disabled ,并重启设备。
yum -y install httpd mod_ssl
配置防火墙
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
开机启动
systemctl start httpd
systemctl enable httpd
终端输入如下指令检查httpd的运行状态
sudo systemctl status httpd

安装php7

添加源
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
安装
yum install php70w

安装mysql5.7

1.安装wget
  yum -y install wget
2.安装源
  wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  rpm -ivh mysql57-community-release-el7-8.noarch.rpm
3.安装mysql
  yum install mysql-server
4.启动mysql服务
  systemctl start mysqld
5.查看mysql的启动状态
  systemctl status mysqld
6.开机启动
  systemctl enable mysqld
  systemctl daemon-reload
7.修改root本地登录密码
  查找mysql生成的随机密码
  grep 'temporary password' /var/log/mysqld.log
  mysql -uroot -p
  修改密码,注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示error 1819 (hy000): your password does not satisfy the current policy requirements错误
  alter user 'root'@'localhost' identified by 'mynewpass4!'; 
8.配置默认编码为utf8
  修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置
  [mysqld]
  character_set_server=utf8
  init_connect='set names utf8'
9.配置mysql远程连接
  mysql -uroot -p
  use mysql;
  grant all on *.* to 'root'@'%' identified by 'root用户的密码' with grant option;
flush privileges;
然后用以下命令查看哪些用户和host可以访问,%代表任意ip地址
select user,host from user;
防火墙添加3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
10.mysql忘记密码
1.修改mysql的配置文件(默认为/etc/my.cnf),在[mysqld]下添加一行skip-grant-tables
2.service mysqld restart后,即可直接用mysql进入
3.mysql> update mysql.user set authentication_string=password('123qwe') where user='root' and host = 'localhost';
  mysql> flush privileges;
  mysql> quit;
 将/etc/my.cnf文件还原,重新启动mysql:service mysql restart,这个时候可以使用mysql -u root -p'123qwe'进入了
 mysql>set password = password('newpasswd'); 设置新密码

总结

以上所述是小编给大家介绍的centos7服务器中apache、php7以及mysql5.7的安装配置代码,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网