centos 7 php目录权限设置密码,CentOS7 配置LAMP环境

本文详细介绍了如何在CentOS7系统上安装和配置LAMP(Linux、Apache、MySQL、PHP)环境,并安装phpMyAdmin。步骤包括关闭防火墙、安装Apache服务、设置MySQL、安装PHP以及部署phpMyAdmin。此外,还涉及了MySQL的安全性配置和phpMyAdmin的访问验证。最后,文章提供了检查各个组件是否安装成功的验证方法。
摘要由CSDN通过智能技术生成

一、关闭防火墙

1.查看防火墙状态

systemctl status firewalld

209584383_1_20201211103431587.png

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地址,运行,出现如下页面即安装成功

209584383_2_20201211103431650.png

三、安装并配置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“要大写

209584383_3_20201211103431775.png

4.启动mysql

systemctl start mysqld

5.设置开机自启动

systemctl enable mysqld

systemctl daemon-reload

6.查看初始密码

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

209584383_4_20201211103431853.png

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安装成功

209584383_5_20201211103431915.png

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

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

5.重启Apache服务

systemctl restart httpd

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

209584383_6_20201211103431978.png

五、安装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,运行,出现如下页面即表示安装成功

209584383_7_20201211103432275.png

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;

来源:https://www.icode9.com/content-3-781951.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值