D.H.Q的烂笔头

Just code for fun~

Ubuntu 12.04 LTS下安装eAccelerator

eAccelerator是什么?下面是它的官方网站介绍

eAccelerator is a free open-source PHP accelerator & optimizer. It increases the performance of PHP scripts by caching them in their compiled state, so that the overhead of compiling is almost completely eliminated. It also optimizes scripts to speed up their execution. eAccelerator typically reduces server load and increases the speed of your PHP code by 1-10 times.

从上面可知,eAccelerator是一个免费开源的PHP加速优化器。它通过缓存PHP代码的编译状态来提高PHP脚本的性能,所以编译的开销几乎为零。同时还优化了代码,加快了代码的执行速度。从而明显减少服务器的负载,使你的PHP代码的执行速度提高1 - 10倍。

简单的说就是,eAccelerator直接调用编译好的opcode,免除PHP代码的编译开销。

这里假如你在Uuntu上已经安装好了PHP,所以用扩展PHP模块的方式来安装eAccelerator,因此需要用到phpize,而phpize是包含在php-dev里,所以下面一行命令就可以安装phpize:

apt-get install php5-dev

成功安装好后,可以在/usr/bin/目录下找到phpize这个命令。

eAccelerator的源代码可以在其寄管的 github 下载:

wget https://github.com/downloads/eaccelerator/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
tar xvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1

源代码安装:

phpize
./configure --with-php-config=/usr/bin/php-config --enable-eaccelerator=shared
make
make test
make install

安装完后会显示“Installing shared extensions: /usr/lib/php5/20090626+lfs/”,而20090626+lfs这个文件夹就是刚安装好的eAccelerator扩展的存放位置。

打开php.ini(Ubuntu默认是放在/etc/php5/cgi/php.ini),配置eAccelerator,在文件最后加上:

[eaccelerator]
zend_extension="/usr/lib/php5/20090626+lfs/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/var/cache/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"

建立eAccelerator的缓存文件夹:

mkdir -p /var/cache/eaccelerator
chmod 0777 /var/cache/eaccelerator

最后,关掉php-cgi进程,重启nginx配置就生效了:

killall -HUP php5-cgi
/etc/init.d/php-fastcgi start
/etc/init.d/nginx reload
/etc/init.d/nginx restart

最后,phpinfo()输出有eAccelerator字样,就算安装完成:)

comments powered by Disqus
返回顶部