Powered by Typecho)))
Optimized by EAimTY
这里有必要说明下php效率问题,suphp比suexec要快一点;比suphp更快的还有suphp_mod_php;再快一些的是mpm-peruser,不过安装配置的麻烦程度也随之递增。考虑到后期部署其他语言的方便性,故选择通用性更强的fcgi模式。
suexec编译选项要注意的事项:
--with-suexec-caller=web-httpd
调用用户,应该跟Apache运行用户保持一致
--with-suexec-uidmin=500
可使用suexec的用户最小uid
--with-suexec-gidmin=500
可使用suexec的用户组最小gid
--with-suexec-userdir=/wwwroot
定义suEXEC允许访问的用户宿主目录下的子目录。suEXEC将以用户身份执行这个目录下的所有可执行程序,所以这些程序必须是"安全程序"。如果使用"简单的"UserDir指令(即不带"*"),则此处应该被设置为相同的值。当UserDir指令所指向的目录与"passwd"文件所指定的用户宿主目录不同时,suEXEC将不会正常工作,其默认值是"public_html"。如果所支持的虚拟主机对每个用户有不同的UserDir ,则应该把他们集中在同一个父目录下,而用这个参数指向这个父目录。如果配置不当,"~userdir"下的cgi请求将无效!
--with-suexec-docroot=/home/
此选项尤为重要,必须是php程序运行的上级目录。不支持通配符*。
--with-suexec-umask=4755
更多配置请看这里
http://lamp.linux.gov.cn/Apache/ApacheMenu/suexec.html
Apache2.2.x安装配置选项略,详情见前面这里。
1:mod_fcgid安装
APXS=/usr/local/apache2/bin/apxs ./configure.apxs
make & make install
2:mod_encoding 安装(解决中文路径问题)
详情搜索本站,在此略过。
权限问题:这是最繁琐的问题,折磨我很久的问题,请注意bin目录,build目录,include目录(这里指的是相对应Apache目录,下文中未明确指出的地方,均是指相对Apache目录)下的文件属主必须为root, modules下的httpd.exp属主为root。其他未明确指出的目录或文件,属主应为Apache运行用户。
关于用户的cgi程序目录问题:1,必须隶属于--with-suexec-docroot目录(关于suexec详细参数,可以运行bin/suexec -V查看)。2,cgi程序和cgi的上级目录属主必须为用户本身,且cgi程序有x执行权限。
错误例子:
suexec_log
[2006-01-02 15:03:16]: user mismatch (postfix instead of httpd)
[2006-01-02 15:06:07]: uid: (200/postfix) gid: (200/200) cmd: index.cgi
[2006-01-02 15:06:07]: target uid/gid (200/200) mismatch with directory (502/502) or program (502/502)
[2006-01-02 15:06:11]: uid: (200/postfix) gid: (200/200) cmd: index.cgi
[2006-01-02 15:06:11]: target uid/gid (200/200) mismatch with directory (502/502) or program (502/502)
cgi文件的父目录的属性不匹配,必须也chown 到uid=200的那个。
安装编译所需要的库:
apt-get install libxml2-dev libmcrypt-dev libssl-dev libldap2-dev libmhash-dev libmysqlclient-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libsasl2-dev
安装libevent
cd ~/src
wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar xf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure --enable-shared
make
make installulimit -SHn 65535
安装pcre
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.00.tar.gz
tar zxvf pcre-8.00.tar.gz
cd pcre-8.00/
./configure
make && make install
安装libunwind#否则无法安装Google-perftools
cd /libunwind-0.99
./configure --enableshared
make
make install
安装google-perftools#mysql和nginx需要(64位必须加--enable-frame-pointers)
wget http://google-perftools.googlecode.com/files/google-perftools-1.5.tar.gz
./configure --enableshared --enable-frame-pointers
make
make install
下载purge #清除缓存用的
wget http://labs.frickle.com/files/ngx_cache_purge-1.0.tar.gz
tar zxvf ngx_cache_purge-1.0.tar.gzwget http://nginx.org/download/nginx-0.8.32.tar.gz
tar zxvf nginx-0.8.32.tar.gz
cd nginx-0.8.32/
cd ../
./configure --prefix=/zh/nginx --user=www-data --group=www-data --with-rtsig_module --with-select_module --with-poll_module --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --http-client-body-temp-path=/tmp/nginx/client --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --with-google_perftools_module --add-module=/home/web_package/ngx_cache_purge-1.0
启动nginx错误解决办法
1:error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
解决方法,在/lib中创建一个symbol link到/usr/local/pcre/lib/libpcre.so.0
sudo ln -s /usr/local/pcre/lib/libpcre.so.0 /lib
2:error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directory
安装ImageMagick
cd ~/src
apt-get build-dep imagemagick
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar xf ImageMagick.tar.gz
cd ImageMagick-6.5.8-6/
./configure
make
aptitude install libperl-dev
make installapt-get build-dep php
wget http://cn2.php.net/get/php-5.3.1.tar.bz2/from/this/mirror
tar xf php-5.3.1.tar.bz2
#下载imagick
cd ~/src
wget http://pecl.php.net/get/imagick-2.3.0.tgz
tar xf imagick-2.3.0.tgz
cp -R imagick-2.3.0 php-5.3.1/ext/imagick
cd php-5.3.1
./buildconf --force
#下载php-fpm
apt-get install batch
wget http://launchpad.net/php-fpm/master/0.6/+download/php-fpm-0.6~5.3.1.tar.gz
$ tar -xzf php-fpm-0.6~5.3.1.tar.gz
$ php-fpm-0.6-5.3.1/generate-fpm-patch
$ patch -d php-5.3.1 -p1$ cd php-5.3.1
$ ./buildconf --force./configure --prefix=/zh/php5 --with-fpm --with-libxml-dir=/usr --with-fpm-bin=/zh/php5/fpm --with-fpm-conf=/zh/php5/etc --with-fpm-user=www-data --with-fpm-group=www-data --with-layout=GUN --with-config-file-path=/zh/php5/etc --with-config-file-scan-dir=/zh/php5/etc --with-openssl --with-zlib --enable-bcmath --enable-calendar --with-curl --with-curlwrappers --enable-exif --enable-ftp --disable-rpath --with-gd --with-jpeg-dir --with-png-dir --enable-gd-native-ttf --with-gettext --with-mhash --with-imagick --with-imap --with-imap-ssl --with-ldap --enable-mbstring --with-mcrypt --with-mysql=mysqlnd --enable-mbregex --with-mysql-sock --with-mysqli --with-pdo-mysql --with-pdo-sqlite --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-sysvsem --with-xmlrpc --enable-zip --without-pear --enable-shmop --enable-pcntl --with-libevent=shared --with-kerberos
make
make install
安装记录
molyx:/home/web_package/php-5.3.1# make install
Installing PHP SAPI module: fpm
Installing PHP CLI binary: /zh/php5/bin/
Installing PHP CLI man page: /zh/php5/man/man1/
Installing build environment: /zh/php5/lib/php/build/
Installing header files: /zh/php5/include/php/
Installing helper programs: /zh/php5/bin/
program: phpize
program: php-config
Installing man pages: /zh/php5/man/man1/
page: phpize.1
page: php-config.1
/home/web_package/php-5.3.1/build/shtool install -c ext/phar/phar.phar /zh/php5/bin
ln -s -f /zh/php5/bin/phar.phar /zh/php5/bin/pharupdate-rc.d php-fpm defaults
sed -i "s/nobody/www-data/g" /etc/php-fpm.conf
/etc/init.d/php-fpm start
make install
cp php.ini-dist /zh/php5/etc/php.ini
ln -s /zh/php5/sbin/php-fpm /etc/init.d/php-fpm
update-rc.d -f php-fpm defaults
编译后的php安装在/opt/php下面,php的配置文件是/opt/php/lib/php.ini
和其他Linux下不同,在Debian下这时候启动php-fpm会失败,原因是在Debian下php-fpm的配置文件中必须指定运行时的用户才行。
优化php-fpm
编辑php-fpm的配置文件/etc/php-fpm.conf,
* 去掉display_errors参数的注释,修改参数值为1
* 去掉sendmail_path参数的注释
* 去掉user,group参数的注释
* 修改max_children参数的值为10
安装php加速器eAccelerator
tar jxf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3
apt-get install -y autoconf
/zh/php5/bin/phpize
./configure --with-php-config=/zh/php5/bin/php-config --enable-eaccelerator --enable-shared
make
make install
mkdir /tmp/php/eaccelerator_cache
然后重启php-fpm,在phpinfo()页面中应该能看到eaccelerator的信息了。
附录:
memcache模块安装:
/zh/php5/bin/phpize
./configure --enable-memcache --enable-shared --with-php-config=/zh/php5/bin/php-config
make
make install
Suhosin模块安装:
/zh/php5/bin/phpize
./configure --with-php-config=/zh/php5/bin/php-config --enable-shared --enable-suhosin
make
make install
extension_dir = "/zh/php5/lib/php/extensions/no-debug-non-zts-20090626"
;suhosin module
[suhosin]
extension=suhosin.so
;memcache module
[memcache]
extension=memcache.so
;eaccelerator module
[eaccelerator]
;zend_extension="/zh/php5/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/php/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
错误解决
1:utf8_mime2text() has new signature, but U8T_CANONICAL is missing
安装c-client
apt-get install libc-client-dev
2:configure: error: libevent.a could not be found. Stop.
使用参数--with-libevent=shared
3:This c-client library is built with Kerberos support.
添加 --with-kerberos to your configure line. Check config.log for details
使用EA或者类似的OP CODE加速器已经是搭建PHP环境的默认选项了
但是在使用nginx的环境内
会需要使用fastcgi方式来运行php
这种情况下.EA的内存占用可能会和你在APACHE下使用EA不同
由于APACHE调用PHP的方式是模块方式的
所有PHP是位于同一个进程下面的
所以所有PHP模块调用的EA是同一个的.
内存只会占用shm_size大小.
APACHE进程间共享这同一个EA
也就是如果你在ea的配置下面写了64M.则只会占用整个系统的64M
而如果用fastcgi模式
特别是php-fpm
每个php都是独立进程
导致每个PHP进程下面都会独立分配EA的内存
则总的内存占用量 = shm_size * php进程数
如果你还用64M的话.开启20个PHP进程就意味着你用掉了1280M内存.
虽然目前只是分配到虚拟内存
但是对于大型网站的话,
不久之后就会占用到了这么大量的内存.
目前具体如何解决还没有找到
但是大家需要注意这个情况.
不同进程间ea缓冲相同文件是否会导致两份数据目前还没有测试.
转自:
http://www.hiadmin.com/php-fpm%e4%b8%8b%e4%bd%bf%e7%94%a8eaccelerator%e4%ba%a7%e7%94%9f%e7%9a%84%e5%86%85%e5%ad%98%e9%97%ae%e9%a2%98/