一、环境
系统:CentOS 6.4x64最小化安装
IP:192.168.3.54
二、下载软件包
apache官网www.apache.org上有提供源码下载
[root@httpd ~]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.12.tar.gz
三、安装
解压并安装
[root@httpd ~]# tar xf httpd-2.4.12.tar.gz [root@httpd ~]# cd httpd-2.4.12 [root@httpd httpd-2.4.12]# ./configure > --prefix=/usr/local/apache-2.4.12 > --enable-deflate \ #压缩 > --enable-expires \ #缓存 > --enable-headers > --enable-modules=most > --enable-so > --with-mpm=worker \ #worker模型 > --enable-rewrite \ #rewrite重写规则 > --with-apr=/usr/local/apr > --with-apr-util=/usr/local/apr-util > --enable-ssl #支持ssl checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E 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 configure: configure: Configuring Apache Portable Runtime library... configure: checking for APR... no configure: error: APR not found. Please read the documentation. #结果显示我们需要安装apr apr-util,pcre-devel,openssl-devel #下载apr和apr-util [root@httpd ~]# wget [root@httpd ~]# wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz #先安装pcre-devel,apr [root@httpd httpd-2.4.12]# yum install pcre-devel openssl-devel -y [root@httpd ~]# tar xf apr-1.5.2.tar.gz [root@httpd ~]# cd apr-1.5.2 [root@httpd apr-1.5.2]# ./configure --prefix=/usr/local/apr [root@httpd apr-1.5.2]# make && make install #安装apr-util [root@httpd ~]# tar xf apr-util-1.5.4.tar.gz [root@httpd ~]# cd apr-util-1.5.4 [root@httpd apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@httpd apr-util-1.5.4]# make && make install #再次安装httpd [root@httpd httpd-2.4.12]# ./configure --prefix=/usr/local/apache-2.4.12 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util [root@httpd httpd-2.4.12]# make && make install
安装完成后,创建软连接,方便管理
[root@httpd ~]# ln -s /usr/local/apache-2.4.12/ /usr/local/apache
创建httpd启动脚本文件,httpd的启动脚本可以将/usr/local/apache/bin/apachectl复制到/etc/init.d目录下。这里我们选择手动创建启动脚本文件
[root@httpd ~]# vim /etc/init.d/httpd #!/bin/bash # # Startup script for the Apache Web Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is used to serve # HTML files and CGI. # processname: httpd # pidfile: /usr/local/apache2/logs/httpd.pid # config: /usr/local/apache2/conf/httpd.conf # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl httpd=/usr/local/apache/bin/httpd pid=$httpd/logs/httpd.pid prog=httpd RETVAL=0 # The semantics of these two functions differ from the way apachectl does # things -- attempting to start while running is a failure, and shutdown # when not running is also a failure. So we just do it the way init scripts # are expected to behave here. start() { echo -n $"Starting $prog: " daemon $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd $pid } reload() { echo -n $"Reloading $prog: " killproc $httpd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status $httpd RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f $pid ] ; then stop start fi ;; reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status" echo $"|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL #启动httpd服务 root@httpd ~]# /etc/init.d/httpd start Starting httpd: AH00557: httpd: apr_sockaddr_info_get() failed for httpd AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName‘ directive globally to suppress this message [ OK ] #提示有FQDN错误,解决如下 [root@httpd ~]# echo "ServerName localhost:80" >>/usr/local/apache/conf/httpd.conf #重新启动httpd服务 [root@httpd ~]# /etc/init.d/httpd stop Stopping httpd: [ OK ] [root@httpd ~]# /etc/init.d/httpd start Starting httpd: [ OK ] [root@httpd ~]# netstat -anpt |grep httpd tcp 0 0 :::80 :::* LISTEN 59398/httpd
在客户端访问httpd服务
通过以上步骤apache已成功安装,服务也正常启动,最后将httpd服务添加到开机自动启动
[root@httpd ~]# chkconfig --add httpd [root@httpd ~]# chkconfig httpd on [root@httpd ~]# chkconfig |grep http httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
本文出自 “ly36843运维” 博客,请务必保留此出处http://ly36843.blog.51cto.com/3120113/1642118
原文地址:http://ly36843.blog.51cto.com/3120113/1642118