CentOS7、CentOS8安装httpd,mariadb,php环境

2020-11-16 17:01:14    金凯    5363

一、准备工作

1、本说明使用root用户操作,若非root用户操作,出现权限问题,可以使用su,sudo,sudo -i 等命令获取root权限
2、关闭selinux
//获取selinux状态
[root@localhost ~]# getenforce  //enforceing代表开启,permissive代表警告,disabled代表关闭
//暂时关闭,重启之后没有效果
[root@localhost ~]# setenforce 0    //关闭
[root@localhost ~]# setenforce 1    //开启
//通过配置文件“/etc/sysconfig/selinux”来修改selinux状态,需要重启机器,永久关闭
[root@localhost ~]# vi/etc/sysconfig/selinux 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled  //修改为disabled

3、关闭防火墙或开放相关端口

//firewall
//查看防火墙状态
[root@localhost ~]# systemctl status firewalld 或者 firewall-cmd
//防火墙开放80端口外部访问
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp //添加80端口
[root@localhost ~]# firewall-cmd --reload //生效
//查看开放端口列表
[root@localhost ~]# firewall-cmd --permanent --zone=public --list-ports
//启动防火墙
[root@localhost ~]# systemctl start firewalld
//禁用防火墙
[root@localhost ~]# systemctl stop firewalld
//设置开机启动
[root@localhost ~]# systemctl enable firewalld
//停止并禁用开机启动
[root@localhost ~]# systemctl disable firewalld
//重启防火墙
[root@localhost ~]# firewall-cmd --reload

二、运行环境安装

运行环境使用apache + php + mariadb 组合
注:CentOS7后已经不再支持mysql,mariadb是 MySQL 的一个分支版本,提供的功能可和 MySQL 完全兼容
1、安装apache
首先查看Linux中是否已有安装的apache,已安装可直接使用,若apache版本较低,启动时可能会出现问题,可以先卸载,然后再安装
//查看系统中已安装的所有apache软件包列表
[root@localhost ~]# rpm  -qa  |grep  httpd 
[root@localhost ~]#     //未安装apache或已完全卸载
[root@localhost ~]# rpm  -qa  |grep  httpd 
[root@localhost ~]# httpd-tools-2.4.6-93.el7.centos.x86_64  //已安装apache
[root@localhost ~]# httpd-2.4.6-93.el7.centos.x86_64   //已安装apache
//卸载apache软件包 --nodeps是指卸载软件时,忽略依赖关系
[root@localhost ~]# rpm -e --nodeps httpd 
//安装apache(yum源安装)
//安装完成后,再用 rpm  -qa  |grep httpd,查看apache是否已安装成功
[root@localhost ~]# yum install httpd
//查看apache状态
[root@localhost ~]# systemctl status httpd
//启动apache
[root@localhost ~]# systemctl start httpd
//停止apache
[root@localhost ~]# systemctl stop httpd
//开机自启apache
[root@localhost ~]# systemctl enable httpd
//开机不自启apache
[root@localhost ~]# systemctl disable httpd
验证httpd是否安装成功,浏览器访问 http://ip:port
2、安装php
选择版本5.6/7.0/7.1,安装zdoo还可以安装7.2版本,本文使用php7.0
需要安装pdo, pdo_mysql,json,pcre,php_sockets,php-zip,curl,gd,filter,php-openssl,php-mbstring等扩展
//查看当前php版本
[root@localhost ~]# php -v
//查看当前php相关的安装包
[root@localhost ~]# yum list installed | grep php
//更换RPM源
#CentOs 7.X:
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
//关闭php-fpm和apache服务
[root@localhost ~]# systemctl stop php-fpm
//删除已经安装的php相关包
[root@localhost ~]# yum remove php*
//安装php,不同的RPM源含有php版本不同
[root@localhost ~]# yum install php70w php70w-cli php70w-common php70w-devel php70w-embedded 
php70w-fpm php70w-gd php70w-mbstring php70w-mysqlnd php70w-opcache 
php70w-pdo php70w-xml php70w-ldap php70w-mcrypt
//重新启动php-fpm和apache服务,再次检查版本
[root@localhost ~]# systemctl start php-fpm
//验证php是否安装成功,执行命令创建phpinfo.php文件
[root@localhost ~]# vi /var/www/html/phpinfo.php
//phpinfo.php文件插入如下内容
<?php phpinfo(); ?>
浏览器访问 http://ip:port/phpinfo.php
3、安装mariaDB
//查看当前mariadb相关的安装包
[root@localhost ~]# yum list installed | grep mariadb
//卸载mariadb
[root@localhost ~]# yum remove mariadb-server
//安装mariadb
[root@localhost ~]# yum install mariadb-server
//查看mariadb服务状态
[root@localhost ~]# systemctl status mariadb
//开启mariadb服务
[root@localhost ~]# systemctl start mariadb  
//关闭mariadb服务
[root@localhost ~]# systemctl stop mariadb 
//设置mariadb开机自启
[root@localhost ~]# systemctl enable mariadb
//设置mariadb开机不自启
[root@localhost ~]# systemctl disable mariadb
//进行数据库的配置
[root@localhost ~]# mysql_secure_installation
//配置时出现的各个选项
############
Enter current password for root (enter for none):  //输入数据库超级管理员root的密码(注意不是系统root的密码),第一次进入还没有设置密码则直接回车
Set root password? [Y/n]  //设置密码,y
New password:  //新密码
Re-enter new password:  //再次输入密码
Remove anonymous users? [Y/n]  //移除匿名用户, y
Disallow root login remotely? [Y/n]  //拒绝root远程登录,n,不管y/n,都会拒绝root远程登录
Remove test database and access to it? [Y/n]  //删除test数据库,y:删除。n:不删除,数据库中会有一个test数据库,一般不需要
Reload privilege tables now? [Y/n]  //重新加载权限表,y。或者重启服务也行
#############
//测试能否登录成功,出现 MariaDB [(none)]> 就表示已经能够正常登录使用MariaDB数据库
[root@localhost ~]# mysql -u root -p
4、安装ioncube解密扩展
ioncube扩展安装文档参考 https://www.zsite.com/book/chanzhieps/189.html

三、源码安装

ZDOO安装文档参考 https://www.zdoo.com/book/zdoo/zdooinstall-5.html
ZSITE安装文档参考 https://www.zsite.com/book/chanzhieps/189.html