0
回答
WEB服务器Apache编译指南及高级技巧
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

一 本文目的
  本文旨在详述如何编译Apache,OpenSSL,ModSSL,MM,Mod_Perl,PHP,Zend,MySQL和Oracle支持及其可能遇到的问题,和一些常用的加速编译和提高工作效率的技巧。
  
  二 工作环境
  Redhat Linux OS 6.x/7.x
  
  三 编译过程
  1. 所需的软件
  
  MM 1.1.3 http://www.engelschall.com/sw/mm/
  OpenSSL 0.9.6d www.openssl.org
  ModSSL 2.8.10_1.3.26 www.modssl.org
  Apache 1.3.26 www.apache.org
  MySQL 3.23.51 www.mysql.com
  PHP 4.2.1/3.0.18 www.php.net
  Zend Optimizer 1.3.1 https://www.zend.com/store/freeware.php
  Mod_Perl 1.27 http://perl.apache.org/dist/
  Oracle 8.1.7 www.oracle.com
  
  2. 开始编译
  
  a. 首先编译MM (可选)
  
  cd ../mm-1.1.3
  ./configure --prefix=/usr/local/mm (单独的目录便于区别)
  make
  make test
  make install
  
  b. 编译OpenSSL (http: 可选 https:必需)
  
  cd ../openssl-0.9.6d
  ./config no-threads -fPIC
  make
  make test
  make install
  
  注:no-threads 没有多线程支持,因为Apache 1.3.x不用多线程。
  
  c. 编译Mod_SSL (http: 可选 https:必需)
  
  cd mod_ssl-2.8.10-1.3.26
  ./configure --with-apache=../apache_1.3.26
  
  d. 编译Apache
  
  d1 最大子进程限制修补 (可选)
  
  cd ../apache_1.3.26
  vi src/include/httpd.h
  change value 256 to 1024 or above
  
  d2 为后来的PHP带Oracle支持作准备 (可选)
  
  如果你要编译PHP带Oracle支持,你要修改Apache编译文件configure加下面的行 LIBS=-lpthread在
  for var in CFLAGS LDFLAGS LIBS INCLUDES DEPS; do
  前面,如下所示
  
  LIBS=-lpthread
  for var in CFLAGS LDFLAGS LIBS INCLUDES DEPS; do
  
  注:忘记了加LIBS=-lpthread,你可以
  # cd /usr/src/apache_1.3.26
  # make clean
  # LIBS=-lpthread ./config.status
  # make
  # make install
  
  d3 编译Apache
  
  EAPI_MM=../mm-1.1.3 SSL_BASE=../openssl-0.9.6d ./configure
  --prefix=/usr/local/apache_ssl --enable-module=most --enable-shared=max --enable-module=rewrite --enable-shared=rewrite --enable-module=proxy --enable-shared=proxy --enable-module=ssl --enable-shared=ssl
  make
  make certificate (TYPE=test by default)
  make install
  strip /usr/local/apache_ssl/bin/*
  
  注:
  d3.1 如果你只是为了测试SSL,可用上面的命令,因为默认是为了测试。
  d3.2 如果你升级正在运行的SSL站点,可用make certificate TYPE=dummy,最后拷贝已经在用的ssl.crt/server.crt 和
  ssl.key/server.key。
  d3.3 在make install之前,可用命令ldd src/httpd 看有没有输出libpthread以确认前面有没有enable LIBS=-lpthread。
  d3.4 strip 所有的apache可执行文件包括httpd以节省内存空间。
  
  e 编译MySQL
  
  shell> groupadd mysql
  shell> useradd -g mysql mysql
  shell> cd /usr/local
  shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
  shell> ln -s full-path-to-mysql-VERSION-OS mysql
  shell> cd mysql
  shell> scripts/mysql_install_db
  shell> chown -R root .
  shell> chown -R mysql data
  shell> chgrp -R mysql .
  shell> bin/safe_mysqld --user=mysql &
  
  shutdown MySQL: cd /usr/local/mysql;bin/mysqladmin shutdown
  
  f 编译PHP
  
  ./configure --with-apxs=/usr/local/apache_ssl/bin/apxs --with-mysql=/usr/local/mysql --with-zlib --disable-debug --enable-track-vars --with-xml --with-gdbm --enable-sysvsem --enable-sysvshm --with-openssl=/usr/local/ssl --with-mm=/usr/local/mm --enable-ftp
  
  如果需要Oracle支持,再加上--with-oracle=/home/oracle/oracle8 --with-oci8=/home/oracle/oracle8 --enable-sigchild (假定Oracle home 目录是/home/oracle/oracle8)
  
  make
  make install
  cp php.ini-dist /usr/local/apache_ssl/conf/php.ini
  加下面的部分到/usr/local/apache_ssl/conf/httpd.conf
  
  AddType application/x-httpd-php .php
  AddType application/x-httpd-php-source .phps
  
  加下面的部分到 /usr/local/apache_ssl/bin/apachectl
  
  PHPRC=/usr/local/apache_ssl/conf
  export PHPRC
  LD_LIBRARY_PATH=$ORACLE_HOME/lib
  export LD_LIBRARY
  
  上面的LD_LIBRARY部分如果不加,当你编译PHP带Oracle支持,启动Apache时你可能会得到错误信息如下 libclntsh.so.8.0:not found
  
  如果仍然有oracle问题,可能你需要全部的Oracle环境变量放入apachectl中,如下例:
  
  . /etc/profile
  TWO_TASK=asdbs; export TWO_TASK
  ORACLE_HOME=/home/oracle/oracle8; export ORACLE_HOME
  ORACLE_BASE=/home/oracle; export ORACLE_BASE
  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:/usr/local/lib:/usr/lib; export LD_LIBRARY_PATH
  ulimit unlimited
  ulimit -n 32768
  umask 002
  PATH=$ORACLE_HOME/bin:/usr/local/bin:/usr/bin;export PATH
  
  g 安装Zend Optimizer
  
  #cd /usr/local/apache_ssl/libexec
  #cp /path/to/ZendOptimizer-1.1.0-PHP_4.0.5-Linux_glibc21-i386/ZendOptimizer.so .
  
  然后加下面的部分到/usr/local/apache_ssl/conf/php.ini
  
  zend_optimizer.optimization_level=15
  zend_extension="/usr/local/apache/libexec/ZendOptimizer.so"
  
  h 编译Mod_Perl
  
  # cd mod_perl-1.27
  # perl Makefile.PL USE_APXS=1 WITH_APXS=/usr/local/apache_ssl/bin/apxs EVERYTHING=1
  # make
  # make test
  # make install
  # mkdir /usr/local/apache_ssl/perl
  
  Add the following single line to /usr/local/apache_ssl/conf/httpd.conf
  Include conf/mod_perl.conf
  the content of mod_perl.conf is as follows:
  -------------------------------
  # Typical for plain cgi scripts:
  ScriptAlias /cgi-bin/ /usr/local/apache_ssl/perl/
  # Typical for Apache::Registry scripts:
  Alias /perl/ /usr/local/apache_ssl/perl/
  # Typical for Apache::PerlRun scripts:
  Alias /cgi-perl/ /usr/local/apache_ssl/perl/
  
  PerlModule Apache::Registry
  <Location /perl>
  SetHandler perl-script
  PerlHandler Apache::Registry
  Options +ExecCGI
  PerlSendHeader On
  allow from all
  </Location>
  -------------------------------
  注:常见的perl script 问题。
  
  How to write Perl script?
  
  a. standard perl script
  #!/usr/bin/perl
  print "Content-Type: text/html\n\n";
  
  b. CGI perl script
  use strict;
  use CGI qw(:all);
  print header;
  
  b. print "Location: URL"; and print header; problem?
  当你要用print "Location: URL" 功能时,你不能有任何print header;语句在print "Location: URL"之前。
  
  use strict;
  use CGI qw(:all);
  
  print "Location: http://www.linuxforum.net";
  
  print header;
  print "This is a testing html page\n\n";
  
  否则象下面这样print "Location: http://www.linuxforum.net";不将工作。
  use strict;
  use CGI qw(:all);
  print header;
  print "Location: http://www.linuxforum.net";
  
  
  i 修改Apache配置文件中的模块位置
  
  当你编译SSL后再编译PHP和Mod_Perl时,PHP和Mod_Perl模块包含在Ifdefine SSL中,也就是只有启动SSL时才会载入PHP和Mod_Perl,让我们修改它如下:
  
  LoadModule php4_module libexec/libphp4.so
  LoadModule perl_module libexec/libperl.so
  <IfDefine SSL>
  LoadModule ssl_module libexec/libssl.so
  </IfDefine>
  
  AddModule mod_php4.c
  AddModule mod_perl.c
  <IfDefine SSL>
  AddModule mod_ssl.c
  </IfDefine>
  
  j 配置及启动Apache
  
  #/usr/local/apache_ssl/bin/apachectl start
  #/usr/local/apache_ssl/bin/apachectl stop

举报
范堡
发帖于9年前 0回/610阅
顶部