本文中提到的源码为截止到2009年11月20日的最新稳定版 (最后修改时间: 2009-11-20)
安装 mysql
groupadd mysql
useradd mysql -g mysql -M -s /bin/false
tar zxvf mysql-5.1.40.tar.gz
cd mysql-5.1.40
./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql --without-debug --with-big-tables \
--with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread \
--enable-static --enable-assembler --enable-local-infile --with-readline --with-ssl \
--enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
make
make install
以下为附加步骤,如果你想在这台服务器上运行MySQL数据库,则执行以下两步。
如果你只是希望让PHP支持MySQL扩展库,能够连接其他服务器上的MySQL数据库,那么,以下两步无需执行。
1、以mysql用户帐号的身份建立数据表:
chown -R mysql.mysql /usr/local/mysql
cp support-files/my-large.cnf /etc/my.cnf
scripts/mysql_install_db --user=mysql
2、加入开机自启动;并启动mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 700 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
service mysqld start
安装GD库(可选)
安装 zlib
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/usr/local/zlib
make
make install
cd ..
安装 freetype
tar zxvf freetype-2.3.8.tar.gz
cd freetype-2.3.8
./configure --prefix=/usr/local/freetype
make
make install
cd ..
安装 libpng
tar zxvf libpng-1.2.35.tar.gz
cd libpng-1.2.35
cp scripts/makefile.linux makefile
make test
make install
cd ..
安装 jpeg
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
mkdir /usr/local/jpeg
mkdir /usr/local/jpeg/bin
mkdir /usr/local/jpeg/lib
mkdir /usr/local/jpeg/include
mkdir /usr/local/jpeg/man
mkdir /usr/local/jpeg/man/man1
./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
make
make install
cd ..
在RHEL5 64 位下编译jpeg-6b时候报以下错误:
make: ./libtool: Command not found make: *** [jcapimin.lo] Error 127
错误分析:由于libtool版本过低导致的,进入jpeg-6b的源码目录,复制相关文件覆盖,然后重新configure。
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
安装 gd
依赖gettext,同时需要将-fPIC选项加入到Makefile的CFLAG中,大约230行。
tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype \
--with-png --with-zlib=/usr/local/zlib
make
make install
cd ..
编译最新的2.0.35版本,make的时候出现以下错误:
configure.ac:64: error: possibly undefined macro: AM_ICONV
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
make: *** [configure] Error 1
解决办法: configure的时候加上--enable-m4_pattern_allow参数;便能顺利编译安装
安装 libiconv(可选) tar zxvf libiconv-1.12.tar.gz
cd libiconv-1.12
./configure
make
make install
cd ..
安装 libmcrypt(可选) tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --disable-posix-threads
make
make check
make install
cd libltdl
ldconfig
./configure --enable-ltdl-install
make
make install
cd ..
安装 mhash(可选) tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
cd ..
安装 mcrypt(可选) tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/lib ./configure --with-libiconv-prefix
make
make install
cd ..
configure时候出现如下错误:
configure: error: "You need at least libmhash 0.8.15 to compile this programhttp://mhash.sf.net/"
前面已经安装过mhash,初步分析为预编译的时候没找到lib文件所在的地址;
所以在./configure前面加上LD_LIBRARY_PATH=/usr/local/lib
安装 libevent tar -xzvf libevent-1.4.9-stable.tar.gz
cd /usr/local/libevent-1.4.9-stable/
./configure --prefix=/usr/local/libevent
make
make install
cd ..
安装 PHP(fastcgi模式) tar zxvf php-5.2.11.tar.gz
<ul>生成 php-fpm补丁
tar zxvf php-fpm-0.6~5.2.11.tar.gz
php-fpm-0.6-5.2.11/generate-fpm-patch
安装Sohusin应用补丁
gzip -d suhosin-patch-5.2.11-0.9.7.patch.gz
cd php-5.2.11
patch -p 1 -i ../suhosin-patch-5.2.11-0.9.7.patch
cd ..
安装 php-fpm补丁
cd php-5.2.11
patch -p1 < ../fpm.patch
cd ..
</ul>
cd php-5.2.11
./buildconf --force
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-freetype-dir=/usr/local/freetype \
--with-jpeg-dir=/usr/local/jpeg --with-png-dir --with-zlib=/usr/local/zlib --with-gd=/usr/local/gd \
--with-gdbm=/usr/lib --with-libevent=/usr/local/libevent --enable-safe-mode --enable-sockets \
--with-iconv-dir --enable-mbstring --enable-mbregex --with-curl --with-curlwrappers --enable-bcmath \
--with-mhash --with-mcrypt --enable-fastcgi --with-fpm --with-pear --enable-force-cgi-redirect \
--enable-discard-path --enable-shmop --enable-xml --enable-sysvsem --enable-inline-optimization \
--enable-pcntl --enable-discard-path --with-libxml-dir --enable-suhosin --enable-zip
make
make install
cp php.ini-dist /usr/local/php/etc/php.ini
cd ..
</ul>
# PHP-FPM 0.6 for PHP 5.2.11的编译开关从enable改为了with, 要做相应修改,同时要增加--with-libevent开关
# 加上--enable-suhosin 韩国的PHP 守护神补丁
安装PHP5扩展模块(可选)
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..
tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
