ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

CentOS7 配置LAMP环境

2020-12-11 10:33:40  阅读:280  来源: 互联网

标签:mysql 配置 CentOS7 LAMP systemctl php70w MySQL password root


一、关闭防火墙

1.查看防火墙状态

systemctl status firewalld

  • inactive 关闭状态
  • active  开启状态

2.关闭防火墙

systemctl stop firewalld

3.永久关闭防火墙

systemctl disable firewalld

二、安装Apache

1.安装Apache服务及扩展包

yum -y install httpd httpd-manual mod_ssl mod_perl mod_auth_mysql

2.启动Apache服务

systemctl start httpd

3.设置Apache服务开机自启动

systemctl enable httpd

4.查看apache是否安装成功

在浏览器地址栏输入 http://ip地址,运行,出现如下页面即安装成功

 

 

三、安装并配置MySQL

  1.更新YUM源

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

 2.安装MySQL

yum -y install mysql-community-server

  如果出现”No match for argument“错误,请先运行yum module disable mysql禁用默认的mysql模块,再安装MySQL

 3.查看MySQL版本号

mysql -V

 出现如下信息即表示安装成功,注意”V“要大写

 

 

  4.启动mysql

systemctl start mysqld

 5.设置开机自启动

systemctl enable mysqld
systemctl daemon-reload

 6.查看初始密码

grep "password" /var/log/mysqld.log

  

 7.配置MySQL的安全性

mysql_secure_installation
  • 重置root账号的密码
Enter password for user root: #输入上一步获取的root用户初始密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration of the plugin.
Using existing password for root.
Estimated strength of the password: 100 
Change the password for root ? (Press y|Y for Yes, any other key for No) : Y #是否更改root用户密码,输入Y
New password: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/
Re-enter new password: #再次输入新密码
Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
  • 输入Y删除匿名用户账号
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? (Press y|Y for Yes, any other key for No) : Y  #是否删除匿名用户,输入Y
Success.
  • 输入Y禁止root账号远程登录
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入Y
Success.
  • 输入Y删除test库以及对test库的访问权限
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入Y
- Dropping test database...
Success.
  • 输入Y重新加载授权表
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入Y
Success.
All done!

四、安装PHP

 1.更新YUM源

  • 添加epel源
yum install -y \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  • 添加Webtatic源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

  2.安装PHP

yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64  php70w-pdo.x86_64   php70w-mysqlnd  php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb

  3.查看PHP版本

php -v

  出现如下结果即表示php安装成功

 4.在Apache网站根目录创建测试文件

echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

 5.重启Apache服务

systemctl restart httpd

 6.运行。在浏览器地址栏输入http://ip地址/phpinfo.php,出现如下页面即表示安装成功

 

 

 五、安装phpMyAdmin

 1.创建phpMyAdmin数据存放目录

mkdir -p /var/www/html/phpmyadmin

 2.下载phpMyAdmin压缩包并解压

  • 下载
wget https://files.phpmyadmin.net/phpMyAdmin/4.0.10.20/phpMyAdmin-4.0.10.20-all-languages.zip
  • 解压
yum install -y unzip
unzip phpMyAdmin-4.0.10.20-all-languages.zip

 3.复制phpMyAdmin文件到准备好的数据存放目录

mv phpMyAdmin-4.0.10.20-all-languages/*  /var/www/html/phpmyadmin

 4.检查是否安装成功。在浏览器地址栏输入http://ip地址/phpmyadmin,运行,出现如下页面即表示安装成功

 

 

LAMP环境配置完成!

如果使用navicat连接数据库报错,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server,是无法给远程连接的用户权限问题,就是”7.配置MySQL的安全性“中第三步设置了禁止远程登陆

解决办法:

mysql -u root -p密码

  进入Mysql控制台

  • 提权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION; 
  • 刷新
flush privileges;

标签:mysql,配置,CentOS7,LAMP,systemctl,php70w,MySQL,password,root
来源: https://www.cnblogs.com/zxf100/p/14119054.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有