Linux源码安装Apache

下载 httpd-2.4.1 源码文件
httpd-2.4.1.tar.gz          http://httpd.apache.org/download.cgi

1.# 将文件cp到/usr/local/
  [root@localhost ~]# cd /usr/local/ 
  [root@localhost local]# tar -zxvf httpd-2.4.1.tar.gz 
  [root@localhost local]# cd httpd-2.4.1
  [root@localhost httpd-2.4.1]# ./configure --prefix=/usr/loca/httpd-apache/ --enable-modules=most --enable-mods-shared=most --with-mpm=prefork --enable-so --enable-rewrite

# 上面请特别注意到: 
--prefix=/安装的路径:设置apache安装路径 
--enable-so     :这个项目则是在宣告使用动态函式库!特别重要! 
--enable-rewrite  :这个项目只是预防用的!可以先设定,不过不一定会用到!
--enable    :表示需要启用的模块,可以自行增减


2.# 而且在此处可能会出现错误
# checking for APR...no
# 下载apr-1.4.6.tar.gz      http://apr.apache.org/download.cgi
# 同样放在/usr/local/
  [root@localhost httpd-2.4.1]# cd /usr/local
  [root@localhost local]# tar -zxvf apr-1.4.6.tar.gz
  [root@localhost local]# cd apr-1.4.6


# 将apr-1.4.6安装在/usr/local/apr下面
  [root@localhost apr-1.4.6]# ./configure
  [root@localhost apr-1.4.6]# make && make install


# 安装完成后继续
  [root@localhost apr-1.4.6]# cd ../httpd-2.4.1
  [root@localhost httpd-2.4.1]# ./configure --prefix=/usr/loca/httpd-apache/ --enable-modules=most --enable-mods-shared=most --with-mpm=prefork --enable-so --enable-rewrite

3.# 此处可能还会出现错误
  checking for APR-util...no
# 继续下载安装文件
# 下载apr-util-1.4.1.tar.gz     http://apr.apache.org/download.cgi

# 同样放在/usr/local/
  [root@localhost httpd-2.4.1]# cd /usr/local
  [root@localhost local]# tar -zxvf apr-util-1.4.1.tar.gz
  [root@localhost local]# cd apr-util-1.4.1

# 安装apr-util-1.4.1
  [root@localhost apr-util-1.4.1]# ./configure --with-apr=/usr/local/apr
  [root@localhost apr-util-1.4.1]# make && make install

# 安装完成后继续
  [root@localhost apr-1.4.6]# cd ../httpd-2.4.1
  [root@localhost httpd-2.4.1]# ./configure --prefix=/usr/loca/httpd-apache/ --enable-modules=most --enable-mods-shared=most --with-mpm=prefork --enable-so --enable-rewrite

shared=all --with-ssl=/usr/local/openssl/ --enable-track-vars --enable-rewrite

4.# 可能还会报错
# 安装pcre-8.30.tar.gz          http://pcre.org
# 同样放在/usr/local/
  [root@localhost httpd-2.4.1]# cd /usr/local
  [root@localhost local]# tar -zxvf pcre-8.30.tar.gz
  [root@localhost local]# cd pcre-8.30

# 安装apr-util-1.4.1
  [root@localhost pcre-8.30]# ./configure --with-apr=/usr/local/apr
  [root@localhost pcre-8.30]# make && make install

# 继续
  [root@localhost apr-1.4.6]# cd ../httpd-2.4.1

  [root@localhost httpd-2.4.1]# ./configure --prefix=/usr/loca/httpd-apache/ --enable-modules=most --enable-mods-shared=most --with-mpm=prefork --enable-so --enable-rewrite


# 成功了
  [root@localhost httpd-2.4.1]# make && make install

# OK
  [root@localhost apr]# cd ../httpd-apache/

# 启动Apache
  [root@localhost httpd-apache]# /usr/local/httpd-apache/bin/apachectl start 
  [root@localhost httpd-apache]# netstat -an |grep 80

# 打开浏览器,输入http://localhost(或者IP地址)
# 出现 It works!

# 至此,Apache安装完成


将apache注册为系统服务并开机启动:

1.设置开机启动

在/etc/rc.d/rc.local中增加启动apache的命令,例如:/usr/local/httpd/bin/apachectl start

2.注册为系统服务

把上面apache启动脚本apachectl复制到 /etc/rc.d/init.d/目录下,并重命名为httpd

使用编辑器打开httpd文件,并在第一行#!/bin/sh下增加两行文字如下(这是必需的,否则会报httpd不支持chkconfig

# chkconfig: 35 70 30
# description: Apache

接着注册该服务

chkconfig --add httpd

一切OK了,启动服务

service httpd start

其中所增加的第二行中三个数字第一个表示在运行级别3和5下启动apache,第二、三是关于启动和停止的优先级配置,无关紧要。



编译的httpd不支持chkconfig的解决方法

用chkconfig将自编译设置为系统服务的时候,httpd 服务不支持 chkconfig。

解决过程如下:

1.编辑/etc/init.d/httpd

#!/bin/bash
#chkconfig:345 61 61

#description:Apache httpd

2.配置

[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# chkconfig --list|grep httpd

httpd           0:关闭 1:关闭  2:关闭 3:关闭  4:关闭  5:关闭  6:关闭

[root@localhost ~]# chkconfig --level 345 httpd on
[root@localhost ~]# chkconfig --list|grep httpd

httpd           0:关闭  1:关闭 2:关闭 3:启用 4:启用 5:启用  6:关闭










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值