Centos7源码安装Apache2

Centos7源码安装Apache2

编译环境;

yum -y install gcc gcc-c++

依赖的软件包:

apr-1.4.6

[root@localhost ~]# tar -xf apr-1.4.6.tar.gz
[root@localhost ~]# cd apr-1.4.6
[root@localhost apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.4.6]# make && make install

apr-util-1.4.1

[root@localhost ~]# tar -xf apr-util-1.4.1.tar.gz
[root@localhost ~]# cd apr-util-1.4.1
[root@localhost apr-1.4.6]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.4.1]# make && make install

pcre-8.34

[root@localhost ~]# tar -xf pcre-8.34.tar.gz
[root@localhost ~]# cd pcre-8.34
[root@localhost pcre-8.34]# ./configure --prefix=/usr/local/pcre
[root@localhost pcre-8.34]# make && make install

安装Apache

[root@localhost ~]# tar -xf httpd-2.4.54.tar.gz
[root@localhost ~]# cd httpd-2.4.54
[root@localhost httpd-2.4.54]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre/bin/pcre-config
[root@localhost httpd-2.4.54]# make && make install

关闭seblinux和firewall:

[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld

启动apache:

[root@localhost ~]# /usr/local/apache2/bin/apachectl start

测试网站是否正常运行:

在这里插入图片描述

添加运行apache的用户:

[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
[root@localhost ~]# id apache
uid=996(apache) gid=994(apache)=994(apache)
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
修改user和group为apache

修改属主和属组:

chown apache.apache -R /usr/local/apache2/htdocs

设置开机自启:

[root@localhost ~]# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd # 复制到init.d 并重命名为httpd
# 编辑httpd脚本,在第2行(#!/bin/sh下面)添加如下注释信息(包括#):
# chkconfig: 35 61 61
# description: Apache

#3个参数意义分别为:在哪些运行级别启动httpd(3,5);启动序号(S61);关闭序号(K61)
# chkconfig --add httpd #所有开机模式下自启动,chkconfig httpd on 表示345模式下自启动
# 此时已经将httpd添加入服务了。在rc3.d、rc5.d路径中将来就会出现S61httpd的链接,其他运行级别路径中会出现K61httpd的链接。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值