linux Apache 的安装

rpm –qa httpd 查询是否安装了 Apache

rpm –e 包名卸载安装程序

rpm –e --nodeps 包名卸载安装程序不产生依赖

#检查是否安装有依赖库

yum install –y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

zlibzlib-devel ncurses-devel gcc-c++ wget tree vim lsof apr*

[root@Liangenyu tools]# wget

http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.27.tar.gz

#查看下载的包大小

[root@Liangenyu tools]# ls httpd-2.2.27.tar.gz -hs

7.2M httpd-2.2.27.tar.gz

#解压安装包

[root@Liangenyu tools]# tar zxvf httpd-2.2.27.tar.gz

#切换到 httpd 目录

[root@Liangenyu tools]# cd httpd-2.2.27

#ls 查看下有没有 INSTALL   README [root@Liangenyuhttpd-2.2.27]# ls

ABOUT_APACHE    CHANGES              httpd.dsp            libhttpd.dep    NOTICE

server

acinclude.m4config.layout  httpd.mak          libhttpd.dsp    NWGNUmakefilesrclib

Apache.dsw       configure          httpd.speclibhttpd.mak    os                           support                   64

build               configure.in     include                LICENSE            README                   test BuildAll.dsp   docs INSTALL                Makefile.in     README.platforms   VERSIONING BuildBin.dsp   emacs-style    InstallBin.dsp  Makefile.win   README-win32.txt buildconfhttpd.dep          LAYOUT                 modules            ROADMAP

#因为安装步骤可以参考 INSTALL

[root@Liangenyuhttpd-2.2.27]# cat INSTALL

APACHE INSTALLATION OVERVIEW

Quick Start - Unix

------------------

For complete installation documentation, see [ht]docs/manual/install.html or

http://httpd.apache.org/docs/2.2/install.html

$ ./configure --prefix=PREFIX

$ make

$ make install

$ PREFIX/bin/apachectl start

……………………………………………….

#常用的配置参数:

--prefix 默认安装在/usr/local/apache 目录下,改参数用于自定义 Apache 的安装目录!

例如:./configure –prefix=/usr/local/apache

--enabled-moudles 用于指定除默认模块以外需要额外安装的 Apache 模块,不同模块之间用空

格分隔

--enabled-mods-shared 跟—enabled-moudles 相同,用于指定需要额外安装的模块在 Apache

运行的时候会自动载入

#编译参数

[root@Liangenyuhttpd-2.2.27]# ./configure

> --prefix=/application/apache2.2.27 #安装的目录

大提高传输速度,提示访问者访问体验,在生产环境中,这是 apache 调优的重要选项之一

> --enable-expires             #激活允许通过配置文件控制 http 的“expires”和“cache-control” 头内容,即对网站图片,js,css 等内容,提供在客户端浏览器缓存的设置,这是 apache 调优的重 要选项之一

> --enable-headers             #提供允许 http 请求头的控制

> --enable-moudles=most     #激活多数模块

> --enable-so                     #激活 apache 服务的 DSO 支持,即在以后可以以 DSO 的方式编译

安装共享模块,这个模块本身不能以 DSO 方式编译

> --with-mpm=worker          #选择 apache mpm 的模式为 worker 模式,因为 worker 模式原

理是更多的使用线程来处理请求,所以可以处理更多的并发请求,而系统资源的开销小于基于进程

的 MPM prefork,如果不指定此参数,默认得到模式是 prefork 进程模式。这是 apache 调优的一

个重要选项之一。

> --enable-rewrite                #提供基于 URL 规则的重写功能,根据已知 URL 地址,转换其他想

要的 url 地址,如伪静态功能就是这个模块实现的,这是 apache 在生产环节中必用的一个重要功能

可以使用./configure –help 命令来查看以上各个参数的用途

在安装 apache 软件包时,忘记安装以上模块,可以使用 dso 方式编译安装

检查编译结果:

检查是否有 error:

Echo $?

[root@Liangenyuhttpd-2.2.27]# echo $?

0

安装出现的错误:

checkingfor zlib location ..not found error:mod_deflate has been……. 解决方法:

yuminstall zlibzlib-devel –y

…………编译中…………………………..

make[1]: Leaving directory `/home/oldboy/tools/httpd-2.2.27' --à注意:此非错误信息 [root@Liangenyuhttpd-2.2.27]# make install

#最后创建软连接 apache

[root@Liangenyuhttpd-2.2.27]# ln -s /application/apache2.2.27/ /application/apache

#用软连接查看 apache 目录下的文件

[root@Liangenyuhttpd-2.2.27]# ll /application/apache

lrwxrwxrwx. 1 root root 26 12 月   4 22:08 /application/apache ->

/application/apache2.2.27/

[root@Liangenyuhttpd-2.2.27]# ls /application/apache/

总用量 60

drwxr-xr-x.   2 root root   4096 12 月 4 22:06 bin

drwxr-xr-x.   2 root root   4096 12 月 4 22:06 build

drwxr-xr-x.   2 root root   4096 12 月 4 22:06 cgi-bin

drwxr-xr-x.   4 root root   4096 12 月 4 22:06 conf

drwxr-xr-x.   3 root root   4096 12 月 4 22:06 error

drwxr-xr-x.   2 root root   4096 12 月 4 22:06 htdocs

drwxr-xr-x.   3 root root   4096 12 月 4 22:06 icons

drwxr-xr-x.   2 root root   4096 12 月 4 22:06 include

drwxr-xr-x.   3 root root   4096 12 月 4 22:06 lib

drwxr-xr-x.

2 root root

4096 12

4 22:06 logs

drwxr-xr-x.

4 root root

4096 12

4 22:06 man

drwxr-xr-x. 14 root root 12288 12 月  4 22:06 manual

drwxr-xr-x.    2 root root   4096 12 月  4 22:06 modules

# -t 参数是检查语法的意思

[root@Liangenyuhttpd-2.2.27]# /application/apache/bin/apachectl -t

Syntax OK#语法 ok

#启动 Apache 服务

#查看端口是否启用

[root@Liangenyuhttpd-2.2.27]# lsof -i :80

COMMAND    PID     USER     FD    TYPE DEVICE SIZE/OFF NODE NAME httpd     5437     root       4uIPv6    64183          0t0    TCP *:http (LISTEN) httpd              5440 daemon       4uIPv6    64183           0t0   TCP *:http (LISTEN) httpd     5441 daemon       4uIPv6    64183           0t0   TCP *:http (LISTEN)

httpd     5442 daemon       4uIPv6    64183           0t0   TCP *:http (LISTEN)

#测试 apache 是否安装成功的 2 个方法:

1.浏览器中输入服务器 IP 地址,出现以下图示,证明安装 apache 成功了!

2.

[root@Liangenyuhttpd-2.2.27]# wget 192.168.1.33

--2014-12-04 22:19:50--    http://192.168.1.33/

正在连接 192.168.1.33:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:44 [text/html]

正在保存至: “index.html”

100%[=================================================>] 44

--.-K/s     in 0s

2014-12-04 22:19:50 (9.74 MB/s) - 已保存“index.html” [44/44])

#如果不能够正常访问,请检查 iptables,selinux 是否已经正常关闭!

原文地址:https://www.cnblogs.com/fanweisheng/p/11327784.html