CentOS7 配置LAMP环境

  • A+
所属分类:linux技术
摘要

一、关闭防火墙 1.查看防火墙状态2.关闭防火墙3.永久关闭防火墙二、安装Apache

一、关闭防火墙

1.查看防火墙状态

systemctl status firewalld 

CentOS7 配置LAMP环境

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

CentOS7 配置LAMP环境

 

 

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

CentOS7 配置LAMP环境

 

 

  4.启动mysql

systemctl start mysqld 

 5.设置开机自启动

systemctl enable mysqld systemctl daemon-reload 

 6.查看初始密码

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

  CentOS7 配置LAMP环境

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

CentOS7 配置LAMP环境

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

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

 5.重启Apache服务

systemctl restart httpd 

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

CentOS7 配置LAMP环境

 

 

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

CentOS7 配置LAMP环境 

 

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;