3r211 发表于 2014-9-4 09:04:30

LAMP编译安装之———httpd

LAMP(Linux- Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据 库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和 Java/J2EE架构相比,LAMP具有Web资源丰富、轻量、快速开发等特点,微软的.NET架构相比,LAMP具有通用、跨平台、高性能、低价格的 优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。    本节我们先来编译安装一下httpd,废话不多说。
    httpd-2.4.9需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里选择使用编译源代码的方式进行。
(1) 编译安装apr

1
2
3
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr






注意:在编译的时候你可能也会碰到和我一样的错误

1
2
3
4
rm: cannot remove `libtoolT': No such file or directory
config.status: executing default commands
config.status: include/apr.h is unchanged
config.status: include/arch/unix/apr_private.h is unchanged




我从网上找到的解决方法
vim configure
修改一下选项
$RM "$cfgfile"

$RM -f "$cfgfile"

确认没有问题就执行

1
# make && make install




(2) 编译安装apr-util

1
2
3
# tar xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr




注意这里apr指向的是刚刚编译安装的Apr路径

确认没有问题就执行

1
# make && make install





(3)编译安装httpd
httpd-2.4.9编译过程也要依赖于pcre-devel软件包,需要事先安装。此软件包系统光盘自带,因此,找到并安装即可。这里我就不演示了。
下面我们就开始编译安装httpd-2.4.9了。

1
2
3
# tar xf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event






确认没有问题就执行

1
# make && make install





(4)修改httpd的主配置文件,设置其Pid文件的路径
编辑/etc/httpd24/httpd.conf,添加如下行即可:

1
# vim /etc/httpd24/httpd.conf




PidFile"/var/run/httpd.pid"

这样我们的httpd服务就已经安装成功了,我们可以启动下试试。
注意我们的安装路径,我们的执行脚本的位置是在/usr/local/apache/bin/下,因此我们先cd进去。

1
2
3
# cd /usr/local/apache/bin/
# ls
abapachectlapxscheckgiddbmmanageenvvarsenvvars-stdfcgistarterhtcachecleanhtdbmhtdigesthtpasswdhttpdhttxt2dbmlogresolverotatelogs




然后就可以执行了

注意,在执行的时候可以会有这样的警告,这是我们可以去配置文件中修改ServerName这一项

1
# vim /etc/httpd24/httpd.conf




启用并修改成localhost

修改完之后我们的服务就可以启用了
当命令输错时会有提示

按照提示可以知道我们可以通过以下命令打开

1
# ./httpd -k start




现在我们可以通过windows上的浏览器来验证下是否可以用了

没错,这样我们的httpd就完成了。

(5)提供SysV服务脚本
如果你想让httpd24可以向其它那些服务脚本一样可以通过servcie service_name start|stop|restart|status等命令来使用的话只需要在/etc/rc.d/init.d/下建立相应的脚本即可。

1
# vim /etc/rc.d/init.d/httpd24





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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
#
# httpd      Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.It is used to serve
#      HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
      . /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0

start() {
      echo -n $"Starting $prog: "
      LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
      RETVAL=$?
      echo
      [ $RETVAL = 0 ] && touch ${lockfile}
      return $RETVAL
}

stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
      RETVAL=$?
      echo $"not reloading due to configuration syntax error"
      failure $"not reloading $httpd due to configuration syntax error"
    else
      killproc -p ${pidfile} $httpd -HUP
      RETVAL=$?
    fi
    echo
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
      status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
    stop
    start
fi
;;
reload)
      reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac

exit $RETVAL






当然想要执行必须给此脚本赋予执行权限:

1
# chmod +x /etc/rc.d/init.d/httpd24




服务脚本创建好之后还需要加入服务列表,并启用:



好了,那么这样我们的HTTP服务器就编译安装成功了!

页: [1]
查看完整版本: LAMP编译安装之———httpd