菜鳥學Linux第058篇筆記httpd編譯安裝

科技探索者發表於2017-11-13

菜鳥學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


相關文章