下载

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz
 [root@localhost src]# wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.31.tar.bz2
--2016-08-01 01:22:13--  http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.31.tar.b   z2
正在解析主机 mirrors.hust.edu.cn... 202.114.18.160
正在连接 mirrors.hust.edu.cn|202.114.18.160|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:5610489 (5.3M) [application/octet-stream]
正在保存至: “httpd-2.2.31.tar.bz2”
2016-08-01 01:22:44 (180 KB/s) - 已保存 “httpd-2.2.31.tar.bz2” [5610489/5610489])
[root@localhost src]# ls
httpd-2.2.31.tar.bz2  mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz

解压

[root@localhost src]# tar jvxf httpd-2.2.31.tar.bz2
[root@localhost src]# ls
httpd-2.2.31  httpd-2.2.31.tar.bz2  mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz

查看INSTALL文件

[root@localhost src]# cd httpd-2.2.31
[root@localhost httpd-2.2.31]# ls
ABOUT_APACHE  config.layout  httpd.spec      LICENSE        README.platforms
acinclude.m4  configure      include         Makefile.in    README-win32.txt
Apache.dsw    configure.in   INSTALL         Makefile.win   ROADMAP
build         docs           InstallBin.dsp  modules        server
BuildAll.dsp  emacs-style    LAYOUT          NOTICE         srclib
BuildBin.dsp  httpd.dep      libhttpd.dep    NWGNUmakefile  support
buildconf     httpd.dsp      libhttpd.dsp    os             test
CHANGES       httpd.mak      libhttpd.mak    README         VERSIONING
[root@localhost httpd-2.2.31]# vim INSTALL

为了避免出错,先安装一些库文件

[root@localhost httpd-2.2.31]# yum install -y zlib-devel
[root@localhost httpd-2.2.31]# yum install -y pcre pcre-devel apr apr-devel

配置编译参数

[root@localhost httpd-2.2.31]# ./configure \
> --prefix=/usr/local/apache2 \
> --with-included-apr \
> --enable-so \
> --enable-deflate=shared \
> --enable-expires=shared \
> --enable-rewrite=shared \
> --with-pcre

checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu

Configuring Apache Portable Runtime library ...

configuring package in srclib/apr now
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
Configuring APR library
Platform: x86_64-unknown-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.5.2
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/httpd-2.2.31/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
configure failed for srclib/apr

出错了……

解决方案:

[root@localhost httpd-2.2.31]# yum install gcc

重新配置编译参数

[root@localhost httpd-2.2.31]# ./configure \
> --prefix=/usr/local/apache2 \
> --with-included-apr \
> --enable-so \
> --enable-deflate=shared \
> --enable-expires=shared \
> --enable-rewrite=shared \
> --with-pcre
[root@localhost httpd-2.2.31]# echo $?
0

编译和安装

[root@localhost httpd-2.2.31]# make
[root@localhost httpd-2.2.31]# echo $?
0
[root@localhost httpd-2.2.31]# make install
[root@localhost httpd-2.2.31]# echo $?
0

安装后

[root@localhost httpd-2.2.31]# ls /usr/local/apache2/
bin    cgi-bin  error   icons    lib   man     modules
build  conf     htdocs  include  logs  manual

启动Apache

[root@localhost httpd-2.2.31]# /usr/local/apache2/bin/apachectl start
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName

[root@localhost httpd-2.2.31]# ps aux |grep httpd
root     52131  0.0  0.1  37556  1788 ?        Ss   02:48   0:00 /usr/local/apache2/bi                                                                                  n/httpd -k start
daemon   52132  0.0  0.1  37688  1260 ?        S    02:48   0:00 /usr/local/apache2/bi                                                                                  n/httpd -k start
daemon   52133  0.0  0.1  37688  1260 ?        S    02:48   0:00 /usr/local/apache2/bi                                                                                  n/httpd -k start
daemon   52134  0.0  0.1  37688  1260 ?        S    02:48   0:00 /usr/local/apache2/bi                                                                                  n/httpd -k start
daemon   52135  0.0  0.1  37688  1260 ?        S    02:48   0:00 /usr/local/apache2/bi                                                                                  n/httpd -k start
daemon   52136  0.0  0.1  37688  1260 ?        S    02:48   0:00 /usr/local/apache2/bi                                                                                  n/httpd -k start
root     52138  0.0  0.0 103316   896 pts/0    S+   02:52   0:00 grep httpd
[root@localhost httpd-2.2.31]# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State                                                                                       PID/Program name
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN                                                                                      1335/sshd
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN                                                                                      1682/master
tcp        0      0 :::3306                     :::*                        LISTEN                                                                                      1578/mysqld
tcp        0      0 :::80                       :::*                        LISTEN                                                                                      52131/httpd
tcp        0      0 :::22                       :::*                        LISTEN                                                                                      1335/sshd
tcp        0      0 ::1:25                      :::*                        LISTEN                                                                                      1682/master
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node PID/Program name    Path
unix  2      [ ACC ]     STREAM     LISTENING     11827  1578/mysqld         /tmp/mysql.                                                                                sock
unix  2      [ ACC ]     STREAM     LISTENING     11460  1260/dbus-daemon    /var/run/db                                                                                us/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     9110   1/init              @/com/ubunt                                                                                u/upstart
unix  2      [ ACC ]     STREAM     LISTENING     12046  1682/master         public/clea                                                                                nup
unix  2      [ ACC ]     STREAM     LISTENING     12053  1682/master         private/tls                                                                                mgr
unix  2      [ ACC ]     STREAM     LISTENING     12057  1682/master         private/rew                                                                                rite
unix  2      [ ACC ]     STREAM     LISTENING     12061  1682/master         private/bou                                                                                nce
unix  2      [ ACC ]     STREAM     LISTENING     12065  1682/master         private/def                                                                                er
unix  2      [ ACC ]     STREAM     LISTENING     12069  1682/master         private/tra                                                                                ce
unix  2      [ ACC ]     STREAM     LISTENING     12073  1682/master         private/ver                                                                                ify
unix  2      [ ACC ]     STREAM     LISTENING     12077  1682/master         public/flus                                                                                h
unix  2      [ ACC ]     STREAM     LISTENING     12081  1682/master         private/pro                                                                                xymap
unix  2      [ ACC ]     STREAM     LISTENING     12085  1682/master         private/pro                                                                                xywrite
unix  2      [ ACC ]     STREAM     LISTENING     12089  1682/master         private/smt                                                                                p
unix  2      [ ACC ]     STREAM     LISTENING     12093  1682/master         private/rel                                                                                ay
unix  2      [ ACC ]     STREAM     LISTENING     12097  1682/master         public/show                                                                                q
unix  2      [ ACC ]     STREAM     LISTENING     12101  1682/master         private/err                                                                                or
unix  2      [ ACC ]     STREAM     LISTENING     12105  1682/master         private/ret                                                                                ry
unix  2      [ ACC ]     STREAM     LISTENING     12109  1682/master         private/dis                                                                                card
unix  2      [ ACC ]     STREAM     LISTENING     12113  1682/master         private/loc                                                                                al
unix  2      [ ACC ]     STREAM     LISTENING     12117  1682/master         private/vir                                                                                tual
unix  2      [ ACC ]     STREAM     LISTENING     12121  1682/master         private/lmt                                                                                p
unix  2      [ ACC ]     STREAM     LISTENING     12125  1682/master         private/anv                                                                               il
unix  2      [ ACC ]     STREAM     LISTENING     12129  1682/master         private/sca                                                                          che

查看Apache工作模式

[root@localhost httpd-2.2.31]# /usr/local/apache2/bin/apachectl -M
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Loaded Modules:
 core_module (static)
 authn_file_module (static)
 authn_default_module (static)
 authz_host_module (static)
 authz_groupfile_module (static)
 authz_user_module (static)
 authz_default_module (static)
 auth_basic_module (static)
 include_module (static)
 filter_module (static)
 log_config_module (static)
 env_module (static)
 setenvif_module (static)
 version_module (static)
 mpm_prefork_module (static)
 http_module (static)
 mime_module (static)
 status_module (static)
 autoindex_module (static)
 asis_module (static)
 cgi_module (static)
 negotiation_module (static)
 dir_module (static)
 actions_module (static)
 userdir_module (static)
 alias_module (static)
 so_module (static)
 deflate_module (shared)
 expires_module (shared)
 rewrite_module (shared)
Syntax OK

静态与动态模块

[root@localhost httpd-2.2.31]# ls /usr/local/apache2/modules/
httpd.exp  mod_deflate.so  mod_expires.so  mod_rewrite.so
[root@localhost httpd-2.2.31]# ls /usr/local/apache2/bin/httpd
/usr/local/apache2/bin/httpd
[root@localhost httpd-2.2.31]# du -sh !$
du -sh /usr/local/apache2/bin/httpd
2.1M    /usr/local/apache2/bin/httpd

只查看静态模块

[root@localhost httpd-2.2.31]# /usr/local/apache2/bin/apachectl –l
Compiled in modules:
  core.c
  mod_authn_file.c
  mod_authn_default.c
  mod_authz_host.c
  mod_authz_groupfile.c
  mod_authz_user.c
  mod_authz_default.c
  mod_auth_basic.c
  mod_include.c
  mod_filter.c
  mod_log_config.c
  mod_env.c
  mod_setenvif.c
  mod_version.c
  prefork.c
  http_core.c
  mod_mime.c
  mod_status.c
  mod_autoindex.c
  mod_asis.c
  mod_cgi.c
  mod_negotiation.c
  mod_dir.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  mod_so.c

配置文件

查看配置文件有没有语法错误

[root@localhost httpd-2.2.31]# /usr/local/apache2/bin/apachectl -t
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK

配置文件

[root@localhost httpd-2.2.31]# ls /usr/local/apache2/conf/httpd.conf
/usr/local/apache2/conf/httpd.conf

为了去掉一直提示的警告

httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName

解决方案:

[root@localhost httpd-2.2.31]# vim /usr/local/apache2/conf/httpd.conf
找到#ServerName www.example.com:80
去掉注释并修改为
ServerName localhost.localdomain

重新启动Apache

[root@localhost httpd-2.2.31]# /usr/local/apache2/bin/apachectl restart

restart与graceful的区别

  • /usr/local/apache2/bin/apachectl restart
  • /usr/local/apache2/bin/apachectl graceful

    restart杀掉进程再重新开启新的进程;graceful是原来的进程还在,只是重新加载了配置文件