CentOS7 服务器中 apache,php7 以及 mysql5.7 的配置代码如下所示:
yum upgradeyum install.NET-tools
安装 apache
( http://m.8682222.com/ )关闭 SELinux 编辑器打开 etc/selinux/config 文件, 找到 SELINUX=enforcing 字段, 将其改成 SELINUX=disabled , 并重启设备. yum -y install httpd mod_ssl 配置防火墙 firewall-cmd --permanent --add-port=80/tcpfirewall-cmd --permanent --add-port=443/tcpfirewall-cmd --reload 开机启动 systemctl start httpdsystemctl enable httpd 终端输入如下指令检查 httpd 的运行状态 sudo systemctl status httpd
安装 PHP7
添加源 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmrpm -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 --permanentfirewall-cmd --reload
10.MySQL 忘记密码 1. 修改 MySQL 的配置文件 (默认为 / etc/my.cnf), 在[mysqld] 下添加一行 skip-grant-tables2.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'); 设置新密码
总结
来源: http://www.bubuko.com/infodetail-3045453.html