注:此方法为直接调用yum软件源进行在线安装,非源码手动编译安装
Part 1:安装PHP7.2
--->PHP第一种安装方法
1、如果之前已经安装我们先卸载一下yum -y remove php*
2、由于linux的yum源不存在php7.x,所以我们要更改yum源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
3、yum 安装php72w和各种拓展,选自己需要的即可,这里建议全选yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
--->PHP第二种安装方法
1、配置安装yum源 EPEL and Remi repositoryyum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-6.rpm
2、安装 yum-utilsyum install yum-utils
3、yum-config-manager 管理要安装的版本,以下3个,选择自己要安装的版本执行yum-config-manager --enable remi-php72 [Install PHP 7.2,选择性安装]
yum-config-manager --enable remi-php70 [Install PHP 7.0,选择性安装]
yum-config-manager --enable remi-php71 [Install PHP 7.1,选择性安装]
4、开始安装yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo php-fpm
5、启动php服务并设置开机自启动systemctl start php-fpm
systemctl enable php-fpm
Part 2:安装MySQL
1、安装依赖yum install libaio-devel ncurses-devel cmake gcc gcc-c++ bison -y
2、安装 MySQL,如果提示-bash: wget: 未找到命令请先使用命令安装wgetyum -y install wget# 下载
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
# 校验校验码
md5sum mysql57-community-release-el7-9.noarch.rpm
# 安装
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum install mysql-server
3、启动MySQL服务systemctl start mysqld
systemctl status mysqld
4、查看mysql默认的临时密码grep 'temporary password'/var/log/mysqld.log
# 使用默认密码登录后,任何事情做不了
5、更改密码(要利用临时密码进入后,执行下面的设置)mysql -uroot -p
# 修改密码策略 < mysql5.7 默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少8位 >
--------------------------可忽略---------------------------
set global validate_password_policy=0;
set global validate_password_length=0;
-------------------------------------------------------------
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; ## 要权限最大的话 可以使用下面语句,但不是太安全
ALTER USER 'root'@'%' IDENTIFIED BY '123456';
###如果出现'You must reset your password using ALTER USER statement before executing this statement.'
alter user user() identified by "123456";
### 下面有可能会用到的命令
mysql -u root -p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
Part 3:安装Apach
1、Apache在默认的CentOS仓库中可用,安装非常简单。 在CentOS和RHEL上,Apache软件包和服务称为httpd。 要安装软件包,请运行以下命令:yum -y install httpd*
2、安装完成后,启用并启动Apache服务:sudo systemctl enable httpd
sudo systemctl start httpd
备注:
如果 yum安装报错Error: xz compression not available,则使用下列命令后重新安装
yum remove epel-release
rm -rf /var/cache/yum/x86_64/6/epel/
yum clean all
yum -y remove php*