歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> 手動為LiteSpeed安裝eAccelerator和XCache的方法分享

手動為LiteSpeed安裝eAccelerator和XCache的方法分享

日期:2017/3/1 18:05:29   编辑:Linux技術
其實這句話用“和”字不好,因為eAccelerator和XCache並不兼容,你只能忍痛割愛選擇其一,但貌似eAccelerator對新版5.4的PHP支持不好,因此高版本的PHP,XCache算是更好的選擇。至於兩者的具體對比,不在本文的涉及之列,大家可以自行網絡搜索~在閱讀本文前,強烈閱讀本站關於LiteSpeed的相關教程,比如LiteSpeed的安裝方法和面板的配置。

其實LiteSpeed在編譯PHP的時候有這兩個組件可選,但為什麼微魔要單獨手動安裝呢?原因是官方的這兩個組件勾選後經常出現無法解析等問題,這一問題和具體你使用的VPS似乎無關,而和官網鏈接的時常抽風有關,因此,為了避免卡在Compile PHP的第一步,可以暫時取消這兩個組件,像本文一樣,手動安裝~

無論安裝哪一個,請先確保/usr/local/lsws/lsphp5/lib/php.ini是否存在,若不存在,執行如下命令

cp /usr/local/lsws/php/php.ini /usr/local/lsws/lsphp5/lib/

無論你選擇安裝哪一個,最後都請在LiteSpeed面板裡Graceful Restart重啟生效~
安裝eAccelerator
1.安裝必要的依賴文件(很多時候這一步其實是多此一舉,但是為了避免出錯,還是做吧~)

本文我以Debian為例,至於CentOS,可以講文中apt-get換成yum,基本可以通用~

apt-get install autoconf automake libtool m42.安裝eAccelerator

可自行到官網查詢最新版的下載鏈接,替換下面的url(前往官網下載頁)

復制代碼代碼如下:
cd ~
wget https://github.com/downloads/eaccelerator/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
/usr/local/lsws/lsphp5/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/lsws/lsphp5/bin/php-config
make
make install


如果你默認在LiteSpeed裡編譯的是PHP 5.4,進行make的時候可能出現如下錯誤,原因可能是新版對5.4的不兼容造成的。要麼改裝XCache,要麼就換PHP 5.3吧

復制代碼代碼如下:
/home/package/eaccelerator-0.9.6.1/eaccelerator.c: In function ‘eaccelerator_restore’:
/home/package/eaccelerator-0.9.6.1/eaccelerator.c:878: warning: assignment discards qualifiers from pointer target type
/home/package/eaccelerator-0.9.6.1/eaccelerator.c: In function ‘eaccelerator_compile_file’:
/home/package/eaccelerator-0.9.6.1/eaccelerator.c:1317: error: ‘zend_class_entry’ has no member named ‘line_start’
/home/package/eaccelerator-0.9.6.1/eaccelerator.c: At top level:
/home/package/eaccelerator-0.9.6.1/eaccelerator.c:1913: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘eaccelerator_functions’
/home/package/eaccelerator-0.9.6.1/eaccelerator.c:1938: error: ‘eaccelerator_functions’ undeclared here (not in a function)
make: *** [eaccelerator.lo] Error

13.配置eAccelerator生效(這一部分在前面的文章裡講過,這裡不多說了~)

復制代碼代碼如下:
mkdir /usr/local/eaccelerator_cache
chmod -R 777 /usr/local/eaccelerator_cache
vi /usr/local/lsws/lsphp5/lib/php.ini

在php.ini文件末尾加入如下字段

復制代碼代碼如下:
[eaccelerator]
zend_extension="/usr/local/lsws/lsphp5/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="1"
eaccelerator.cache_dir="/usr/local/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"
eaccelerator.keys = "disk_only"
eaccelerator.sessions = "disk_only"
eaccelerator.content = "disk_only"

檢測php.ini文件是否正常

復制代碼代碼如下:
/usr/local/lsws/lsphp5/bin/php -v

不出意外的話應該不會報錯~

安裝XCache
1.安裝Xcache(查看官網最新版本)

復制代碼代碼如下:
cd ~
wget http://xcache.lighttpd.net/pub/Releases/3.0.0/xcache-3.0.0.tar.gz
tar zxvf xcache-3.0.0.tar.gz
cd xcache-3.0.0
/usr/local/lsws/lsphp5/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/lsws/lsphp5/bin/php-config
make
make install

make install後會給出一個目錄,記下來備用,根據litespeed的版本不同,似乎這個目錄名也不同~我的是/usr/local/lsws/lsphp5/lib/php/extensions/no-debug-non-zts-20100525/
2.修改php.ini文件

復制代碼代碼如下:
vi /usr/local/lsws/lsphp5/lib/php.ini

在末尾加入以下內容

復制代碼代碼如下:
extension_dir = "/usr/local/lsws/lsphp5/lib/php/extensions/no-debug-non-zts-20100525/"
extension="xcache.so"
[xcache-common]
;; install as zend extension (recommended), normally “$extension_dir/xcache.so”
;; or install as extension, make sure your extension_dir setting is correct
; extension = xcache.so
[xcache.admin]
xcache.admin.auth = On
xcache.admin.user = "mOo"
; xcache.admin.pass = md5($your_password)
xcache.admin.pass =
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 32M
xcache.count = 1
xcache.slots = 8K
xcache.ttl = 3600
xcache.gc_interval = 300
; Same as aboves but for variable cache
; If you don’t know for sure that you need this, you probably don’t
xcache.var_size = 0M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
; N/A for /dev/zero
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.cacher = On
xcache.stat = On

其中,密碼字段xcache.admin.pass可自定義,用md5加密你要的密碼填入,比如

echo -n "vmvps" | md5sum

3.檢驗php.ini是否出錯

/usr/local/lsws/lsphp5/bin/php -v

如果出現如下錯誤

PHP Fatal error: Directive 'allow_call_time_pass_reference' is no longer available in PHP in Unknown on line 0可以通過以下命令解決

perl -pi -e 's/^allow_call_time_pass_reference/;allow_call_time_pass_reference/' /usr/local/lsws/lsphp5/lib/php.ini

本文到此結束,還是那句話,無論你選擇安裝哪一個,最後都請在LiteSpeed面板裡Graceful Restart重啟生效~
Copyright © Linux教程網 All Rights Reserved