CentOS5.2编译安装Apache 2.2.10,MySQL 5.0.67,PHP-5.2.6(支持GD),ZendOptimizer3.3.0


1.安装Apache 2.2.10
虽然选择了无包安装CentOS,但是由于包依赖关系,CentOS还是会自动安装Apache,所以需要首先卸载掉Apache,依次点击Applications->Add/Remove Software->把万维网服务器前面的勾去掉即可。
开始编译安装Apache
解压 tar zxvf httpd-2.2.10.tar.gz
进入目录,开始编译
./configure –sysconfdir=/etc –enable-ssl –enable-modules –enable rewrite
一般apache还需要支持url改写,所以编译时加上后面的部分;
正常情况下,如果选择了无包安装CentOS,会出现下面的错误:
checking whether to enable mod_ssl… checking dependencies
checking for SSL/TLS toolkit base… none
checking for OpenSSL version… checking openssl/opensslv.h usability… no
checking openssl/opensslv.h presence… no
checking for openssl/opensslv.h… no
checking openssl/ssl.h usability… no
checking openssl/ssl.h presence… no
checking for openssl/ssl.h… no
no OpenSSL headers found
checking for SSL-C version… checking sslc.h usability… no
checking sslc.h presence… no
checking for sslc.h… no
no SSL-C headers found
configure: error: …No recognized SSL/TLS toolkit detected
解决办法,安装 openssl
yum -y install openssl-devel
下载安装和更新的列表信息
Running Transaction
Updating : e2fsprogs-libs               ####################### [ 1/15]
Updating : krb5-libs                    ####################### [ 2/15]
Installing: e2fsprogs-devel              ####################### [ 3/15]
Installing: libsepol-devel               ####################### [ 4/15]
Installing: libselinux-devel             ####################### [ 5/15]
Installing: keyutils-libs-devel          ####################### [ 6/15]
Installing: krb5-devel                   ####################### [ 7/15]
Installing: zlib-devel                   ####################### [ 8/15]
Installing: openssl-devel                ####################### [ 9/15]
Updating : krb5-workstation             ####################### [10/15]
Updating : e2fsprogs                    ####################### [11/15]
Cleanup   : e2fsprogs-libs               ####################### [12/15]
Cleanup   : krb5-workstation             ####################### [13/15]
Cleanup   : e2fsprogs                    ####################### [14/15]
Cleanup   : krb5-libs                    ####################### [15/15]
Installed: openssl-devel.i386 0:0.9.8b-8.3.el5_0.2
Dependency Installed: e2fsprogs-devel.i386 0:1.39-10.el5_1.1 keyutils-libs-devel.i386 0:1.2-1.el5 krb5-devel.i386 0:1.6.1-17.el5_1.1 libselinux-devel.i386 0:1.33.4-4.el5 libsepol-devel.i386 0:1.15.2-1.el5 zlib-devel.i386 0:1.2.3-3
Dependency Updated: e2fsprogs.i386 0:1.39-10.el5_1.1 e2fsprogs-libs.i386 0:1.39-10.el5_1.1 krb5-libs.i386 0:1.6.1-17.el5_1.1 krb5-workstation.i386 0:1.6.1-17.el5_1.1
Complete!
OK, openssl安装完毕。
然后再次输入./configure –sysconfdir=/etc –enable-ssl –enable-modules –enable rewrite
这样就生成了makefile
然后make和make install即可完成Apache安装。
终端输入:/usr/local/apache2/bin/apachectl start启动apache,
终端输入:netstat -tnl看看端口,如果有80了,说明apache启动成功了。
最后需要设置Apache随CentOS启动,终端输入:echo “/usr/local/apache2/bin/apachectl start &” >> /etc/rc.local
安装MySQL
下载MySQL
解压缩 tar xvf mysql-5.0.67.tgz
进入目录开始编译./configure –sysconfdir=/etc
一般情况会出现一个错误提示如下:
checking for termcap functions library… configure: error: No curses/termcap library found
解决办法如下:
yum -y install ncurses-devel
安装完毕后再次输入:./configure –sysconfdir=/etc
出现安装成功信息:Thank you for choosing MySQL!
后面的工作就是make和make install了。
安装完后,拷贝一个配置文件当作MySQL的配置文件
cp /usr/local/share/mysql/my-large.cnf /etc/my.cnf
开始启动MySQL
终端输入:useradd -d /usr/local/var mysql
一般会提示mysql用户存在
su - mysql
/usr/local/bin/mysql_install_db
启动开始
[mysql@localhost var]$ /usr/local/bin/mysqld_safe
这里可能会碰到点小问题,一般是文件权限问题和文件夹需要重新建立问题,具体细节我记不请了。
netstat -tnl ,如果看到3306端口,就说明MySQL启动成功。
然后配置MySQL随CentOS启动,终端输入:echo “/usr/local/bin/mysqld_safe &” >> /etc/rc.local
编译安装GD库,让php支持更多图形方面的内容,例如gif jpg(jpeg) png wbmp xml 和 ttf字体(此部分要在PHP安装前进行,且按照以下顺序进行安装)
1.安装ncurses-5.6
解压缩 tar zxvf ncurses-5.6.tar.gz,进入目录
./configure –prefix=/usr –with-shared –without-debug
make
make install
2.安装zlib2
解压缩 tar zxvf tar zxvf zlib-1.2.3.tar.gz,进入目录
./configure –prefix=/usr/local/zlib
make
make install
3.安装PNG
解压缩 tar zxvf tar zxvf libpng-1.2.26.tar.gz,进入目录
cp scripts/makefile.linux ./makefile
./configure –prefix=/usr/local/libpng
make
make install
4.安装ttf ( ttf 是字体的支持 )
tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure –prefix=/usr/local/freetype
make
make install
5.安装JPEG6
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
mkdir -pv /usr/local/libjpeg/{,bin,lib,include,man/man1,man1}
./configure –prefix=/usr/local/libjpeg –enable-shared –enable-static
make
make install
6.安装 libxml2
tar zxvf libxml2-2.6.31.tar.gz
cd libxml2-2.6.31
./configure –prefix=/usr/local/libxml2
make
make install
cp xml2-config /usr/bin
7.安装 libmcrypt-2.5.7.tar.gz
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make
make install
8.安装Fontconfig
tar -zxvf fontconfig-2.4.2.tar.gz
cd fontconfig-2.4.2
./configure –prefix=/usr/local/fontconfig –with-freetype-config=/usr/local/freetype/bin/freetype-config
一般这里会出现一个错误提示如下:
checking for LIBXML2… configure: error: Package requirements (libxml-2.0 >= 2.6) were not met:
No package ‘libxml-2.0′ found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables LIBXML2_CFLAGS
and LIBXML2_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
解决方法:确定 /usr/local/libxml2/lib/pkgconfig 目录下有 libxml-2.0.pc
export PKG_CONFIG_PATH=/usr/local/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH
然后再次输入:./configure –prefix=/usr/local/fontconfig –with-freetype-config=/usr/local/freetype/bin/freetype-config
make
make install
9.安装GD库
tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure –prefix=/usr/local/libgd –with-png=/usr/local/libpng –with-fr
如果前面安装都顺利,会看到下面的支持信息:
Support for PNG library:          yes
Support for JPEG library:         yes
Support for Freetype 2.x library: yes
Support for Fontconfig library:   yes
Support for Xpm library:          no
Support for pthreads:             yes
继续
make
make install
安装PHP5.2.6
tar zxvf php-5.2.6.tar.gz
cd php-5.2.6
./configure –prefix=/usr/local/php5 –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql=/usr/local –with-gd=/usr/local/libgd –enable-gd-native-ttf –with-ttf –enable-gd-jis-conv –with-freetype-dir=/usr/local/freetype –with-jpeg-dir=/usr/local/libjpeg –with-png-dir=/usr/local/libpng –with-libxml-dir=/usr/local/libxml2 –with-zlib-dir=/usr/local/zlib –enable-xml –enable-mbstring –enable-sockets
成功提示信息是:Thank you for using PHP.
make
make install
拷贝一个配置文件当作我们以后的php.ini
cp php.ini-dist /usr/local/php5/lib/php.ini
修改 apache 配置文件 httpd.conf 加入对php的支持
vi /etc/httpd.conf
加入:
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
然后重启 apache
/usr/local/apache2/bin/apachectl restart
站点目录是:/usr/local/apache2/htdocs
最后我们还要添加上系统PATH,这样就可以在终端直接输入php即可运行程序,
在终端输入:vi .bashrc,加入这一行:export PATH=”$PATH:/usr/local/php5/bin”,
然后注销当前用户重新登录即可,注意,这种方式只对当前用户有效,不是全局设置。
安装 ZendOptimizer3.3.0
tar xzvf ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz
cd ZendOptimizer-3.3.0a-linux-glibc21-i386
./install
其中要注意有一步要求填写之前PHP的安装目录,要这么填写/usr/local/php5/lib才正确。
经过使用发现,安装的ZendOptimizer3.3.0版本偏低,不过不要紧,重新安装ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz即可。