将eAccelerator集成到PHP5和Lighttpd(OpenSUSE 11.2)

将eAccelerator集成到PHP5和Lighttpd(OpenSUSE 11.2)

本指南介绍了如何将eAccelerator 集成到PHP5和lighttpd在OpenSUSE 11.2系统上。 从eAccelerator项目页面: “eAccelerator是一个免费的开源PHP加速器,优化器和动态内容缓存,通过将其缓存在编译状态来提高PHP脚本的性能,从而几乎完全消除了编译的开销。它还可以优化脚本以加快执行速度,eAccelerator通常可以减少服务器负载,并将PHP代码的速度提高1-10倍。

本文档不附带任何形式的保证! 我不会保证这将为您工作!

1初步说明

我已经在具有IP地址192.168.0.100的OpenSUSE 11.2服务器上测试了这一点,其中lighttpd和PHP5已经安装并工作(例如,如本教程所示: 在OpenSUSE 11.2上安装带有PHP5和MySQL支持的Lighttpd )。 在本教程中,我将使用lighttpd的默认文档root / srv / www / htdocs进行演示。 当然,您也可以使用任何其他vhost,但您可能必须调整本教程中使用的info.php文件的路径。

2检查PHP5的当前状态

首先,在安装eAccelerator之前,先看一下我们的PHP5安装。 为此,我们在文件root / srv / www / htdocs中创建文件info.php

vi /srv/www/htdocs/info.php
<?php
phpinfo();
?>

之后,我们在浏览器中调用该文件: http : //192.168.0.100/info.php

正如你所看到的,我们已经安装了PHP 5.3.2 ...

...但eAccelerator没有在页面上的任何地方提到:

3安装eAccelerator

不幸的是,在官方存储库中没有用于OpenSUSE 11.2的eAccelerator软件包,因此我们必须从源代码编译并安装它。 在我们这样做之前,我们需要安装一些先决条件:

yast2 -i gcc flex wget gcc-c++ make php5-devel

现在我们可以这样下载并安装eAccelerator(请确保您从eAccelerator网站获取最新版本):

cd /tmp
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
tar xvfj eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
phpize
./configure
make
make install

接下来我们将eaccelerator.ini复制到/etc/php5/conf.d目录中:

cp eaccelerator.ini /etc/php5/conf.d

现在我们必须通过编辑/etc/php5/conf.d/eaccelerator.ini来配置eAccelerator

vi /etc/php5/conf.d/eaccelerator.ini
[eaccelerator]

;;;;;;;;;;;;;;;;;;;
; About this file ;
;;;;;;;;;;;;;;;;;;;
;
; eAccelerator is compatible with Zend Optimizer's loader. Zend Optimizer
; must be installed after eAccelerator in php.ini. If you don't use scripts
; encoded with Zend Encoder then we do not recommend you install Zend Optimizer
; with eAccelerator.


; You must uncomment one (and only one) line from the following to load
; eAccelerator extension.
extension="eaccelerator.so"
;zend_extension="/usr/lib/php/modules/eaccelerator.so"
;zend_extension_ts="/usr/lib/php/modules/eaccelerator.so"

;extension="eaccelerator.dll"
;zend_extension_ts="c:\php4\eaccelerator.dll"
;zend_extension="c:\php4\eaccelerator.dll"

; The amount of shared memory (in megabytes) that eAccelerator will use.
; "0" means OS default. Default value is "0".
eaccelerator.shm_size = "0"

; The directory that is used for disk cache. eAccelerator stores precompiled
; code, session data, content and user entries  here. The same data can be
; stored in shared memory also (for more quick access). Default value is
; "/tmp/eaccelerator".
eaccelerator.cache_dir = "/var/cache/eaccelerator"

; Enables or disables eAccelerator. Should be "1" for enabling or
; "0" for disabling. Default value is "1".
eaccelerator.enable = "1"

; Enables or disables internal peephole optimizer which may speed up code
; execution. Should be "1" for enabling or "0" for disabling.
; Default value is "1".
eaccelerator.optimizer = "1"

; Enables or disables debug logging. Setting this to 1 will print information
; to the log file about the cach hits of a file.
eaccelerator.debug = 0

; Set the log file for eaccelerator. When this option isn't set then the data
; will be logged to stderr
eaccelerator.log_file = "/var/log/lighttpd/eaccelerator_log"

; A string that's prepended to all keys. This allows two applications that use the
; same key names to run on the same host by setting this in .htaccess or in the main
; configuration file for the whole webserver.
eaccelerator.name_space = ""

; Enables or disables PHP file modification checking. Should be "1"
; for enabling or "0" for disabling. You should set it to "1" if you want
; to recompile PHP files after modification. Default value is "1".
eaccelerator.check_mtime = "1"

; Determine which PHP files must be cached. You may specify the number of
; patterns (for example "*.php *.phtml") which specifies to cache or
; not to cache. If pattern starts with the character "!", it means to ignore
; files which are matched by the following pattern. Default value is "" that
; means - all PHP scripts will be cached.
eaccelerator.filter = ""

; When eAccelerator fails to get shared memory for new script it removes
; all scripts which were not accessed at last "shm_ttl" seconds from shared
; memory. Default value is "0" that means - don't remove any files from
; shared memory.
eaccelerator.shm_ttl = "0"

; When eAccelerator fails to get shared memory for new script it tries to
; remove old script if the previous try was made more then "shm_prune_period"
; seconds ago. Default value is "0" that means - don't try to remove any
; files from shared memory.
eaccelerator.shm_prune_period = "0"

; Enables or disables caching of compiled scripts on disk. It has no effect
; on session data and content caching.
; Default value is "0" that means - use disk and shared memory for caching.
eaccelerator.shm_only = "0"

; The script paths that are allowed to get admin information and do admin
; controls
eaccelerator.allowed_admin_path = ""

我改变了上述文件中的两个设置: eaccelerator.cache_dir =“/ var / cache / eaccelerator”eaccelerator.log_file =“/ var / log / lighttpd / eaccelerator_log”

(您可以阅读本页上的各种配置设置: http : //www.eaccelerator.net/wiki/Settings 。)

如你所见,我们正在使用磁盘缓存目录/ var / cache / eaccelerator ,我们现在必须创建它,使其成为世界可写的:

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

之后,我们重新启动lighttpd,以便我们的新PHP配置生效:

/etc/init.d/lighttpd restart

然后,在浏览器中再次打开info.phphttp : //192.168.0.100/info.php

您现在应该看到页面上提到的eAccelerator,这意味着它已经被成功地集成并且正常工作(我已经在下面的屏幕截图中标记了eAccelerator行,以获得更好的可见性):

4链接

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏