Apache HTTP Server:编译与安装
首先,你需要获得Apache HTTP Server的安装介质。
该部分的信息如下:
————————————————————————————————————————————————
官方网站:http://httpd.apache.org/
最新发行版为:2.4
文档页:http://httpd.apache.org/docs/2.4/
————————————————————————————————————————————————
本文参考官方文档:编译与安装。
原文地址:http://httpd.apache.org/docs/2.4/install.html
该文档适用于Unix和类Unix操作系统平台。
如果需要了解在Microsoft Windows平台上的技术细节,参阅:
1.Using Apache HTTP Server with Microsoft Windows(使用Apache)
http://httpd.apache.org/docs/2.4/platform/windows.html
2.Compiling Apache for Microsoft Windows(编译Apache)
http://httpd.apache.org/docs/2.4/platform/win_compiling.html
在编译[./configure]前,需要保证操作系统安装了:libtool和autoconf。
Apache HTTPD需要使用它们来创建build环境(该过程是为源码包安装的第二步[make/make install]服务的)
如果你已经部署过Apache HTTP Server,需要对其版本升级,那么你需要查阅:升级部分,以确认技术细节(URL:http://httpd.apache.org/docs/2.4/install.html#upgrading)
安装HTTP Server的其他需求:
1.APR/APR-Util(URL:http://apr.apache.org/)
2.PCRE(Perl-Compatible Regular Expressions Library)
3.Ansi-C Compiler(yum install gcc)
4.apxs
关于HTTP Server主机的说明:
OS Version:Red Hat Enterprise Linux 5 Update 10
1 2 3 4 5 6 7 8 9 10 |
[root@webserver ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.10 (Tikanga) [root@webserver ~]# [root@webserver ~]# lsb_release -a LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch Distributor ID: RedHatEnterpriseServer Description: Red Hat Enterprise Linux Server release 5.10 (Tikanga) Release: 5.10 Codename: Tikanga [root@webserver ~]# |
网络相关配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[root@webserver ~]# cat /etc/hosts # Do not remove the following line, or various programs # that require network functionality will fail. # Localhost 127.0.0.1 # Public 192.168.119.141 webserver [root@webserver ~]# [root@webserver ~]# ifconfig -a eth0 Link encap:Ethernet HWaddr 00:0C:29:86:BE:84 inet addr:192.168.119.141 Bcast:192.168.119.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe86:be84/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:51659 errors:0 dropped:0 overruns:0 frame:0 TX packets:27114 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:54138691 (51.6 MiB) TX bytes:1824547 (1.7 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:2633 errors:0 dropped:0 overruns:0 frame:0 TX packets:2633 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:6727512 (6.4 MiB) TX bytes:6727512 (6.4 MiB) sit0 Link encap:IPv6-in-IPv4 NOARP MTU:1480 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@webserver ~]# |
IPTables与Selinux:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[root@webserver ~]# service iptables status Firewall is stopped. [root@webserver ~]# chkconfig --list iptables iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@webserver ~]# [root@webserver ~]# sestatus SELinux status: disabled [root@webserver ~]# [root@webserver ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - SELinux is fully disabled. SELINUX=disabled # SELINUXTYPE= type of policy in use. Possible values are: # targeted - Only targeted network daemons are protected. # strict - Full SELinux protection. SELINUXTYPE=targeted [root@webserver ~]# |
磁盘使用量:
1 2 3 4 5 6 7 |
[root@webserver ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 2.6G 14G 16% / /dev/sda1 289M 17M 258M 7% /boot tmpfs 500M 0 500M 0% /dev/shm /dev/sr1 4.1G 4.1G 0 100% /iso [root@webserver ~]# |
YUM状态:
1 2 3 4 5 6 7 8 9 10 |
[root@webserver ~]# yum repolist Loaded plugins: product-id, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. repo id repo name status Cluster Cluster 32 ClusterStorage ClusterStorage 39 Server Server 3,358 VT VT 59 repolist: 3,488 [root@webserver ~]# |
介质临时存储目录:/software
上传介质到服务器:
1 2 3 4 5 6 |
[root@webserver ~]# cd /software [root@webserver software]# ll total 6852 -rw-r--r-- 1 root root 6820719 Aug 19 16:01 httpd-2.4.10.tar.gz -rw-r--r-- 1 root root 172415 Aug 19 10:57 mod_cluster-1.2.6.Final-linux2-x64-so.tar.gz [root@webserver software]# |
解压:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@webserver software]# gzip -d httpd-2.4.10.tar.gz [root@webserver software]# ll total 33280 -rw-r--r-- 1 root root 33856000 Aug 19 16:01 httpd-2.4.10.tar -rw-r--r-- 1 root root 172415 Aug 19 10:57 mod_cluster-1.2.6.Final-linux2-x64-so.tar.gz [root@webserver software]# tar -xf httpd-2.4.10.tar [root@webserver software]# ll total 33284 drwxr-xr-x 11 501 games 4096 Jul 16 01:15 httpd-2.4.10 -rw-r--r-- 1 root root 33856000 Aug 19 16:01 httpd-2.4.10.tar -rw-r--r-- 1 root root 172415 Aug 19 10:57 mod_cluster-1.2.6.Final-linux2-x64-so.tar.gz [root@webserver software]# ls httpd-2.4.10 ABOUT_APACHE apache_probes.d BuildBin.dsp config.layout emacs-style INSTALL LICENSE NOTICE README.cmake srclib acinclude.m4 ap.d buildconf configure httpd.dsp InstallBin.dsp Makefile.in NWGNUmakefile README.platforms support Apache-apr2.dsw build CHANGES configure.in httpd.spec LAYOUT Makefile.win os ROADMAP test Apache.dsw BuildAll.dsp CMakeLists.txt docs include libhttpd.dsp modules README server VERSIONING [root@webserver software]# |
创建HTTP Server的安装路径:
1 2 3 4 5 |
[root@webserver software]# mkdir /httpd [root@webserver software]# ll -d /httpd/ drwxr-xr-x 2 root root 4096 Aug 19 16:02 /httpd/ [root@webserver software]# ls /httpd/ [root@webserver software]# |
编译:./configure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[root@webserver software]# cd httpd-2.4.10 [root@webserver httpd-2.4.10]# ./configure --prefix=/httpd/ (... ...etc) creating srclib/Makefile creating os/Makefile creating server/Makefile creating support/Makefile creating test/Makefile config.status: creating docs/conf/httpd.conf config.status: creating docs/conf/extra/httpd-autoindex.conf config.status: creating docs/conf/extra/httpd-dav.conf config.status: creating docs/conf/extra/httpd-default.conf config.status: creating docs/conf/extra/httpd-info.conf config.status: creating docs/conf/extra/httpd-languages.conf config.status: creating docs/conf/extra/httpd-manual.conf config.status: creating docs/conf/extra/httpd-mpm.conf config.status: creating docs/conf/extra/httpd-multilang-errordoc.conf config.status: creating docs/conf/extra/httpd-ssl.conf config.status: creating docs/conf/extra/httpd-userdir.conf config.status: creating docs/conf/extra/httpd-vhosts.conf config.status: creating docs/conf/extra/proxy-html.conf config.status: creating include/ap_config_layout.h config.status: creating support/apxs config.status: creating support/apachectl config.status: creating support/dbmmanage config.status: creating support/envvars-std config.status: creating support/log_server_status config.status: creating support/logresolve.pl config.status: creating support/phf_abuse_log.cgi config.status: creating support/split-logfile config.status: creating build/rules.mk config.status: creating build/pkg/pkginfo config.status: creating build/config_vars.sh config.status: creating include/ap_config_auto.h config.status: executing default commands [root@webserver httpd-2.4.10]# |
编译:make
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@webserver httpd-2.4.10]# make (... ...输出) make[4]: Nothing to be done for `local-shared-build'. make[4]: Leaving directory `/software/httpd-2.4.10/modules/dav/fs' make[3]: Leaving directory `/software/httpd-2.4.10/modules/dav/fs' make[3]: Entering directory `/software/httpd-2.4.10/modules/mappers' Building shared: mod_vhost_alias.la mod_negotiation.la mod_dir.la mod_actions.la mod_speling.la mod_userdir.la mod_alias.la mod_rewrite.la make[4]: Entering directory `/software/httpd-2.4.10/modules/mappers' make[4]: Nothing to be done for `local-shared-build'. make[4]: Leaving directory `/software/httpd-2.4.10/modules/mappers' make[3]: Leaving directory `/software/httpd-2.4.10/modules/mappers' make[2]: Leaving directory `/software/httpd-2.4.10/modules' make[2]: Entering directory `/software/httpd-2.4.10/support' make[2]: Leaving directory `/software/httpd-2.4.10/support' make[1]: Leaving directory `/software/httpd-2.4.10' [root@webserver httpd-2.4.10]# |
编译:make install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
[root@webserver httpd-2.4.10]# make install (... ...输出) make[3]: Leaving directory `/software/httpd-2.4.10/modules/mappers' make[2]: Leaving directory `/software/httpd-2.4.10/modules' make[2]: Entering directory `/software/httpd-2.4.10/support' make[2]: Leaving directory `/software/httpd-2.4.10/support' Installing configuration files mkdir /httpd/conf mkdir /httpd/conf/extra mkdir /httpd/conf/original mkdir /httpd/conf/original/extra Installing HTML documents mkdir /httpd/htdocs Installing error documents mkdir /httpd/error Installing icons mkdir /httpd/icons mkdir /httpd/logs Installing CGIs mkdir /httpd/cgi-bin Installing header files mkdir /httpd/include Installing build system files mkdir /httpd/build Installing man pages and online manual mkdir /httpd/man mkdir /httpd/man/man1 mkdir /httpd/man/man8 mkdir /httpd/manual make[1]: Leaving directory `/software/httpd-2.4.10' [root@webserver httpd-2.4.10]# |
这样,HTTP Server就安装好了。
它的配置文件为:$HTTPD_HOME/conf/httpd.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[root@webserver httpd-2.4.10]# cd /httpd/ [root@webserver httpd]# ls bin build cgi-bin conf error htdocs icons include logs man manual modules [root@webserver httpd]# ll total 56 drwxr-xr-x 2 root root 4096 Aug 19 16:50 bin drwxr-xr-x 2 root root 4096 Aug 19 16:50 build drwxr-xr-x 2 root root 4096 Aug 19 16:50 cgi-bin drwxr-xr-x 4 root root 4096 Aug 19 16:50 conf drwxr-xr-x 3 root root 4096 Aug 19 16:50 error drwxr-xr-x 2 root root 4096 Aug 19 16:02 htdocs drwxr-xr-x 3 root root 4096 Aug 19 16:50 icons drwxr-xr-x 2 root root 4096 Aug 19 16:50 include drwxr-xr-x 2 root root 4096 Aug 19 16:50 logs drwxr-xr-x 4 root root 4096 Aug 19 16:50 man drwxr-xr-x 14 root root 12288 Jul 16 01:15 manual drwxr-xr-x 2 root root 4096 Aug 19 16:50 modules [root@webserver httpd]# ls conf/ extra httpd.conf magic mime.types original [root@webserver httpd]# ll conf/httpd.conf -rw-r--r-- 1 root root 18000 Aug 19 16:50 conf/httpd.conf [root@webserver httpd]# |
启动程序:$HTTPD_HOME/bin/apachectl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
[root@webserver httpd]# netstat -tupln | grep 80 [root@webserver httpd]# bin/apachectl -h Usage: /httpd//bin/httpd [-D name] [-d directory] [-f file] [-C "directive"] [-c "directive"] [-k start|restart|graceful|graceful-stop|stop] [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X] Options: -D name : define a name for use in <IfDefine name> directives -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile -C "directive" : process directive before reading config files -c "directive" : process directive after reading config files -e level : show startup errors of level (see LogLevel) -E file : log startup errors to file -v : show version number -V : show compile settings -h : list available command line options (this page) -l : list compiled in modules -L : list available configuration directives -t -D DUMP_VHOSTS : show parsed vhost settings -t -D DUMP_RUN_CFG : show parsed run settings -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG -t -D DUMP_MODULES : show all loaded modules -M : a synonym for -t -D DUMP_MODULES -t : run syntax check for config files -T : start without DocumentRoot(s) check -X : debug mode (only one worker, do not detach) [root@webserver httpd]# [root@webserver httpd]# bin/apachectl -k start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.119.141. Set the 'ServerName' directive globally to suppress this message [root@webserver httpd]# [root@webserver httpd]# netstat -tupln | grep 80 tcp 0 0 :::80 :::* LISTEN 9045/httpd [root@webserver httpd]# [root@webserver httpd]# ps -ef | grep httpd root 9045 1 0 16:57 ? 00:00:00 /httpd//bin/httpd -k start daemon 9046 9045 0 16:57 ? 00:00:00 /httpd//bin/httpd -k start daemon 9047 9045 0 16:57 ? 00:00:00 /httpd//bin/httpd -k start daemon 9050 9045 0 16:57 ? 00:00:00 /httpd//bin/httpd -k start root 9136 1521 0 16:57 pts/2 00:00:00 grep httpd [root@webserver httpd]# [root@webserver httpd]# |
浏览器:http://192.168.119.141:80
——————————————————————————————————
Ending。