Jun 24

[Linux] 从源码编译安装Apache+FastCgi+PHP 不指定

felix021 @ 2011-6-24 12:39 [IT » 软件] 评论(0) , 引用(0) , 阅读(5817) | Via 本站原创 | |
使用以下脚本来编译安装,需要把安装文件下载到 [ROOT]/src/ 下。

目录结构:

[ROOT]
    /src
        /php-5.2.17.tar.bz2
        ...
    /httpd
    /php
    /fcgi-bin

#!/bin/bash

set -x

ROOT="/home/felix021/lamp"
ROOT_E=${ROOT//\//\\\/}        # escape for sed, / => \/

WWWROOT="/home/felix021/lamp/wwwroot"
WWWROOT_E=${WWWROOT//\//\\\/}  # escape for sed, / => \/

HTTPD_PORT=80

FCGI_CHILDREN=4
FCGI_MAX_REQUESTS=1000

# 下载好的源码文件
fastcgi="mod_fastcgi-2.4.6"        #.tar.gz
httpd="httpd-2.2.17"                #.tar.bz2
php="php-5.2.17"                    #.tar.bz2
eaccelerator="eaccelerator-0.9.6.1" #.tar.bz2

SRCROOT=${ROOT}/src
mkdir -p $ROOT/{httpd,php,fcgi-bin}
mkdir -p $WWWROOT

# fcgi-bin (for apache + mod_fastcgi) 
# 创建这个脚本可以用来包装php-cgi,可以控制启动的FCGI进程数量
if [ ! -e "${ROOT}/fcgi-bin/php.cgi" ]; then
    > ${ROOT}/fcgi-bin/php.cgi echo "#!/bin/sh
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x

### Set PATH ###
PHP_CGI=${ROOT}/php/bin/php-cgi
PHP_FCGI_CHILDREN=${FCGI_CHILDREN}
PHP_FCGI_MAX_REQUESTS=${FCGI_MAX_REQUESTS}

### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec \$PHP_CGI
"
    chmod +x ${ROOT}/fcgi-bin/php.cgi
fi

# php
cd $SRCROOT
if [ ! -d "${php}" ]; then
    tar jxf ${php}.tar.bz2
    cd $php
    ./configure --prefix=${ROOT}/php --with-gd --with-iconv \
        --with-curl --enable-fastcgi --with-openssl --enable-mbstring  #有需要的话自己再增加一些模块吧
    echo Making... Please wait. "tail -f `pwd`/php.log" to view make output.
    make -j4 &> php.log
    make install
    cp php.init-dist ${ROOT}/php/lib/php.ini
fi

# eaccelerator
if [ ! -d "${eaccelerator}" ]; then
    tar jxf ${eaccelerator}.tar.bz2
    cd $eaccelerator
    export PHP_PREFIX=${ROOT}/php
    $PHP_PREFIX/bin/phpize
    ./configure --enable-eaccelerator=shared \
        --with-php-config=$PHP_PREFIX/bin/php-config
    make -j4 &> eaccelerator.log
    make install
    echo Please edit php.ini to enable eaccelerator.so
fi


# httpd
cd $SRCROOT
if [ ! -d "${httpd}" ]; then
    tar jxf ${httpd}.tar.bz2
    cd ${httpd}
    ./configure --prefix=${ROOT}/httpd --enable-rewrite
    echo Making... Please wait. "tail -f `pwd`/httpd.log" to view make output.
    make -j4 &> httpd.log
    make install

    conf_path="${ROOT}/httpd/conf/httpd.conf"

    # 下面这段sed脚本是把端口、DocRoot替换了,并允许目录下使用.htaccess来配置url rewrite
    sed -i $conf_path \
        -e "s/^Listen 80$/Listen ${HTTPD_PORT}/" \
        -e "s/\/.*\/htdocs\>/${WWWROOT_E}/" \
        -e "s/AllowOverride None/AllowOverride FileInfo/"

    fcgi_path="${ROOT}/fcgi-bin/"

    # 在配置中加入FastCgi相关的内容
    echo "
LoadModule fastcgi_module modules/mod_fastcgi.so

FastCgiServer \"${fcgi_path}php.cgi\"
AddHandler php-fastcgi .php

ScriptAlias /fcgi-bin/ \"${fcgi_path}\"
Action php-fastcgi "/fcgi-bin/php.cgi"
AddType application/x-httpd-php .php

<Directory \"${fcgi_path}\">
    SetHandler fastcgi-script
    Options FollowSymlinks +ExecCGI
    Order Allow,Deny
    Allow from All
</Directory>
"  >> $conf_path

fi

# mod_fastcgi for httpd
cd $SRCROOT
if [ ! -d "${fastcgi}" ]; then
    tar zxf ${fastcgi}.tar.gz
    cd ${fastcgi}
    cp Makefile.AP2 Makefile
    make top_dir=${ROOT}/httpd -j4 &> fastcgi.log
    make top_dir=${ROOT}/httpd install
fi

echo Done. Please run "${ROOT}/httpd/bin/apachectl start"




欢迎扫码关注:




转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   *非必须
网址   电邮   [注册]