Centos7源码安装Apache2
编译环境;
yum -y install gcc gcc-c++
依赖的软件包:
[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
[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
[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的链接。