分類

近期留言

線上訪客

2024 年 4 月
1234567
891011121314
15161718192021
22232425262728
2930  

分類

近期留言

Web Server 加速

最近在測 WordPress, 發現網頁打開速度真的很慢
一開始是以為是網頁的圖檔太多, 後來用了幾個網站Check才發現不是

找了一下, 大概有三個地方是應該調整,
至少是裝好 freeBSD 後, 如果你的軟體是用 port 安裝的, 大概都不會有的:

第一個是 php 的部份:

php 可以加掛 eAccelerator – 這是一套 php 的加速軟體, 安裝方式簡單說明如下:

# cd /usr/ports/www/eaccelerator
# make install

安裝完成前應該會看到一段該死的指示:
You have installed the eaccelerator package.

Edit /usr/local/etc/php.ini and add:

zend_extension=”/usr/local/lib/php/20050922/eaccelerator.so”

Then create the cache directory:

mkdir /tmp/eaccelerator
chown www /tmp/eaccelerator
chmod 0700 /tmp/eaccelerator

你如果照作大概就會打開不了網頁, as usual google 一下, 知道要修改兩個地方:

1, 打開 /usr/local/etc/php/extension.ini , 在檔案的最後面加上:
extension=eaccelerator.so

2, 再打開 /usr/local/etc/php.ini , 在檔案的最後面加上這些設定:

eaccelerator.shm_size=”16″
eaccelerator.cache_dir=”/tmp/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
accelerator.shm_max=”0″
eaccelerator.shm_ttl=”0″
eaccelerator.shm_prune_period=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9

檢查 eAccelerator 是否載入的方法如下:

# /usr/local/bin/php -v
PHP 5.2.12 with Suhosin-Patch 0.9.7 (cli) (built: Jan 26 2010 14:33:59)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerato
r

第二個是 apache 的部份:

如果你是用 port 來安裝 apache, 大概都不會啟用 HTTP Compression. 這個部份如果不確定, 可以連到 Check HTTP Compression 檢查一下, 如果出現這個畫面

就知道 HTTP Compression 沒有啟動. 解決方法就是把 apache 上的 mod_deflate 啟用.

1, 首先 check /usr/local/etc/apache22/httpd.conf 檔案裡有沒有這一行:
LoadModule deflate_module libexec/apache22/mod_deflate.so

2, 如果沒有, 請到 /usr/ports/www/apache22 裡面去執行

# make config

把 Enable mod_deflate 打 V

然後重新 compile apache 並安裝, 再去修改 /usr/local/etc/apache22/httpd.conf , 加入如下設定:

< IfModule mod_deflate.c>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE js css
< IfModule mod_deflate.c>

然後重新啟動 apache, 再連到 Check HTTP Compression 檢查一次, 結果會變成:

就大功告成了

第三個是調整 MySQL, 啟用快取

這個部份只要修改 /etc/my.cnf 檔案, 加入下列三行:
query_cache_limit = 4M
query_cache_size = 128M
query_cache_type = 1

再重新啟動 MySQL 就可以了.

三個都修改後, 感覺整個 WordPress 的網站開啟速度順暢很多

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>