引用至http://blog.yening.cn/2006/07/02/54.html

配置最新最IN的 Web Server!! 编译 Apache 2.2 + PHP 5.1.2 + MYSQL 5.0.19 的详细步骤.

  • 准备,下载所需要的库文件
  • 安装 Ubuntu Server
  • 安装编译器和必须的运行库
  • 编译安装 Apache 2.2、PHP 5.12、MySQL 5.01
  • 测试,配置Apache和MySQL自启动.
  1. 准备,下载所需要的文件
    *
    Name Size Last Version
    Ubuntu-Server 6.04 (Dapper Drake) i386 634M Discover
     
    bison-2.1.tar.gz 1285K Discover
    flex-2.5.4a.tar.gz 372K Discover
    bzip2-1.0.3.tar.gz 653K Discover
    zlib-1.2.3.tar.gz 484K Discover
    openssl-0.9.8.tar.gz 3183K Discover
    libiconv-1.10.tar.gz 3861K Discover
    freetype-2.1.10.tar.gz 1350K Discover
    jpegsrc.v6b.tar.gz 598K Discover
    libpng-1.2.9beta9.tar.gz 800K Discover
    gd-2.0.33.tar.gz 573K Discover
    libxml2-2.6.23.tar.gz 4407K Discover
    curl-7.15.2.tar.gz 1762K Discover
     
    httpd-2.2.0.tar.bz2 4725K Discover
    mysql-max-5.0.19-linux-i686.tar.gz 37650K Discover
    php-5.1.2.tar.bz2 6171K Discover
    ZendOptimizer-3.0.0Beta3-linux-glibc21-i386.tar.gz 6469K Discover
  2. 安装 Ubuntu Server

    linux Apache 2.2 + PHP 5.1.2 + MYSQL 5.0.19+svn

    Ubuntu 的安装过程相当友好,根据向导一步步向下做就可以了,除了分区的时候要留意一点外,其它基本都是Next,Next,这里就不再累赘。因为只在本机随便玩玩,为求方便,安装完毕系统后我装了一个ssh,并且修改了root的密码.步骤如下:

    1) 安装 ssh

    shell> apt-get install ssh

    2) 修改root的密码

    shell> sudo passwd root (提示您输入密码)
  3. 安装编译器和必须的运行库
    1. 安装编译器

      新装好的ubuntu光秃秃的,连基本的c++编译器和make工具都没有,我们需要安装以下基本的编译工具.

      gcc
      make
      autoconf
      automake
      libtool

      考虑到系统的兼容性,并且上面的东东比较都大,不找最新版本了,直接用apt-get install XXX 来安装.因为我们的Ubuntu是dailyBulid的,所以光盘的内容基本上都是最新的了,无需重新下载.一定要最新版本的话,不妨先apt-get update 来更新一下软件的仓库,然后再 apt-get install.

    2. 安装必须的运行库和工具
      1. 配置c++编译器选项,针对不同的CPU进行编译优化,如无特殊要求,可以跳过这一步.[更多CPU的编译参数]
        # Intel PentiumIV,Celeon Family
        export CFLAGS=”-march=pentium4 -mfpmath=sse -msse2 -O2 -pipe -s -fomit-frame-pointer”

        # AMD Alton,Duron Family
        export CFLAGS=”-O3 -march=athlon-xp -pipe -fomit-frame-pointer -msse -mmmx -m3dnow -mfpmath=sse”

      2. 开始编译并配置SSL证书 假设下载好的所有软件都放在 /usr/src 目录下,并且所有的软件都安装在 /usr/local 目录下. 按表中的先后顺序编译lib和必须的工具 (如libpng需要bzip2,不同的包,有一定的依存关系).如无特殊说明,编译的基本命令为:
        tar -xzvf PACKAGE-VERSION.tar.gz
        cd PACKAGE-VERSION
        ./configure --prefix=/usr/local
        make
        make install

        * [Update] openssl 0.98d 默认不编译共享库 libssl.so,在 configure 必须加上 shared 参数,具体请看README文件,否则curl等只能使用系统老的 libssl 库.

        * 编译 jpegsrc.v6b.tar.gz,make install 后 ,还需要再 make install-lib 安装头文件.

        Good Luck & Congratulate! linux Apache 2.2 + PHP 5.1.2 + MYSQL 5.0.19+svn

        顺利编译上面的一大堆lib和tools后,接下来生成SSL的证书,生成的证书只能自己使用,真正的ca证书需要花钱购买的.

        * 在生成文件的时候,会有一些交互问答,其中有一点很重要 Enter pass phrase: 程序会通过您的输入的内容生成一个不可逆的hash,通过这个hash来保护的证书和数据加密传输,将其简单理解为设置密码就行了.

        # Create a private key and place it into directory/var/ssl

        mkdir /var/ssl
        cd /var/ssl
        /usr/local/bin/openssl genrsa -des3 -rand some_big_file_1:some_big_file_2 -out server.key 1024

        # Next, we will create a private key without a pass-phrase,this is less secure, but it allows us to bootup the serverwithout manually entering the pass-phrase every time

        /usr/local/bin/openssl rsa -in server.key -out server.key.unsecure

        # We will also create a request file that will be emailed toproper certification authority for getting a trusted SSLcertificate (if needed) under file localhost.key.csr:

        /usr/local/bin/openssl req -new -key server.key -out server.key.csr

        注意:当提示输入 Common Name (eg, YOUR name) []: ,请输入你需要SSL支持的域名,如localhost,blog.yening.cn,否则浏览器会提示证书错误.

        # While waiting for the certification authority, we can createa temporary self-signed certificate, good for 2 year(730 day);

        /usr/local/bin/openssl x509 -req -days 730 -in server.key.csr -signkey server.key -out server.crt
        chmod 400 server.crt
        chmod 400 server.key
        chmod 400 server.key.unsecure
    3. 编译安装 Apache 2.2、PHP 5.12、MySQL 5.01
      • 编译安装 Apache 2
        cd /usr/src
        bzip2 -d httpd-2.2.0.tar.bz2
        tar -xvf httpd-2.2.0.tar
        cd httpd-2.2.0
        ./configure --prefix=/usr/local/apache2 \
        --enable-so \
        --enable-auth-digest \
        --enable-rewrite \
        --enable-setenvif \
        --enable-mime \
        --enable-ssl \
        --with-ssl=/usr/local \
        --enable-headers

        make
        make install
        ln -s /usr/local/apache2/bin/apachectl /usr/local/bin
        ln -s /usr/local/apache2/conf/httpd.conf /etc/httpd.conf
        mv /usr/local/apache2/htdocs /var/www

        ** 配置

        修改 /usr/local/apache2/conf/httpd.conf

        # 修改文档根目录到 /var/www

        DocumentRoot “/var/www”

        # 配置 /var/www 目录的权限

        Options Indexes Includes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all

        # 默认首页添加 index.htm index.php

        DirectoryIndex index.html index.htm index.php

        # 监听443端口,支持https连接
        取消注释 httpd.conf 中的 Include conf/extra/httpd-ssl.conf
        用编辑器编辑 httpd-ssl.conf 配置服务器私钥,以下是我的配置文件内容:

        Listen 443

        AddType application/x-x509-ca-cert .crt
        AddType application/x-pkcs7-crl .crl.
        # SSLPassPhraseDialog builtin
        SSLPassPhraseDialog exec:/usr/local/apache2/conf/sendsslpwd
        SSLSessionCache shmcb:/usr/local/apache2/logs/ssl_scache(512000)
        SSLSessionCacheTimeout 300
        SSLMutex file:/usr/local/apache2/logs/ssl_mutex

        <virtualhost _default_:443="">
        DocumentRoot “/var/www”
        ServerName localhost:443</virtualhost>

        ServerAdmin [email protected]
        SSLEngine on
        SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
        SSLCertificateFile /var/ssl/server.crt
        SSLCertificateKeyFile /var/ssl/server.key

        <filesmatch>
        SSLOptions +StdEnvVars
        </filesmatch>

        <directory>
        SSLOptions +StdEnvVars
        </directory>

        BrowserMatch “.*MSIE.*” \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0

        创建SSL密码自动应答文件,否则每次Apache启动的时候,都会要求你输入SSL的密码.
        创建 /usr/local/apache2/conf/sendsslpwd ,内容如下.

        #!/bin/bash
        SSLpasswd=”YOUR PASSPHRASE “
        echo $SSLpasswd
        chmod 755 /usr/local/apache2/conf/sendsslpwd
        ** 测试
        shell> apachectl start

        打开浏览器,输入http(s)://SERVERIP/,都能看到 It works! 说明 Apache With SSL 安装成功.

        正确生成的证书在IE的安全警报下,应该会有两个绿色小勾,如图所示:
        linux Apache 2.2 + PHP 5.1.2 + MYSQL 5.0.19+svn
        生成的证书会在第二天起效(可以调整一下系统时间测试),但第三个小勾还是如果配置对的话还是会打上的.

      • 安装 MySQL 5
        cd /usr/src tar -xzvf mysql-max-5.0.19-linux-i686.tar.gz
        mv mysql-max-5.0.19-linux-i686 /usr/local/mysql
        cd /usr/local/mysql
        groupadd mysql
        useradd -g mysql mysql
        scripts/mysql_install_db --user=mysql
        chown -R root .
        chown -R mysql data
        chgrp -R mysql .
        ln -s /usr/local/mysql/bin/mysqld_safe /usr/local/bin
        ln -s /usr/local/mysql/bin/mysql /usr/local/bin

        ** 测试:
        shell> mysqld_safe --user=mysql &
        shell>mysql

        屏幕出现 mysql> 提示,说明MySQL安装成功.

      • 编译安装 PHP 5
        cd /usr/src
        bzip2 -d php-5.1.2.tar.bz2
        tar -xvf php-5.1.2.tar
        cd php-5.1.2

        ./configure --prefix=/usr/local \
        --with-config-file-path=/usr/local/apache2/conf \
        --with-apxs2=/usr/local/apache2/bin/apxs \
        --with-bz2=/usr/local \
        --with-curl=/usr/local \
        --with-curlwrappers \
        --enable-ftp \
        --enable-sockets \
        --disable-ipv6 \
        --with-gd=/usr/local \
        --with-jpeg-dir=/usr/local \
        --with-png-dir=/usr/local \
        --with-freetype-dir=/usr/local \
        --enable-gd-native-ttf \
        --with-iconv-dir=/usr/local \
        --enable-mbstring \
        --with-gettext \
        --with-openssl-dir=/usr/local \
        --with-libxml-dir=/usr/local \
        --with-mysql=/usr/local/mysql \
        --with-mysqli=/usr/local/mysql/bin/mysql_config \
        --with-mysql-sock=/tmp/mysql.sock \
        --enable-sqlite-utf8 \
        --with-zlib=/usr/local \
        --with-zlib-dir=/usr/local \
        --enable-zend-multibyte

        make
        make install
        cp php.ini-dist /usr/local/apache2/conf/php.ini
        ln -s /usr/local/apache2/conf/php.ini /etc/php.ini

        ** 配置

        #在Apache中添加php关联,这步应该是编译php的时候自动完成的,但是我编译的时候没有自动添上,可能是Apache2.2的缘故。打开/usr/local/apache2/conf/httpd.conf,加入

        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps

        # 根据具体的您要求配置php,这步可以略过 vi/usr/local/apache2/conf/php.ini

      • 安装 ZendOptimizer
        cd /usr/src tar -xzvf
        ZendOptimizer-3.0.0Beta3-linux-glibc21-i386.tar.gz
        cd ZendOptimizer-3.0.0Beta3-linux-glibc21-i386
        ./install.sh

        按照屏幕提示输入 php.ini 的路径即可,安装程序会自动关闭WebServer,安装完毕后会帮你再启动(忙了一天,这步最爽,哈哈.)

    4. 测试,配置Apache和MySQL自动启动.经过漫长的等待,激动人心的一刻终于来了。

      # 创建一个php文件

      shell> echo ‘’ > /var/www/index.php

      打开浏览器,输入 http://SERVERIP/index.php,出现以下画面:

      linux Apache 2.2 + PHP 5.1.2 + MYSQL 5.0.19+svn

      恭喜您,和我一样,拥有目前最新,最IN的 WebServer和PHP了,再研究一下PHP的configure和PCEL,您可以获得PHP更多的模块和功能.

      最后,用vi编辑 /etc/rc.local 文件,让Apache和MySQL在系统启动的时候自动启动.

      # 在exit 0前面加入

      /usr/local/apache2/bin/apachectl start
      /usr/local/mysql/bin/mysqld_safe --user=mysql &

      ■ 其它问题:
      一台Apache Web服务只能创建一个SSL站点

      当您有多个虚拟主机同时监听443端口时,Apache的error.log日志文件中会出现以下提示:

      [Tue Aug 01 15:37:05 2006] [warn] Init: SSL server IP/port conflict: ssl-1.verycd.com:443 (/usr/local/apache2/conf/extra/httpd-ssl.conf:236) vs. ssl-2.verycd.com:443 (/usr/local/apache2/conf/extra/httpd-ssl.conf:250)
      [Tue Aug 01 15:37:05 2006] [warn] Init: You should not use name-based virtual hosts in conjunction with SSL!!

      详细的描述请参考 http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html

64位编译有问题的朋友,可参考 阿标的《CENTOS4.3安装全攻略》,写得也非常详细.

大功告成!!

:: Change Log ::
  • 2006-11-07 添加编译openssl 动态库 libssl.so 所需要参数.
  • 2006-11-02 暂时发现 php-5.20 无法使用最新 curl-7.16.0 编译通过,降到 curl-7.15.5 就正常了.
  • 2006-08-07 (v1.22) 更新SSL的自动密码应答部分,其它问题。
  • 2006-07-25 (v1.21) 更新关于编译参数优化的资料,修正SSL证书生成部分的说明.
  • 2006-07-02 (v1.2)
    • 修正SSL部分的配置说明,修正编译参数被wordpress转义的bug.
    • 以上配置在 PHP-5.1.4,Apache-2.2.2,MySQL-5.0.22 (Ubuntu,6.06)依然有效.
      linux Apache 2.2 + PHP 5.1.2 + MYSQL 5.0.19+svn

    最新的版本 Subversion 可以在这里找到 :http://subversion.tigris.org/project_packages.html

    * 检查已安装的 Apache2 是否已经安装了 mod_dav .

    如果已经成功安装了Apache,使用 httpd -M 来查看有没有安装 dav_module,如果没有的话 必须附加 ‘–enable-dav’ ‘–enable-dav-fs’ 两个参数重新编译 Apache,否则即使编译通过了svn,apache也会启动不起来.

    如何编译 Apache 请参考我另外一篇文章.

    * 编译SVN,遇到的问题和解决方法.

    使用默认的文件系统保存数据.

    最终完整通过安装和测试的编译参数为:

    ./configure --with-apxs=/usr/local/apache2/bin/apxs \
    --with-apr=/home/src/server/httpd-2.2.2/srclib/apr \
    --with-apr-util=/home/src/server/httpd-2.2.2/srclib/apr-util

    make
    make install

    其中 /home/src/server/ 为 httpd-2.2.2 源代码所在文件夹,根据实际情况调整一下.

    ◆ 遇到问题:

    1) --with-apr 和 --with-apr-util 如果没有加上的话,即使编译成功了也会出现

    Can’t set position pointer in file ‘/home/svn/repos/db/revs/0′: Invalid argument

    这样的错误提示.

    2) 暂时不能使用 Berkeley DB [* 已解决]

    svn保存文件更新数据库的方法有两个,一种是直接使用 fs (filesystem)来保存,另一种是通过Oracle提供支持的开源数据库 Berkeley DB 进行保存。但是如果加上 –with-berkeley-db=/usr/local/BerkeleyDB.4.4 就会configure时就会报错.

    configure: error: APR-UTIL was installed independently, it won’t be
    possible to use the specified Berkeley DB: /usr/local/BerkeleyDB.4.4

    我想 apr-unit 暂时不支持吧,我们就用默认的fs好了.

    3) 在make 的时候可能会遇到缺少 srclib/apr/libapr-1.la,srclib/apr-util/libaprutil-1.la 两个文件,找不到而make error.

    解决办法:/usr/local/apache2/lib/ 中找到,将其复制到源代码文件夹相应的位置中.

    Update!!

    使用 BerkeleyDB 保存数据.

    1) 安装 BerkeleyDB

    cd /usr/local/src
    wget http://downloads.sleepycat.com/db-4.3.29.tar.gz

    tar xzvf db-4.3.29.tar.gz
    cd /usr/local/src/db-4.3.29/build_unix
    ../dist/configure --enable-compat185
    make
    make install

    2) 更新apr和apr-util源代码

    # 清理编译后的.la文件
    cd /usr/local/src/httpd-2.2.3

    make clean

    cd /usr/local/src/subversion-1.3.2
    rm -rf apr
    rm -rf apr-util
    cp -rf /usr/local/src/httpd-2.2.3/srclib/apr ./
    cp -rf /usr/local/src/httpd-2.2.3/srclib/apr-util/ ./

    3) 编译安装

    ./configure --with-apxs=/usr/local/apache2/bin/apxs \
    --with-berkeley-db=/usr/local/BerkeleyDB.4.3 \
    --with-ssl
    make
    make install

    ◆ 遇到问题:
    1) BerkeleyDB 版本不能大于 4.3.否则同样会出现以下错误.

    configure: error: APR-UTIL was installed independently, it won’t be
    possible to use the specified Berkeley DB: /usr/local/BerkeleyDB.4.4

    主要是apr-util 暂时不支持4.4的版本.

    2) 必须更新apr,apr-util 源代码.
    subversion-1.3.2 自带的 apr-util 的版本是0.9.6的,必须升级为 1.2.7 虽然能编译过去。但在 svn checkout 的时候会提示

    svn: REPORT request failed on ‘/!svn/vcc/default’
    svn: REPORT of ‘/!svn/vcc/default’: Could not read status line: connection was closed by server.

    这个问题困扰了我很长时间,Google和官方论坛都无结果。后来昨天竟然自己无意中解决了,感动的得哭了:)

    * 配置Apache和SVN,测试

    成功编译svn后会在 httpd.conf 中自动加上

    LoadModule dav_svn_module modules/mod_dav_svn.so
    LoadModule authz_svn_module modules/mod_authz_svn.so

    两个模块,没有的话,自行加上或检测是否真的编译成功.

    假设我们现在要将一个名为 Lair 的项目导入到 SVN中

    1). Apache的配置

    在 conf/httpd.conf 或 conf/extra/httpd-vhosts.conf 中加入

    <location> </location>

    DAV svn
    SVNPath /home/svn/Lair

    可以参考以下apache的配置,实现数据加密传输,用户身份验证.

    Listen 443

    AddType application/x-x509-ca-cert .crt
    AddType application/x-pkcs7-crl .crl.

    SSLPassPhraseDialog exec:/etc/sendsslpwd
    SSLSessionCache shmcb:/usr/local/apache2/logs/ssl_scache(512000)
    SSLSessionCacheTimeout 300
    SSLMutex file:/usr/local/apache2/logs/ssl_mutex

    <virtualhost _default_:443="">
    DocumentRoot /var/SVNRoot
    ServerName svn.yousite.com:443
    ServerAdmin [email protected]
    <location></location></virtualhost>

    DAV svn
    SVNPath /var/SVNRoot
    AuthzSVNAccessFile /etc/svnserve.conf
    Satisfy Any
    AuthType Basic
    AuthName “yousite SVN Repository”
    AuthUserFile /etc/httpd-passwords.txt
    Require valid-user


    SSLEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SSLCertificateFile /etc/ssl/server.crt
    SSLCertificateKeyFile /etc/ssl/server.key

    更详细的配置说明文档 http://svnbook.red-bean.com/nightly/en/svn.ref.mod_dav_svn.conf.html

    2). 配置,并且测试SVN,

    创建一个新用户,用了保存仓库.

    useradd -m svn

    创建一个新模块

    su daemon (apache是以daemon用户运行的,所以要切换身份,否则可能会报目录访问权限错误)
    svnadmin create --fs-type fsfs /home/svn/Lair

    导入原来的项目

    svn import /var/www/Lair http://localhost/svn/Lair -m ‘Initial import’

    重新建立工作目录

    rm -rf /var/www/Lair (注意备份!!)
    svn checkout http://localhost/svn/Lair

    测试打开 http://localhost/svn/Lair
    linux Apache 2.2 + PHP 5.1.2 + MYSQL 5.0.19+svn
    如能看到一个你项目录列表,说明您成功了。

    * 其它小结

    ■ 数据转移:

    从 Windows 平台 SVN 服务器转移
    如果windows svn储存的格式也是dbd的话,直接将SVN的文件夹copy过来即可.然后
    执行 svnadmin recover /var/SVNRoot 检查一下数据库是否损坏.

    最后注意权限,确保 db 目录下的所有文件可写。

    chmod 755 db
    chmod 666 db/*

    否则checkout时出现以下错误,多数是因为 文件或者目录权限问题 引起的,可以尝试用 chown 或者 chmod 命令修改一下权限

    <m:human-readable errcode="”160029″"> </m:human-readable>

    Could not open the requested SVN filesystem

    <m:human-readable errcode="”13″">
    Could not open the requested SVN filesystem
    </m:human-readable>

    另外一种方法没有测试过,原理大致和mysqldump一样,将svn导出为文本文件,然后重新导入,好处是可以避免因为存储格式不同而导致的数据转移困难。

    # dump data to file (assuming a repo @ c:\repo):

    svnadmin dump c:\repo > c:\repo.txt
    # Copy the file over to linux:
    mkdir /repo
    svnadmin create /repo
    svnadmin load /repo < /repo.txt

    ■ 设置访问控制

    当 httpd.conf 中 设置 AuthzSVNAccessFile 时,可以设置不同用户对不同目录的访问控制.以下是一个例子.

    [groups]
    root = admin.root
    web = user1,user2
    soft = user3,user4

    [/]
    @root = rw

    [/www]

    @web = rw

    [/soft]
    @soft = rw

    详细的说明文档:http://svnbook.red-bean.com/nightly/en/svn.serverconfig.httpd.html

    ■ 配置文件,使用其支持对文件中的 $Id$ 标签每次提交的时候自动更新版本信息(自动属性).

    Windows : C:\Documents and Settings\%USERNAME%\Application Data\Subversion\config
    Linux : ~\.subversion\config

    [miscellany]

    enable-auto-props = yes
    [auto-props]
    *.php=svn:keywords=Id
    *.html=svn:keywords=Id

    >> 关于自动属性的更高级讨论

    ■ 几条常用svn 命令
    svn update
    svn add “filename”
    svn commit

    ———————–
    Change Log:

  • 2006-08-14 neon库subversion已经自带,不需要在单独安装,添加-with-ssl即可使用svn对ssl支持.
  • 2006-08-10 补充自动属性的说明.
  • 2006-08-08 加入关于目录访问验证的说明.
  • 2006-08-07 httpd,2.2.3测试依然有效,解决bdb数据库的支持问题,添加从Windows到Linux下的数据转移方案。
  • 2006-07-25 看到到.声仔对 Can’t set position pointer in file 另一种解决方案,我当时也测试了,好像没有成功。不想用apache源代码编译的朋友可以也测试一下
  • 2006-07-09 初稿.

相关文章:

  • 2021-11-05
  • 2021-06-18
  • 2021-12-08
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-29
  • 2021-12-10
  • 2021-08-21
  • 2021-08-20
  • 2021-09-30
  • 2021-09-01
  • 2022-12-23
相关资源
相似解决方案