centos编译安装apache

本文是基于全新centos环境,暂无进行任何安装操作的centos

一、关闭selinux

1
vim /etc/selinux/config

接着如下图所示
selinux
SELINUX设置为disabled,然后reboot重启

二、配置remi源和epel源

下载地址:

  1. epel
  2. remi

使用wget进行下载,rpm进行安装

1
2
3
4
5
6
// 安装epel
rpm -iv epel-release-latest-6.noarch.rpm
// 安装remi
rpm -iv remi-release-6.rpm
// 重新生成yum源缓存
yum makecache

三、下载安装依赖库

1
yum groupinstall "Development tools"

其他依赖文件

1
2
3
4
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl openssl-devel
yum install libtool libtool-ltdl libtool-ltdl-devel

基于官方文档,点击查看,需要先下载并安装apr以及apr-util

这里约定所有的源码包都下载至/usr/local/src/,编译安装的时候安装到/usr/local/

apr下载地址:apr
apr-util下载地址:apr-util

1
2
wget http://mirrors.ustc.edu.cn/apache/apr/apr-1.5.2.tar.gz
wget http://mirrors.ustc.edu.cn/apache/apr/apr-util-1.5.4.tar.gz

解压apr和apr-util

1
2
tar -zxvf apr-1.5.2.tar.gz
tar -zxvf apr-util-1.5.4.tar.gz

编译安装apr

1
2
3
4
cd apr-1.5.2/
./configure --prefix=/usr/local/apr
make
make install

编译安装apr-util

1
2
3
4
cd apr-util-1.5.4/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install

四、下载安装apache

好了,主角登场,编译安装apache

下载地址:apache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
wget http://mirrors.ustc.edu.cn/apache/httpd/httpd-2.4.18.tar.gz
tar -zxvf httpd-2.4.18.tar.gz
cd httpd-2.4.18/
// 这里基于官方安装文档需要将apr和apr-util的源码包拷贝到apache的srclib目录下
cp -r ../apr-1.5.2/ ./srclib/apr
cp -r ../apr-util-1.5.4/ ./srclib/apr-util
./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=event --with-included-apr
make
make install
// 启动apache
/usr/local/apache/bin/apachectl start
// 放行80端口
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save

接着通过浏览器访问下,看到It works!说明收工啦!~

顺带附加下apache的超时、压缩配置文件,需要打开对应的扩展

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 15 days"
# My favicon
ExpiresByType image/x-icon "access plus 15 days"
# Images
ExpiresByType image/gif "access plus 15 days"
ExpiresByType image/png "access plus 15 days"
ExpiresByType image/jpg "access plus 15 days"
ExpiresByType image/jpeg "access plus 15 days"
# CSS
ExpiresByType text/css "access 15 days"
# Javascript
ExpiresByType application/javascript "access plus 15 days"
</IfModule>

<ifmodule mod_deflate.c>
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/json application/x-httpd-php
AddOutputFilter DEFLATE js css
</ifmodule>