rpm -ivh epel-release-5-3.noarch.rpm
yum list
yum install nginx gcc openssl-devel pcre-devel zlib-devel mysql-server mysql-devel libmcrypt-devel libxml2-devel libtool-ltdl-devel
gzip -cd php-5.2.9-fpm-0.5.10-unofficial.diff.gz |patch -d php-5.2.9 -p1
cd php-5.2.9
./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm --with-mysql --with-mcrypt --with-zlib
make && make install
cp /usr/local/php/sbin/php-fpm /etc/init.d
vim /etc/init.d/php-fpm
# chkconfig: - 85 15
# description: php-fpm
vim /usr/local/php/etc/php-fpm.conf
fpm安装完成后 (其实是php的编译前打上fpm的补丁,在编译的时候增加fpm的参数)
要将 Unix user of processes
<value name="user">nobody</value>
Unix group of processes
<value name="group">nobody</value>
这2个的注释去掉,不然就会提示
root@yuan:/server/nginx/html# /server/php/sbin/php-fpm start
Starting php_fpm Sep 11 17:12:07.248390 [ERROR] fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool 'default'
done
vim /etc/nginx/nginx.conf
取消注释
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
vim /etc/nginx/fastcgi_params
加一条fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
service nginx restart
先安装libevent:
tar zxvf libevent-1.2.tar.gz
cd libevent-1.2
./configure --prefix=/usr
make
make install
Memcached 服务端安装:(源码包官方网站下载)
系统命令
tar xvf memcached-1.2.6.tar.gz
cd memcached-1.2.6
./configure --prefix=/usr/local/memcached --with-libevent=/usr/
make
make install
然后就可以启动memcached的守护进程了:
系统命令
/usr/local/memcached/bin/memcached -p 11211 -l 127.0.0.1 -d -u nobody -P /var/run/memcached.pid -m 64M -c 1024
php中memcache扩展组件的安装:
系统命令
tar xvf memcache-3.0.3.tgz
cd memcache-3.0.3
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config --enable-memcache
make
make install
php中memcache扩展组件的安装:
系统命令
tar xvf memcache-3.0.3.tgz
cd memcache-3.0.3
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache
make
make install
按照我的环境,编译出来的memcache.so保存在 /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ 目录下,如果你的环境不一样,你得根据自己情况修改你的php.ini了。
接着要做的工作就是让php加载这个扩展,编辑你的php.ini,在适当位置(通常是最后,也可以是独立的一个ini文件)加入如下行:
extension=memcache.so
然后重启你的phpfastcgi进程或者apache,运行一个phpinfo()来确认一下,正常的话你应该可以看到这个了:memcache
php-memcache的简单使用举例:
<?php
$memcache = new Memcache;
$memcache->connect('127.0.0.1','11211');
$memcache->setCompressThreshold(20000, 0.2);
echo $memcache->getVersion();
$test = array(1,2,3,4,5,'abcde');
if($memcache->get('test')){
print_r($memcache->get('test'));
echo "\n";
echo 'cached';
echo "\n";
}else{
$memcache->set('test',$test,0,30);
echo 'no cache';
echo "\n";
}
?>
四 配置XCache
1、安装xcache模块
wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
tar -xvzf xcache-1.2.2.tar.gz
cd xcache-1.2.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache --enable-xcache-optimizer
make
make install
2、计算密码的md5值
echo -n "password"|md5sum
5f4dcc3b5aa765d61d8327deb882cf99
3、配置XCache
;注: zend_extension,用来加载zend的扩展,是绝对路径,
extension是相对路径,相对于extension_dir的相对路径,非zend扩展
如果你更改路径以后,一定要apachectl stop后再start,而不要restart。
vi /usr/local/php/etc/php.ini
添加:
[xcache-common]
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
[xcache.admin]
; Change xcache.admin.user to your preferred login name
xcache.admin.user = "admin"
; Change xcache.admin.pass to the MD5 fingerprint of your password
; Use md5 -s "your_secret_password" to find the fingerprint
xcache.admin.pass = "5f4dcc3b5aa765d61d8327deb882cf99"
[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size = 24M
xcache.shm_scheme = "mmap"
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
; Change xcache.var_size to adjust the size of variable cache
xcache.var_size = 8M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[xcache.coverager]
xcache.coverager = On
xcache.coveragedump_directory = ""
5、重启PHP模块
正常load之后,
在phpinfo显出的信息内
Zend这快应该会加上XCache的内容
6、另外两种加速模块:
在我们的测试中,效果都要好于xcache,这3中加速不能同时存在两种,有冲突。
6.1 apc
wget http://pecl.php.net/get/APC-3.0.19.tgz
cd APC-3.0.19
/usr/local/php/bin/phpize
./configure --enable-apc --enable-apc-mmap --with-apxs=/EBS/apache/bin/apxs --with-php-config=/EBS/php/bin/php-config
make
make install
6.2 eaccelerator
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.zip
cd eaccelerator-0.9.5.3
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/EBS/php/bin/php-config
make
make install
vi php.ini
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
五、使用nginx对应多台facgi服务器
思路:前端一台nginx,用于做为负载均衡和处理静态页面。利用nginx的upstream模块来将php请求分发到后段的php-fpm服务器上。
后端多台php-fpm的服务器,只起php-fpm服务来处理php。
这样做减少了php-fpm上的nginx服务,相当于少了一层。
yum list
yum install nginx gcc openssl-devel pcre-devel zlib-devel mysql-server mysql-devel libmcrypt-devel libxml2-devel libtool-ltdl-devel
gzip -cd php-5.2.9-fpm-0.5.10-unofficial.diff.gz |patch -d php-5.2.9 -p1
cd php-5.2.9
./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm --with-mysql --with-mcrypt --with-zlib
make && make install
cp /usr/local/php/sbin/php-fpm /etc/init.d
vim /etc/init.d/php-fpm
# chkconfig: - 85 15
# description: php-fpm
vim /usr/local/php/etc/php-fpm.conf
fpm安装完成后 (其实是php的编译前打上fpm的补丁,在编译的时候增加fpm的参数)
要将 Unix user of processes
<value name="user">nobody</value>
Unix group of processes
<value name="group">nobody</value>
这2个的注释去掉,不然就会提示
root@yuan:/server/nginx/html# /server/php/sbin/php-fpm start
Starting php_fpm Sep 11 17:12:07.248390 [ERROR] fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool 'default'
done
vim /etc/nginx/nginx.conf
取消注释
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
vim /etc/nginx/fastcgi_params
加一条fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
service nginx restart
先安装libevent:
tar zxvf libevent-1.2.tar.gz
cd libevent-1.2
./configure --prefix=/usr
make
make install
Memcached 服务端安装:(源码包官方网站下载)
系统命令
tar xvf memcached-1.2.6.tar.gz
cd memcached-1.2.6
./configure --prefix=/usr/local/memcached --with-libevent=/usr/
make
make install
然后就可以启动memcached的守护进程了:
系统命令
/usr/local/memcached/bin/memcached -p 11211 -l 127.0.0.1 -d -u nobody -P /var/run/memcached.pid -m 64M -c 1024
php中memcache扩展组件的安装:
系统命令
tar xvf memcache-3.0.3.tgz
cd memcache-3.0.3
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config --enable-memcache
make
make install
php中memcache扩展组件的安装:
系统命令
tar xvf memcache-3.0.3.tgz
cd memcache-3.0.3
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache
make
make install
按照我的环境,编译出来的memcache.so保存在 /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ 目录下,如果你的环境不一样,你得根据自己情况修改你的php.ini了。
接着要做的工作就是让php加载这个扩展,编辑你的php.ini,在适当位置(通常是最后,也可以是独立的一个ini文件)加入如下行:
extension=memcache.so
然后重启你的phpfastcgi进程或者apache,运行一个phpinfo()来确认一下,正常的话你应该可以看到这个了:memcache
php-memcache的简单使用举例:
<?php
$memcache = new Memcache;
$memcache->connect('127.0.0.1','11211');
$memcache->setCompressThreshold(20000, 0.2);
echo $memcache->getVersion();
$test = array(1,2,3,4,5,'abcde');
if($memcache->get('test')){
print_r($memcache->get('test'));
echo "\n";
echo 'cached';
echo "\n";
}else{
$memcache->set('test',$test,0,30);
echo 'no cache';
echo "\n";
}
?>
四 配置XCache
1、安装xcache模块
wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
tar -xvzf xcache-1.2.2.tar.gz
cd xcache-1.2.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache --enable-xcache-optimizer
make
make install
2、计算密码的md5值
echo -n "password"|md5sum
5f4dcc3b5aa765d61d8327deb882cf99
3、配置XCache
;注: zend_extension,用来加载zend的扩展,是绝对路径,
extension是相对路径,相对于extension_dir的相对路径,非zend扩展
如果你更改路径以后,一定要apachectl stop后再start,而不要restart。
vi /usr/local/php/etc/php.ini
添加:
[xcache-common]
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
[xcache.admin]
; Change xcache.admin.user to your preferred login name
xcache.admin.user = "admin"
; Change xcache.admin.pass to the MD5 fingerprint of your password
; Use md5 -s "your_secret_password" to find the fingerprint
xcache.admin.pass = "5f4dcc3b5aa765d61d8327deb882cf99"
[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size = 24M
xcache.shm_scheme = "mmap"
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
; Change xcache.var_size to adjust the size of variable cache
xcache.var_size = 8M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[xcache.coverager]
xcache.coverager = On
xcache.coveragedump_directory = ""
5、重启PHP模块
正常load之后,
在phpinfo显出的信息内
Zend这快应该会加上XCache的内容
6、另外两种加速模块:
在我们的测试中,效果都要好于xcache,这3中加速不能同时存在两种,有冲突。
6.1 apc
wget http://pecl.php.net/get/APC-3.0.19.tgz
cd APC-3.0.19
/usr/local/php/bin/phpize
./configure --enable-apc --enable-apc-mmap --with-apxs=/EBS/apache/bin/apxs --with-php-config=/EBS/php/bin/php-config
make
make install
6.2 eaccelerator
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.zip
cd eaccelerator-0.9.5.3
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/EBS/php/bin/php-config
make
make install
vi php.ini
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
五、使用nginx对应多台facgi服务器
思路:前端一台nginx,用于做为负载均衡和处理静态页面。利用nginx的upstream模块来将php请求分发到后段的php-fpm服务器上。
后端多台php-fpm的服务器,只起php-fpm服务来处理php。
这样做减少了php-fpm上的nginx服务,相当于少了一层。
本文转自leonardos51CTO博客,原文链接: http://blog.51cto.com/leomars/419388,如需转载请自行联系原作者