环境:centos5.6 nginx0.8+mysql5.0.77+php5.3.3
php支持memcache的扩展包(libmemcached1.0.14 memcached2.1)
由于mysql独立出来服务器端版本号为5.0.77为了一致,客户端php对mysql的扩展源码安装用了同样版本,也许不一致关系也不大。
memcached2.0.1版本有bug,所以用了最新版本,libmemcached是php的memcached扩展必备包.
版本下载:(统一下载至/usr/local/src/…)
wget http://museum.php.net/php5/php-5.3.3.tar.gz
wget http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.77.tar.gz
wget http://pecl.php.net/get/memcached-2.1.0.tgz
wget https://launchpad.net/libmemcached/1.0/1.0.14/+download/libmemcached-1.0.14.tar.gz
基础环境准备:yum groupinstall "Development Tools"
nginx安装:yum install nginx 略
mysql安装:
- tar zxvf mysql-5.0.77.tar.gz
- cd mysql-5.0.77
- groupadd mysql
- useradd -g mysql mysql
- ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-ssl
- make && make install
- chmod +w /usr/local/mysql
- chown -R mysql.mysql /usr/local/mysql
php安装:
1.php必备组件安装:
yum install gcc gcc-c++ autoconf libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel openssl openssl-devel gd gd-devel pcre pcre-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel flex libevent libevent-devel libmcrypt libmcrypt-devel libtool libtool-ltdl.x86_64
2. php源码安装:
tar zxvf php-5.3.3.tar.gz
cd php-5.3.3
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-mcrypt --with-openssl --with-mhash --enable-sockets --enable-pcntl --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
注:php5.3.3版本的php-fpm(对fastcgi的支持)已经包括在源码中,不需要另外作为补丁打进去,编译时启用—enable-fpm
- 编译完成结果:
- Installing PHP SAPI module: fpm
- Installing PHP CLI binary: /usr/local/php/bin/
- Installing PHP CLI man page: /usr/local/php/man/man1/
- Installing PHP FPM binary: /usr/local/php/sbin/
- Installing PHP FPM config: /usr/local/php/etc/
- Installing PHP FPM man page: /usr/local/php/man/man1/
- Installing build environment: /usr/local/php/lib/php/build/
- Installing header files: /usr/local/php/include/php/
- Installing helper programs: /usr/local/php/bin/
- program: phpize
- program: php-config
- Installing man pages: /usr/local/php/man/man1/
- page: phpize.1
- page: php-config.1
- Installing PEAR environment: /usr/local/php/lib/php/
- [PEAR] Archive_Tar - installed: 1.3.7
- [PEAR] Console_Getopt - installed: 1.2.3
- [PEAR] Structures_Graph- installed: 1.0.3
- [PEAR] XML_Util - installed: 1.2.1
- [PEAR] PEAR - installed: 1.9.1
- Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
- You may want to add: /usr/local/php/lib/php to your php.ini include_path
- /usr/local/src/php-5.3.3/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
- ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
- Installing PDO headers: /usr/local/php/include/php/ext/pdo/
3. php配置文件指定:
- [root@Soap38 php-5.3.3]#cp php.ini-production /usr/local/php/etc/php.ini
- [root@Soap38 php-5.3.3]#echo "/usr/local/php/lib/php">>/etc/php.ini
4. 配置php对php-fpm(factcgi)的支持,使nginx能调度php:
1). 添加php-fpm服务
- [root@Soap38 php-5.3.3]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
- [root@Soap38 php-5.3.3]# chmod +x /etc/init.d/php-fpm
- [root@Soap38 php-5.3.3]# chkconfig --add php-fpm
- [root@Soap38 php-5.3.3]# chmod 666 /usr/local/php/var/run/
2). 配置文件更改:php-fpm
#cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#vi /usr/local/php/etc/php-fpm.conf 去掉以下注释,更改配置文件
- pid = /usr/local/php/var/run/php-fpm.pid
- error_log = /usr/local/php/var/log/php-fpm.log
- listen = 192.168.7.38:9000 监听地址最好改为本机IP,不要默认的127.0.0.1,否则可能会出问题
- listen.owner = nginx 与nginx中帐号一致
- listen.group = nginx
- listen.mode = 0666
- pm.start_servers = 20
- pm.min_spare_servers = 5
- pm.max_spare_servers = 35
- pm.max_requests = 500
/etc/init.d/php-fpm start
chmod 666 /usr/local/php/var/run
5. 配置nginx支持php解析:/etc/nginx/nginx.conf
- user nginx;
- .......
- location / {
- root /usr/share/nginx/html;
- index index.php index.html index.htm;
- }
- location ~ \.php$ {
- root html;
- fastcgi_pass 192.168.7.38:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #或者指定绝对路径也可以/var/www/html/test$fastcgi_script_name
- include fastcgi_params;
- }
php支持memcache的memcached扩展模块安装:
1) libmemcached安装:
- tar zxvf libmemcached-1.0.14.tar.gz
- cd libmemcached-1.0.14
- ./configure --prefix=/usr/local/libmemcached --with-memcached
- make && make install
2) memcached安装
- #tar zxvf memcached-2.1.0.tgz
- #cd memcached-2.1.0
- #/usr/local/php/bin/phpize
- Configuring for:
- PHP Api Version: 20090626
- Zend Module Api No: 20090626
- Zend Extension Api No: 220090626
- #./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached
- #make && make install
安装完后提示模块存放路径:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
修改php.ini文件添加路径和模块:
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
extension = "memcached.so"
备注:一开始是将源码包中的php.ini配置文件模板拷到/etc/php.ini的,发现memcached模块没有加载上,折腾很多后找不出问题,修改php.ini文件随便添加一个不存在的模块,重启php-fpm发现也无出错信息,估计这个php.ini配置文件压根没生效,可能是路径问题。最后想起编译时指定了配置文件路径为/usr/local/php/etc/下,更改到这个目录下测试OK。(注:编译时指定了php配置文件是存放在/usr/local/php/etc/路径下,若不指定的话默认需存放在/usr/local/php/lib/下)
# php -m |grep memcached
memcached 查看OK,模块已加载上
服务启动:
/etc/init.d/php-fpm start
/etc/init.d/nginx start
为了方便php 的命令使用将其路径加入环境变量: export=$PATH:/usr/local/php/bin或加入到/etc/profile中全局永久生效.
测试访问:/usr/share/nginx/html/index.php
<?
phpinfo();
?>
*****************************************************************
源码编译过程出现的问题:
*****************************************************************
/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: *** [sapi/fpm/php-fpm] Error 1
--------------------------------------------
原来是在编辑php时添加的“–with-mcrypt”选项造成。主要是mcrypt原因,lltdl在mcrypt软件包中,确保mcrypt已安装,并安装libtool,libtool-ltdl即可
源码包安装的话:
#cd /software/libmcrypt-2.5.8/libltdl
#./configure –enable-ltdl-install
#make &&make install
另一种安装libltdl的方法:
cd /usr/share/libtool/libltdl
./configure –prefix=/usr
make && make install
/usr/bin/ld: cannot find -libiconv
--------------------------------------------
重装libiconv或舍弃libiconv,使用 –without-iconv,不推荐。在执行时 ./configure … 中指定路径或修改下 Makefile,在最
后面添加 -liconv ,修改后如下
EXTRA_LIBS = -lcrypt -lz -lcrypt -lrt -lmysqlclient -lmcrypt -lldap -llber -lfreetype -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -
lcom_err -lidn -lssl -lcrypto -lz -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -
lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -liconv
Generating phar.phar
chmod: cannot access `ext/phar/phar.phar': No such file or directory
make: [ext/phar/phar.phar] Error 1 (ignored)
--------------------------------------------
5.3.3版本发现源码包中没有phar.phar这个文件, ./configure禁用掉--without-pear或 当前安装目录下cp ext/phar/phar.php ext/phar/phar.phar一份,或做个软链接
libmemcached编译出错:
./libmemcached-1.0/memcached.h:46:27: error: tr1/cinttypes: No such file or directory
make[1]: *** [libmemcached/csl/libmemcached_libmemcached_la-context.lo] Error 1
make[1]: Leaving directory `/packages/libmemcached-1.0.9'
make: *** [all] Error 2
-----------------
#yum install gcc44 gcc44-c++ libstdc++44-devel
# export CC=/usr/bin/gcc44
# export CXX=/usr/bin/g++44
附件建议用vim工具打开