centos7下部署LAMP

1.1 搭建之前的操作

1.1.1 升级系统组件到最新的版本

yum -y update

1.1.2 关闭selinux

首先查看选项

[root@localhost ~]# cat /etc/selinux/config 

# 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=enforcing
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

利用sed更改配置文件

[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disable/' /etc/selinux/config 

确认结果

[root@localhost ~]# cat /etc/selinux/config 

# 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=disable
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
setenforce 0       #临时关闭命令
getenforce         #检测selinux是否关闭,Disabled 为关闭

1.1.3 关闭防火墙

[root@localhost ~]# firewall-cmd --state	#查看默认防火墙状态,关闭后显示not running,开启后显示running
running
systemctl stop firewalld    #临时关闭firewall
systemctl disable firewalld #禁止firewall开机启动

1.2 搭建LAMP环境

1.2.1 安装所需所有软体仓库

Zabbix是建立在LAMP或者LNMP环境之上,在此为了方便就使用yum安装LAMP环境

yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
rpm -qa httpd php mariadb	#安装完成后检查应用版本

1.2.2 编辑httpd

vi /etc/httpd/conf/httpd.conf

在这里插入图片描述

1.2.3 编辑配置php,配置中国时区

vi /etc/php.ini
date.timezone = PRC   # 配置时区  

在这里插入图片描述

1.2.4 启动httpd,mysqld

systemctl start httpd   #启动并加入开机自启动httpd
systemctl enable httpd
systemctl start mariadb  #启动并加入开机自启动mysqld
systemctl enable mariadb
ss -anplt | grep httpd   #查看httpd启动情况,80端口监控表示httpd已启动

在这里插入图片描述

ss -naplt | grep mysqld  #查看mysqld启动情况,3306端口监控表示mysqld已启动 

在这里插入图片描述

1.2.5 创建一个测试页,测试LAMP是否搭建成功

vi /var/www/html/index.php #创建一个测试页,并编辑
<?php
phpinfo()
?>

在这里插入图片描述

1.2.6 初始化mysql数据库,并配置root用户密码

mysqladmin -u root password admin123           #设置数据库root密码

在这里插入图片描述

mysql -u root -p        #root用户登陆数据库
CREATE DATABASE zabbix character set utf8 collate utf8_bin;       #创建zabbix数据库(中文编码格式)
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';  #授予zabbix用户zabbix数据库的所有权限,密码admin123
flush privileges;    #刷新权限
quit                 #退出数据库 

在这里插入图片描述

vi /var/www/html/index.php         #修改测试页内容,测试zabbix用户是否能够登陆数据库,这个环节很重要
<?php
$link=mysql_connect('192.168.100.211','zabbix','admin123');  
if($link) echo "<h1>Success!!</h1>";   #显示Success表示连接数据库成功
 else echo "Fail!!";
mysql_close();
?>

在这里插入图片描述
为保证zabbix用户也可以登录数据库,若出现本地无法登录情况,解决方式如下:

mysql -u root -p  #使用root账户登录数据库;
select user,host from mysql.user;   #有空用户名称占用导致本地无法登录远程可登录
drop user ''@localhost;  #删除空用户

至此LAMP配置并验证完成

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值