一 本文目的 本文旨在詳述如何編譯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 st