在 64 位 FreeBSD 上部署基于 Nginx 的 PHP 运行环境
首先我想说,在 FreeBSD 7.2 上真的很折腾,尤其还是 64 位的系统。其次感谢贾同学的鼎力帮助,我们两个在这个环境上至少连续耗费 30 个小时以上。最后请原谅我不写注释以及 MySQL 主从的跳票(敬请期待),请理解我没有贴报错信息——虽然有太多太多,希望本文对有一定基础、且热爱折腾的同学有所帮助。
本文参考资料:张宴《Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过 Apache 十倍的 Web 服务器(第 6 版)》与袁旭东《FreeBSD 上搭建 nginx 0.7.x + PHP 5.2.x (FastCGI) + MySQL 5.1.x》。之所以要单独发文,是因为我在折腾过程中遇到了太多上述二位所没有遇到或者没有在文中叙述的问题。
由于没有搞定 sed 的原因,很遗憾暂时无法发布自动化脚本。先给个半自动的吧。
mkdir /home/work/src/
chown -R work:work /home/work/
cd /home/work/src/
fetch http://ftp.gnu.org/gnu/wget/wget-1.12.tar.gz
tar xzf wget-1.12.tar.gz
cd wget-1.12
./configure
make
make install
cd ..
rehash
wget -c "http://prdownloads.sourceforge.net/pcre/pcre/8.02/pcre-8.02.tar.gz?download"
tar xzf pcre-8.02.tar.gz
cd pcre-8.02
./configure
make
make install
cd ..
wget -c http://nginx.org/download/nginx-0.7.66.tar.gz
tar xzf nginx-0.7.66.tar.gz
cd nginx-0.7.66
vi auto/cc/gcc
将
# debug
CFLAGS="$CFLAGS -g"
修改为
# debug
# CFLAGS="$CFLAGS -g"
顺便期待 sed 脚本(下文半自动处同)。
./configure --user=work --group=work --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
cd ..
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.47.tar.gz/from/http://ftp.jaist.ac.jp/pub/mysql/
tar xzf mysql-5.1.47.tar.gz
cd mysql-5.1.47
./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase --with-mysqld-user=work --without-ndb-debug --without-debug --with-charset=utf8 --localstatedir=/database --with-collation=utf8_general_ci
若有独立数据库服务器,只需客户端的话,加“--without-server”参数即可。
make
make install
/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/database --user=work
chown -R work:work /database
cp support-files/my-large.cnf /etc/my.cnf
cp support-files/mysql.server /etc/rc.mysqld
chmod +x /etc/rc.mysqld
cd ..
pkg_add -r -f libiconv
wget -c "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
tar xzf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr
make
make install
/sbin/ldconfig
cd libltdl
./configure --enable-ltdl-install
make
make install
cd ../../
wget -c "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"
tar xzf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure --prefix=/usr
make
make install
cd ..
wget -c "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"
tar xzf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
vi src/rfc2440.c
将
include <malloc.h>
修改为
include <stdlib.h>
./configure --prefix=/usr
make
make install
cd ..
wget -c http://xmlsoft.org/sources/libxml2-2.7.7.tar.gz
tar xzf libxml2-2.7.7.tar.gz
cd libxml2-2.7.7
./configure
make
make install
cd ..
wget -c http://curl.haxx.se/download/curl-7.20.0.tar.gz
tar xzf curl-7.20.1.tar.gz
cd curl-7.20.1
./configure
make
make install
cd ..
wget -c "http://prdownloads.sourceforge.net/libpng/libpng-1.4.2.tar.gz?download"
tar xzf libpng-1.4.2.tar.gz
cd libpng-1.4.2
./configure
make
make install
cd ..
wget -c http://www.ijg.org/files/jpegsrc.v8a.tar.gz
tar xzf jpegsrc.v8a.tar.gz
cd jpeg-8a
./configure
make
make install
cd ..
wget -c http://ftp.gnu.org/pub/gnu/make/make-3.79.tar.gz
tar xzf make-3.79.tar.gz
cd make-3.79
./configure
make
make install
cd ..
wget -c http://ftp.twaren.net/Unix/NonGNU/freetype/freetype-2.1.10.tar.gz
tar xzf freetype-2.1.9.tar.gz
cd freetype-2.1.9
/usr/local/bin/make CFLAGS="-O3 -fPIC"
/usr/local/bin/make
/usr/local/bin/make install
cd ..
wget -c http://ftp.gnu.org/gnu/libtool/libtool-2.2.tar.gz
tar xzf libtool-2.2.tar.gz
cd libtool-2.2
./configure
make
make install
cd ..
wget -c http://www.php.net/get/php-5.2.13.tar.gz/from/this/mirror
wget -c http://php-fpm.org/downloads/php-5.2.13-fpm-0.5.13.diff.gz
tar xzf php-5.2.13.tar.gz
gzip -cd php-5.2.13-fpm-0.5.13.diff.gz | patch -d php-5.2.13 -p1
cd php-5.2.13
./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
make
make install
cp php.ini-dist /etc/php.ini
cd ..
pkg_add -r -f autoconf262
wget -c http://pecl.php.net/get/memcache-2.2.5.tgz
tar xzf 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 ..
wget -c http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2
tar xzf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make with-eaccelerator-shared-memory=yes
make install
cd ..
wget -c http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
tar xzf 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
make install
由于死活没有成功安装 ImageMagick(低版本装了 PHP 不认,高版本报 png.c 错误),因此使用 GD 代替。安装后的配置方法与调整细节,可参见上文所述两篇参考文献。期待同行交流。
谨以此文,献给 12 年的今天离开我们的所有人。