(lnmp)nginx+mysql+php+memcached扩展

环境:centos5.6  nginx0.8+mysql5.0.77+php5.3.3 

php支持memcache的扩展包(libmemcached1.0.14  memcached2.1

 

由于mysql独立出来服务器端版本号为5.0.77为了一致,客户端phpmysql的扩展源码安装用了同样版本,也许不一致关系也不大。

memcached2.0.1版本有bug,所以用了最新版本,libmemcachedphpmemcached扩展必备包.

 

版本下载:(统一下载至/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安装:

  
  
  
  
  1. tar zxvf mysql-5.0.77.tar.gz   
  2. cd mysql-5.0.77  
  3. groupadd mysql  
  4. useradd -g mysql mysql  
  5. ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-ssl  
  6. make && make install  
  7. chmod +w /usr/local/mysql  
  8. 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

  
  
  
  
  1. 编译完成结果:  
  2. Installing PHP SAPI module:       fpm  
  3. Installing PHP CLI binary:        /usr/local/php/bin/  
  4. Installing PHP CLI man page:      /usr/local/php/man/man1/  
  5. Installing PHP FPM binary:        /usr/local/php/sbin/  
  6. Installing PHP FPM config:        /usr/local/php/etc/  
  7. Installing PHP FPM man page:      /usr/local/php/man/man1/  
  8. Installing build environment:     /usr/local/php/lib/php/build/  
  9. Installing header files:          /usr/local/php/include/php/  
  10. Installing helper programs:       /usr/local/php/bin/  
  11.   program: phpize  
  12.   program: php-config  
  13. Installing man pages:             /usr/local/php/man/man1/  
  14.   page: phpize.1  
  15.   page: php-config.1  
  16. Installing PEAR environment:      /usr/local/php/lib/php/  
  17. [PEAR] Archive_Tar    - installed: 1.3.7  
  18. [PEAR] Console_Getopt - installed: 1.2.3  
  19. [PEAR] Structures_Graph- installed: 1.0.3  
  20. [PEAR] XML_Util       - installed: 1.2.1  
  21. [PEAR] PEAR           - installed: 1.9.1  
  22. Wrote PEAR system config file at: /usr/local/php/etc/pear.conf  
  23. You may want to add: /usr/local/php/lib/php to your php.ini include_path  
  24. /usr/local/src/php-5.3.3/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin  
  25. ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar  
  26. Installing PDO headers:          /usr/local/php/include/php/ext/pdo/ 

3. php配置文件指定:

  
  
  
  
  1. [root@Soap38 php-5.3.3]#cp php.ini-production /usr/local/php/etc/php.ini    
  2. [root@Soap38 php-5.3.3]#echo "/usr/local/php/lib/php">>/etc/php.ini  
  3.  

4. 配置phpphp-fpm(factcgi)的支持,使nginx能调度php

1. 添加php-fpm服务

  
  
  
  
  1. [root@Soap38 php-5.3.3]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm  
  2. [root@Soap38 php-5.3.3]# chmod +x /etc/init.d/php-fpm   
  3. [root@Soap38 php-5.3.3]# chkconfig --add php-fpm  
  4. [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    去掉以下注释,更改配置文件

  
  
  
  
  1. pid = /usr/local/php/var/run/php-fpm.pid  
  2. error_log = /usr/local/php/var/log/php-fpm.log  
  3. listen = 192.168.7.38:9000   监听地址最好改为本机IP,不要默认的127.0.0.1,否则可能会出问题  
  4. listen.owner = nginx   与nginx中帐号一致  
  5. listen.group = nginx 
  6. listen.mode = 0666 
  7. pm.start_servers = 20 
  8. pm.min_spare_servers = 5 
  9. pm.max_spare_servers = 35 
  10. pm.max_requests = 500 

/etc/init.d/php-fpm start

chmod 666 /usr/local/php/var/run 

5. 配置nginx支持php解析:/etc/nginx/nginx.conf

  
  
  
  
  1. user nginx;
  2. .......
  3. location / {  
  4.             root   /usr/share/nginx/html;  
  5.             index index.php index.html index.htm;  
  6.         }  
  7.  
  8.  location ~ \.php$ {  
  9.             root           html;  
  10.             fastcgi_pass   192.168.7.38:9000;  
  11.             fastcgi_index  index.php;  
  12.             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  #或者指定绝对路径也可以/var/www/html/test$fastcgi_script_name  
  13.             include        fastcgi_params;  
  14.         } 

 

php支持memcachememcached扩展模块安装

1 libmemcached安装:

  
  
  
  
  1. tar zxvf libmemcached-1.0.14.tar.gz    
  2. cd libmemcached-1.0.14  
  3. ./configure --prefix=/usr/local/libmemcached --with-memcached  
  4. make && make install   

2 memcached安装

  
  
  
  
  1. #tar zxvf memcached-2.1.0.tgz   
  2. #cd memcached-2.1.0  
  3. #/usr/local/php/bin/phpize  
  4. Configuring for:  
  5. PHP Api Version:         20090626  
  6. Zend Module Api No:      20090626  
  7. Zend Extension Api No:   220090626  
  8. #./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached   
  9. #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原因,lltdlmcrypt软件包中,确保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工具打开

你可能感兴趣的:(PHP,nginx,memcached,LNMP)