且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

菜鸟学Linux 第058篇笔记 httpd编译安装

更新时间:2022-10-04 11:02:23

菜鸟学Linux 第058篇笔记 httpd编译安装



PHP: 脚本编程语言,php解释器

WebApp: 面向对象的特性

Zend引擎:

第一段: 语法分析、语法分析、编译为Opcode;

opcode旋转于内存中

第二段: 执行Opcode;


PHP 缓存器

APC

eAccelerator

XCache



PHP解释器-->MySQL, 如何交互?

bash: a.sh

PHP程序 : b.php

php53-mysql 驱动

httpd+php:

CGI

module

FastCGI/fpm   port: 9000




web性能优化(动态内容静态化)

httpd 

缓存:可以把动态脚本执行后所返回的内容存储在httpd的缓存里,

  第二次有用户再请求时,则可快速响应

应用程序服务器

缓存:可以把用户所请求的动态代码,编译成二进制可执行的格式

  并放入缓存中,第二次有其它用户请求时,则可直接执行,而不

  再进行编译的过程


编译配置LAMP:

Linux, Apache, MySQL, PHP(Python, Perl)

编译安装顺序

httpd --> MySQL --> php --> XCache


Apache: ASF(apache软件基金会), httpd, tomcat, cloudware

httpd 2.4.4

php 5.4.13

MySQL 5.5  (rpm,通用二进制,源码)


rpm包

/bin, /sbin, /usr/bin, /usr/sbin

/lib, /usr/lib

/etc

/usr/share/{doc,man}


编译安装

/usr/local/

bin, sbin

lib

etc

share/{doc,man}

/usr/local/apr/

bin, sbin, lib, includes, etc, share/man

(注意需要添加环境变量,库连接,man文档)


httpd编译安装

apr: Apache Portable Runtime

apr apr-util apr-iconv

安装顺序: apr --> apr-util --> httpd

下载apr apr-util httpd  www.apache.org

安装apr 

# tar -xf apr-1.5.2.tar.gz

# cd apr-1.5.2

# ./configure --prefix=/usr/local/apr

# make

# make install

安装apr-util 

# tar -xf apr-util-1.5.4.tar.gz

# cd apr-util-1.5.4

# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

# make

# make install


安装httpd 

# tar -xf httpd-2.4.25.tar.bz2

# cd httpd-2.4.25.tar.bz2

./configure --prefix=PATH --sysconfdir=PATH 

--enable-so --enable-ssl --enable-deflate --enable-proxy-fcgi

--enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most

--enable-mpms-shared={prefork|worker|event|all 可多选} --with-mpm=event

--enable-rewrite 

--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  (注意这些是一行内容)

        # make

        # make install

/etc/httpd/httpd.conf

Pidfile "/var/run/httpd.pid"


vim /etc/rc.d/init/httpd

#!/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


chmod +x /etc/init.d/httpd

chkconfig -add httpd

chkconfig --level 35 httpd on


添加环境变量 /etc/profile.d/

vim httpd.sh

export PATH=$PATH:/usr/local/apache/bin 

(不会立即生效,需要重新打开shell)


变更模块 /etc/httpd/httpd.conf

#LoadModule env_module modules/mod_env.so

LoadModule prefork_module modules/mod_prefork.so


(到此编译安装httpd结束)



httpd 2.4新特性

1、MPM可于运行时装载

2、Event MPM 可正式使用

3、异步读写

5、每请求配置:<If>, <ElseIf>, <Else>;

6、增强的表达式分析器;

7、毫秒组的KeepAlive Timeout;

8、基于域名的虚拟主机不再需要NameVirtualHost指令

9、降低了内存占用

10、支持在配置文件中使用自定义变量;


新增加的模块

mod_proxy_fcgi

mod_proxy_scgi

等等




对于基于IP的访问控制

废除

Order allow,deny

allow from all

2.4使用Require user

Require (not) ip IPADDR

IP

NETWORK/MASK

NETWORK/LENGTH

NET

172.16.0.0/255.255.0.0 = 172.16.0.0/16 = 172.16

Requre host HOSTNAME

HOSTNAME

DOMAIN

www.mysky.com

mysky.com

所有主机

Require all granted

Require all deny

本文转自Winthcloud博客51CTO博客,原文链接http://blog.51cto.com/winthcloud/1885738如需转载请自行联系原作者


Winthcloud