DATA: 2011-04-20
AUTHOR:andy.feng(FH.CN)
Email: lr@isadba.com
BLOG:linuxguest.blog.51cto.com
RHEL5.4 安裝nginx-1.0 + php-5.2.17(fastcgi)+mysql-5.1.40
AUTHOR:andy.feng(FH.CN)
Email: lr@isadba.com
BLOG:linuxguest.blog.51cto.com
RHEL5.4 安裝nginx-1.0 + php-5.2.17(fastcgi)+mysql-5.1.40
一、下載需要的軟體包
#建立存放軟體包的目錄
mkdir -p /soft/diy
#下載nginx-1.0
wget http://www.nginx.org/download/nginx-1.0.0.tar.gz
#建立存放軟體包的目錄
mkdir -p /soft/diy
#下載nginx-1.0
wget http://www.nginx.org/download/nginx-1.0.0.tar.gz
下載php5.2.17
wget http://cn.php.net/get/php-5.2.17.tar.bz2/from/this/mirror
wget http://cn.php.net/get/php-5.2.17.tar.bz2/from/this/mirror
#下載fastcgi補丁
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
#下載mysql,由於mysql官網現在需要登入才能下載,所以我使用自己的原始碼倉庫、順便鄙視一下oracle公司
wget http://122.225.32.131/icons/mysql-5.1.40.tar.gz
wget http://122.225.32.131/icons/mysql-5.1.40.tar.gz
#下載字元轉換庫libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz (下載太慢,最後我還是使用以前的1.13版本)
#下載PHP的memcache擴充套件
http://pecl.php.net/get/memcache-2.2.6.tgz
#下載PHP的imagick擴充套件
wget http://pecl.php.net/get/imagick-3.0.1.tgz
ftp://mirror.aarnet.edu.au/pub/p_w_picpathmagick/ImageMagick-6.6.5-10.tar.bz2 imagick擴充套件的依耐包
#下載PHP的PDO擴充套件
wget http://pecl.php.net/get/PDO-1.0.3.tgz
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
#PHP加速器相關下載,一般選擇一種,這裡我們講4種常見的加速軟體
#下載eaccelerator加速
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
#下載ZendOptimizer,由於官網下載需要註冊,所以我們在opser上下載
wget http://soft.vpser.net/web/zend/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
#下載PHP的apc擴充套件
wget http://pecl.php.net/get/APC-3.1.7.tgz
#xcache加速
wget http://xcache.lighttpd.net/pub/Releases/1.3.2-rc1/xcache-1.3.2-rc1.tar.bz2
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz (下載太慢,最後我還是使用以前的1.13版本)
#下載PHP的memcache擴充套件
http://pecl.php.net/get/memcache-2.2.6.tgz
#下載PHP的imagick擴充套件
wget http://pecl.php.net/get/imagick-3.0.1.tgz
ftp://mirror.aarnet.edu.au/pub/p_w_picpathmagick/ImageMagick-6.6.5-10.tar.bz2 imagick擴充套件的依耐包
#下載PHP的PDO擴充套件
wget http://pecl.php.net/get/PDO-1.0.3.tgz
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
#PHP加速器相關下載,一般選擇一種,這裡我們講4種常見的加速軟體
#下載eaccelerator加速
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
#下載ZendOptimizer,由於官網下載需要註冊,所以我們在opser上下載
wget http://soft.vpser.net/web/zend/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
#下載PHP的apc擴充套件
wget http://pecl.php.net/get/APC-3.1.7.tgz
#xcache加速
wget http://xcache.lighttpd.net/pub/Releases/1.3.2-rc1/xcache-1.3.2-rc1.tar.bz2
上面是一些軟體的下載地址,如果沒有的情自己google找,官網都可以下載,不過速度比較慢
MD5值 軟體名
94239866e5d1b90e02675e988a5cbad4 APC-3.1.7.tgz
e2167713316639705202cf9b6cb1fdb1 imagick-3.0.1.tgz
048032a3032ebd182150bdee30a5d533 libiconv-1.13.tar.gz
0821830d930a86a5c69110837c55b7da libmcrypt-2.5.8.tar.gz
97639f8821b10f80943fa17da302607e mcrypt-2.6.8.tar.gz
9542f1886b72ffbcb039a5c21796fe8a memcache-2.2.6.tgz
ee66b7d5947deb760aeff3f028e27d25 mhash-0.9.9.9.tar.gz
32e7373c16271606007374396e6742ad mysql-5.1.40.tar.gz
5751c920c266ea5bb5fc38af77e9c71c nginx-1.0.0.tar.gz
2256d0a1d0a358265165ca70e7cfc47a pcre-7.9.tar.gz
74bff68b3f1caaf745edaddbd4df7291 PDO-1.0.3.tgz
6121f450488dd4893f5702051c1f84fb PDO_MYSQL-1.0.2.tgz
5339a2a9c6a0b015b7ce5fcb8d90de84 php-5.2.17-fpm-0.5.14.diff.gz
150586c3af37fbdfa504cf142c447e57 ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
32ccd838e06ef5613c2610c1c65ed228 eaccelerator-0.9.6.1.tar.bz2
305bc145200ef5c1f7bba08a12c5f4f2 ImageMagick-6.6.5-10.tar.bz2
b27947f3045220faf16e4d9158cbfe13 php-5.2.17.tar.bz2
5f6ac6f6f4f8ec2322f0bb040559663b xcache-1.3.2-rc1.tar.bz2
3d0a037e73ffe40ea55b521cbff7ff8d go-pear.phar
94239866e5d1b90e02675e988a5cbad4 APC-3.1.7.tgz
e2167713316639705202cf9b6cb1fdb1 imagick-3.0.1.tgz
048032a3032ebd182150bdee30a5d533 libiconv-1.13.tar.gz
0821830d930a86a5c69110837c55b7da libmcrypt-2.5.8.tar.gz
97639f8821b10f80943fa17da302607e mcrypt-2.6.8.tar.gz
9542f1886b72ffbcb039a5c21796fe8a memcache-2.2.6.tgz
ee66b7d5947deb760aeff3f028e27d25 mhash-0.9.9.9.tar.gz
32e7373c16271606007374396e6742ad mysql-5.1.40.tar.gz
5751c920c266ea5bb5fc38af77e9c71c nginx-1.0.0.tar.gz
2256d0a1d0a358265165ca70e7cfc47a pcre-7.9.tar.gz
74bff68b3f1caaf745edaddbd4df7291 PDO-1.0.3.tgz
6121f450488dd4893f5702051c1f84fb PDO_MYSQL-1.0.2.tgz
5339a2a9c6a0b015b7ce5fcb8d90de84 php-5.2.17-fpm-0.5.14.diff.gz
150586c3af37fbdfa504cf142c447e57 ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
32ccd838e06ef5613c2610c1c65ed228 eaccelerator-0.9.6.1.tar.bz2
305bc145200ef5c1f7bba08a12c5f4f2 ImageMagick-6.6.5-10.tar.bz2
b27947f3045220faf16e4d9158cbfe13 php-5.2.17.tar.bz2
5f6ac6f6f4f8ec2322f0bb040559663b xcache-1.3.2-rc1.tar.bz2
3d0a037e73ffe40ea55b521cbff7ff8d go-pear.phar
二、安裝前的準備工作
1、檢查是否已經安裝apache,php和mysql的rpm包
rpm -qa | egrep `httpd|mysql|php`
如果有
yum remove 對應的軟體
2、安裝必須的軟體
yum -y install patch make gcc gcc-c++ gcc-g77 flex bison file
yum -y install libtool libtool-libs autoconf kernel-devel
yum -y install libjpeg libjpeg-devel libpng libpng-devel gd gd-devel
yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel
yum -y install glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel
yum -y install ncurses ncurses-devel curl curl-devel e2fsprogs
yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel
yum -y install openssl openssl-devel vim-minimal nano sendmail
yum -y install fonts-chinese gettext gettext-devel
yum -y install ncurses-devel
yum -y install gmp-devel pspell-devel
yum -y install unzip
1、檢查是否已經安裝apache,php和mysql的rpm包
rpm -qa | egrep `httpd|mysql|php`
如果有
yum remove 對應的軟體
2、安裝必須的軟體
yum -y install patch make gcc gcc-c++ gcc-g77 flex bison file
yum -y install libtool libtool-libs autoconf kernel-devel
yum -y install libjpeg libjpeg-devel libpng libpng-devel gd gd-devel
yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel
yum -y install glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel
yum -y install ncurses ncurses-devel curl curl-devel e2fsprogs
yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel
yum -y install openssl openssl-devel vim-minimal nano sendmail
yum -y install fonts-chinese gettext gettext-devel
yum -y install ncurses-devel
yum -y install gmp-devel pspell-devel
yum -y install unzip
三、開始安裝
1、安裝PHP需要的庫
libiconv-1.13.tar.gz加強系統對支援字元編碼轉換的功能
tar -zxvf libiconv-1.13.tar.gz
cd libiconv-1.13
./configure –prefix=/usr/local/
make && make install
cd ..
1、安裝PHP需要的庫
libiconv-1.13.tar.gz加強系統對支援字元編碼轉換的功能
tar -zxvf libiconv-1.13.tar.gz
cd libiconv-1.13
./configure –prefix=/usr/local/
make && make install
cd ..
libmcrypt-2.5.8.tar.gz加密演算法庫,php擴充套件mcrypt功能對此庫有依耐關係,要使用mcrypt必須先安裝此庫
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && make install
ldconfig
cd libltdl/
./configure –enable-ltdl-install
make && make install
cd ../..
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && make install
ldconfig
cd libltdl/
./configure –enable-ltdl-install
make && make install
cd ../..
mhash-0.9.9.9.tar.gz hash加密演算法庫
tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure && make && make install
cd ..
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
mcrypt-2.6.8.tar.gz簡單的加密程式,php的加密擴充套件,必須先安裝libmcrypt庫
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
ldconfig
./configure
make && make install
cd ..
2、安裝mysql資料庫,略過.
3、安裝PHP(重點)
tar -jxvf php-5.2.17.tar.bz2
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17
./configure –prefix=/usr/local/php
–with-config-file-path=/usr/local/php/etc
–with-mysql=/usr/local/mysql/
–with-mysqli=/usr/local/mysql/bin/mysql_config –with-iconv-dir=/usr/local/
–with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr/
–enable-xml –disable-rpath –enable-discard-path –enable-bcmath
–enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers
–enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring
–with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl
–enable-sockets –with-ldap –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap
–enable-safe-mode \此選項可選,如果使用可以增加安全性,但是一些功能會被制約
編譯完成後認真閱讀php的反饋資訊,看看是否有debug.log檔案,如果有就仔細閱讀,並解決存在的問題。
確認沒有問題後,繼續:
make ZEND_EXTRA_LIBS=`-liconv`
完成後,如果有時間可以 make test 需要10分鐘左右
make install
cp php.ini-dist /usr/local/php/etc/php.ini
安裝pear支援
老版本的php和新版本的php不同,記得在5.2.10版本上,是執行go-pear檔案,新版本中執行的是phar。
wget http://pear.php.net/go-pear.phar
/usr/local/php/bin/php go-pear.phar
4、安裝PHP擴充套件模組
memcache擴充套件介面,如果想要使用memcache功能,還要單獨安裝memcached軟體。
memcache簡介:memcache相當一個簡單的記憶體資料庫
tar -zxvf memcache-2.2.6.tgz
cd memcache-2.2.6
/usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
./configure –with-php-config=/usr/local/php/bin/php-config
make && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
pdo_mysql擴充套件
pdo簡介:pdo是PHP連線資料庫的統一介面,連線對應資料庫需要對應的pdo驅動。
tar -zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config –with-pdo-mysql=/usr/local/mysql/
make && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
安裝PHP擴充套件imagick,處理影像。
如果PHP版本 >= 5.1.3 依耐的 ImageMagick版本就要大於 >= 6.2.4 。
tar -jxvf ImageMagick-6.6.5-10.tar.bz2
./configure
make && make install
tar -zxvf imagick-3.0.1.tgz
cd imagick-3.0.1
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make && make install
nstalling shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
常用擴充套件安裝完成,下面我們配置PHP
5、配置PHP
編輯/usr/local/php/etc/php.ini檔案,找到”extension_dir = “./””此行,使用下面的類容替換此行
;extension_dir = “./”
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/” #儲存擴充套件庫的位置,下面是擴充套件庫的名字,在這個目錄中要能找到下面的庫檔案
extension = “memcache.so”
extension = “pdo_mysql.so”
extension = “imagick.so”
6、配置PHP加速有多種方法,我們暫時不配置加速[當你的LNMP環境搭建完成以後,再倒回來安裝這部分]
a、安裝APC加速器
tar -zxvf APC-3.1.7.tgz
cd APC-3.1.7
/usr/local/php/bin/phpize
./configure –enable-apc –enable-apc-mmap –with-php-config=/usr/local/php/bin/php-config
make && make install
結果:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
Installing header files: /usr/local/php/include/php/
編輯php.ini,查詢extension_dir行,修改此行內容如下(如果按照上面的方法,提前安裝了其他模組,這行應該是不用修改的),並且新增下面沒有的部分,在最後加入[APC]下面的程式碼:
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
[APC]
extension = apc.so
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64M
apc.optimization = 1
apc.num_files_hint = 0
apc.ttl = 0
apc.gc_ttl = 3600
apc.cache_by_default = on
完成後,重新啟動fastcgi,通過phpinfo函式看到下面資訊就算成功了
apc
APC Support enabled
Version 3.1.7
APC Debugging Disabled
MMAP Support Enabled
MMAP File Mask no value
Locking type pthread mutex Locks
Serialization Support php
Revision $Revision: 307215 $
Build Date Apr 26 2011 23:08:03
b、安裝eaccelerator加速器
tar -jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
/usr/local/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php/bin/php-config
make && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
修改php.ini,註釋剛才關於APC的程式碼
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
extension = “memcache.so”
extension = “pdo_mysql.so”
;extension = “apc.so”
tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure && make && make install
cd ..
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
mcrypt-2.6.8.tar.gz簡單的加密程式,php的加密擴充套件,必須先安裝libmcrypt庫
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
ldconfig
./configure
make && make install
cd ..
2、安裝mysql資料庫,略過.
3、安裝PHP(重點)
tar -jxvf php-5.2.17.tar.bz2
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17
./configure –prefix=/usr/local/php
–with-config-file-path=/usr/local/php/etc
–with-mysql=/usr/local/mysql/
–with-mysqli=/usr/local/mysql/bin/mysql_config –with-iconv-dir=/usr/local/
–with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr/
–enable-xml –disable-rpath –enable-discard-path –enable-bcmath
–enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers
–enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring
–with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl
–enable-sockets –with-ldap –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap
–enable-safe-mode \此選項可選,如果使用可以增加安全性,但是一些功能會被制約
編譯完成後認真閱讀php的反饋資訊,看看是否有debug.log檔案,如果有就仔細閱讀,並解決存在的問題。
確認沒有問題後,繼續:
make ZEND_EXTRA_LIBS=`-liconv`
完成後,如果有時間可以 make test 需要10分鐘左右
make install
cp php.ini-dist /usr/local/php/etc/php.ini
安裝pear支援
老版本的php和新版本的php不同,記得在5.2.10版本上,是執行go-pear檔案,新版本中執行的是phar。
wget http://pear.php.net/go-pear.phar
/usr/local/php/bin/php go-pear.phar
4、安裝PHP擴充套件模組
memcache擴充套件介面,如果想要使用memcache功能,還要單獨安裝memcached軟體。
memcache簡介:memcache相當一個簡單的記憶體資料庫
tar -zxvf memcache-2.2.6.tgz
cd memcache-2.2.6
/usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
./configure –with-php-config=/usr/local/php/bin/php-config
make && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
pdo_mysql擴充套件
pdo簡介:pdo是PHP連線資料庫的統一介面,連線對應資料庫需要對應的pdo驅動。
tar -zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config –with-pdo-mysql=/usr/local/mysql/
make && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
安裝PHP擴充套件imagick,處理影像。
如果PHP版本 >= 5.1.3 依耐的 ImageMagick版本就要大於 >= 6.2.4 。
tar -jxvf ImageMagick-6.6.5-10.tar.bz2
./configure
make && make install
tar -zxvf imagick-3.0.1.tgz
cd imagick-3.0.1
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make && make install
nstalling shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
常用擴充套件安裝完成,下面我們配置PHP
5、配置PHP
編輯/usr/local/php/etc/php.ini檔案,找到”extension_dir = “./””此行,使用下面的類容替換此行
;extension_dir = “./”
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/” #儲存擴充套件庫的位置,下面是擴充套件庫的名字,在這個目錄中要能找到下面的庫檔案
extension = “memcache.so”
extension = “pdo_mysql.so”
extension = “imagick.so”
6、配置PHP加速有多種方法,我們暫時不配置加速[當你的LNMP環境搭建完成以後,再倒回來安裝這部分]
a、安裝APC加速器
tar -zxvf APC-3.1.7.tgz
cd APC-3.1.7
/usr/local/php/bin/phpize
./configure –enable-apc –enable-apc-mmap –with-php-config=/usr/local/php/bin/php-config
make && make install
結果:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
Installing header files: /usr/local/php/include/php/
編輯php.ini,查詢extension_dir行,修改此行內容如下(如果按照上面的方法,提前安裝了其他模組,這行應該是不用修改的),並且新增下面沒有的部分,在最後加入[APC]下面的程式碼:
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
[APC]
extension = apc.so
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64M
apc.optimization = 1
apc.num_files_hint = 0
apc.ttl = 0
apc.gc_ttl = 3600
apc.cache_by_default = on
完成後,重新啟動fastcgi,通過phpinfo函式看到下面資訊就算成功了
apc
APC Support enabled
Version 3.1.7
APC Debugging Disabled
MMAP Support Enabled
MMAP File Mask no value
Locking type pthread mutex Locks
Serialization Support php
Revision $Revision: 307215 $
Build Date Apr 26 2011 23:08:03
b、安裝eaccelerator加速器
tar -jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
/usr/local/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php/bin/php-config
make && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
修改php.ini,註釋剛才關於APC的程式碼
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
extension = “memcache.so”
extension = “pdo_mysql.so”
;extension = “apc.so”
;[APC]
;apc.enabled = 1
;apc.shm_segments = 1
;apc.shm_size = 64M
;apc.optimization = 1
;apc.num_files_hint = 0
;apc.ttl = 0
;apc.gc_ttl = 3600
;apc.cache_by_default = on
;apc.enabled = 1
;apc.shm_segments = 1
;apc.shm_size = 64M
;apc.optimization = 1
;apc.num_files_hint = 0
;apc.ttl = 0
;apc.gc_ttl = 3600
;apc.cache_by_default = on
;##############eaccelerator################
extension = “eaccelerator.so”
[eAccelerator]
eaccelerator.shm_size=”128″
eaccelerator.cache_dir=”/tmp/accelerator_cache”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”300″
eaccelerator.shm_prune_period=”120″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
mkdir -p /tmp/accelerator_cache
chown -R nobody:nobody /tmp/accelerator_cache
extension = “eaccelerator.so”
[eAccelerator]
eaccelerator.shm_size=”128″
eaccelerator.cache_dir=”/tmp/accelerator_cache”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”300″
eaccelerator.shm_prune_period=”120″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
mkdir -p /tmp/accelerator_cache
chown -R nobody:nobody /tmp/accelerator_cache
完成後,重新啟動fastcgi,phpinfo中出現如下資訊,即為成功
eAccelerator
eAccelerator support enabled
Version 0.9.6.1
Caching Enabled true
Optimizer Enabled true
Check mtime Enabled true
Memory Size 134,217,688 Bytes
Memory Available 134,215,092 Bytes
Memory Allocated 2,596 Bytes
Cached Scripts 1
Removed Scripts 0
c、安裝ZendOptimizer加速器
tar zxvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
mkdir -p /usr/local/zend/
cp ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/
然後修改php.ini檔案,把剛才關於eaccelerator相關的程式碼註釋掉。在檔案結尾,加入如下程式碼:
[Zend Optimizer]
zend_optimizer.optimization_level=1
zend_extension=”/usr/local/zend/ZendOptimizer.so”
完成後,從新啟動fastcgi,看到如下資訊,即為成功
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
d、安裝xcache加速器(由於我們使用php是5.2裡面最新的版本,所以對應的xcache還是rc版本)
tar -jxvf xcache-1.3.2-rc1.tar.bz2
cd xcache-1.3.2-rc1
/usr/local/php/bin/phpize
./configure –enable-xcache –enable-xcache-coverager –with-php-config=/usr/local/php/bin/php-config
make && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
修改php.ini,註釋zendoptimizer相關程式碼,在extension_dir那句程式碼下面加入,如下程式碼:
[xcache]
extension = xcache.so
xcache.admin.user = “admin”
;xcache.admin.pass = “(執行) echo ’(你的密碼)’|md5sum(得出的密文)”下面的密碼是123456
xcache.admin.pass = “f447b20a7fcbf53a5d5be013ea0b15af”
xcache.size = 24M
xcache.shm_scheme = “mmap”
xcache.count = 2
xcache.slots = 8k
xcache.ttl = 0
xcache.gc_interval = 0
eAccelerator
eAccelerator support enabled
Version 0.9.6.1
Caching Enabled true
Optimizer Enabled true
Check mtime Enabled true
Memory Size 134,217,688 Bytes
Memory Available 134,215,092 Bytes
Memory Allocated 2,596 Bytes
Cached Scripts 1
Removed Scripts 0
c、安裝ZendOptimizer加速器
tar zxvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
mkdir -p /usr/local/zend/
cp ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/
然後修改php.ini檔案,把剛才關於eaccelerator相關的程式碼註釋掉。在檔案結尾,加入如下程式碼:
[Zend Optimizer]
zend_optimizer.optimization_level=1
zend_extension=”/usr/local/zend/ZendOptimizer.so”
完成後,從新啟動fastcgi,看到如下資訊,即為成功
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
d、安裝xcache加速器(由於我們使用php是5.2裡面最新的版本,所以對應的xcache還是rc版本)
tar -jxvf xcache-1.3.2-rc1.tar.bz2
cd xcache-1.3.2-rc1
/usr/local/php/bin/phpize
./configure –enable-xcache –enable-xcache-coverager –with-php-config=/usr/local/php/bin/php-config
make && make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
修改php.ini,註釋zendoptimizer相關程式碼,在extension_dir那句程式碼下面加入,如下程式碼:
[xcache]
extension = xcache.so
xcache.admin.user = “admin”
;xcache.admin.pass = “(執行) echo ’(你的密碼)’|md5sum(得出的密文)”下面的密碼是123456
xcache.admin.pass = “f447b20a7fcbf53a5d5be013ea0b15af”
xcache.size = 24M
xcache.shm_scheme = “mmap”
xcache.count = 2
xcache.slots = 8k
xcache.ttl = 0
xcache.gc_interval = 0
xcache.var_size = 8M
xcache.var_count = 1
xcache.var_slots = 8k
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = “/tmp/xcache”
xcache.coredump_directory = “”
xcache.cacher = On
xcache.stat = On
;xcache.optimizer = Off/On
xcache.coverager = On
xcache.coveragedump_directory = “”
xcache.var_count = 1
xcache.var_slots = 8k
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = “/tmp/xcache”
xcache.coredump_directory = “”
xcache.cacher = On
xcache.stat = On
;xcache.optimizer = Off/On
xcache.coverager = On
xcache.coveragedump_directory = “”
mkdir /tmp/xcache
chmod 777 /tmp/xcache
完成後,從新啟動fastcgi,看到如下資訊,即為成功
XCache
XCache Support enabled
Version 1.3.2-rc1
Modules Built cacher coverager
Readonly Protection enabled
Cache Init Time 2011-04-28 16:57:25
Cache Instance Id 20336
Opcode Cache enabled, 25,165,824 bytes, 2 split(s), with 8192 slots each
Variable Cache enabled, 8,388,608 bytes, 1 split(s), with 8192 slots each
Shared Memory Schemes mmap
Coverage Auto Dumper disabled
chmod 777 /tmp/xcache
完成後,從新啟動fastcgi,看到如下資訊,即為成功
XCache
XCache Support enabled
Version 1.3.2-rc1
Modules Built cacher coverager
Readonly Protection enabled
Cache Init Time 2011-04-28 16:57:25
Cache Instance Id 20336
Opcode Cache enabled, 25,165,824 bytes, 2 split(s), with 8192 slots each
Variable Cache enabled, 8,388,608 bytes, 1 split(s), with 8192 slots each
Shared Memory Schemes mmap
Coverage Auto Dumper disabled
到這裡常用的PHP加速器軟體就算安裝完成了,任選其一即可,推薦APC和xcache
7、建立php-fpm配置檔案,php-fpm是開源社群為php開發的一個補丁,可以平滑變更php.ini,而無需重啟php-cgi
php-fpm.conf檔案的詳細解釋http://php-fpm.org/wiki/Configuration_File
vim /usr/local/php/etc/php-fpm.conf ,使用 :set nu顯示行號。
需要注意的幾行,給大家說說
(原)41 <value name=”listen_address”>127.0.0.1:9000</value>
(改)41 <value name=”listen_address”>/tmp/php-cgi.sock</value> #個人習慣,比較喜歡使用sock。
(原)63 <!– <value name=”user”>nobody</value> –>#程式的所有者
(原)66 <!– <value name=”group”>nobody</value> –>#程式的所有組,預設都為nobody
(改) <value name=”user”>nobody</value>
(改) <value name=”group”>nobody</value>
59 <!– <value name=”display_errors”>0</value> –> #是否顯示錯誤,1為關閉顯示錯誤,0為開啟錯誤顯示,除錯期間可以開啟
79 <value name=”max_children”>5</value> #為客戶端服務的最大程式數
86 <value name=”StartServers”>20</value> #啟動時建立的程式數
<value name=”MinSpareServers”>5</value> #最小空閒程式數
94 <value name=”MaxSpareServers”>35</value>#最大空閒程式數
(原)107 <value name=”request_slowlog_timeout”>0s</value> #預設關閉慢查詢,建議還是開啟,對效能分析有好處
(改)107 <value name=”request_slowlog_timeout”>5s</value>
(原)113 <value name=”rlimit_files”>1024</value> #設定開啟檔案的限制
(改)113 <value name=”rlimit_files”>51200</value>
132 <value name=”max_requests”>5000</value> #設定大可以接受的請求數
137 <value name=”allowed_clients”>127.0.0.1</value> #允許連線的客戶端
啟動php-cgi
Usage: /usr/local/php/sbin/php-fpm {start|stop|quit|restart|reload|logrotate}
/usr/local/php/sbin/php-fpm start
8、安裝nginx-1.0
安裝pcre-7.9.tar.gz,perl擴充套件正規表示式的支援,主要用於支援url rewrite
tar -zxvf pcre-7.9.tar.gz
cd pcre-7.9
./configure
make && make install
cd ..
安裝ngnx-1.0
tar -zxvf nginx-1.0.0.tar.gz
cd nginx-1.0.0
./configure –prefix=/usr/local/nginx –user=nobody –group=nobody –with-http_stub_status_module –with-http_ssl_module
#config完成後,檢視結果,使用了哪些庫,如果有些你希望使用的庫沒有使用,需要安裝或者新增配置引數
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1 library is not used
+ using system zlib library
make && make install
修改配置檔案
vim /usr/local/nginx/conf/nginx.conf
2 user nobody; #取消註釋
12 events {
13 use epoll;
14 worker_connections 51200;
15 }
36 server {
37 listen 80;
38 server_name 122.225.32.135;
66 location ~ .php$ {
67
68 if ( $fastcgi_script_name ~ ..*/.*php ) {
69 return 403;
70 }
71 root html;
72 fastcgi_pass unix:/tmp/php-cgi.sock;
73 fastcgi_index index.php;
74 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
75 include fastcgi.conf;
76 }
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf #測試配置檔案是否正確
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 或者/usr/local/nginx/sbin/nginx
四、測試
cd /usr/local/nginx/html/
echo “<?phpinfo();?>” >phpinfo.php
使用瀏覽器訪問 http://122.225.32.135/phpinfo.php
如果能夠正常顯示PHP的資訊,基本就算成功了。
五、優化和安全
1、
關於fastcgi存在的一個上傳漏洞,
詳見:
http://www.80sec.com/nginx-securit.html
2、php禁用函式,注意,是一行
disable_functions = set_time_limit,system,exec,shell_exec,,passthru,proc_open,proc_close,proc_get_status,checkdnsrr,getmxrr,getservbyname,getservbyport,syslog,popen,show_source,highlight_file,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname,dl,socket_listen,socket_create,socket_bind,socket_accept,socket_connect,stream_socket_server,stream_socket_accept,stream_socket_client,ftp_connect,ftp_login,ftp_pasv,ftp_get,zlib.compress,gzopen,gzpassthru,gzcompress,phpinfo
Usage: /usr/local/php/sbin/php-fpm {start|stop|quit|restart|reload|logrotate}
/usr/local/php/sbin/php-fpm start
8、安裝nginx-1.0
安裝pcre-7.9.tar.gz,perl擴充套件正規表示式的支援,主要用於支援url rewrite
tar -zxvf pcre-7.9.tar.gz
cd pcre-7.9
./configure
make && make install
cd ..
安裝ngnx-1.0
tar -zxvf nginx-1.0.0.tar.gz
cd nginx-1.0.0
./configure –prefix=/usr/local/nginx –user=nobody –group=nobody –with-http_stub_status_module –with-http_ssl_module
#config完成後,檢視結果,使用了哪些庫,如果有些你希望使用的庫沒有使用,需要安裝或者新增配置引數
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1 library is not used
+ using system zlib library
make && make install
修改配置檔案
vim /usr/local/nginx/conf/nginx.conf
2 user nobody; #取消註釋
12 events {
13 use epoll;
14 worker_connections 51200;
15 }
36 server {
37 listen 80;
38 server_name 122.225.32.135;
66 location ~ .php$ {
67
68 if ( $fastcgi_script_name ~ ..*/.*php ) {
69 return 403;
70 }
71 root html;
72 fastcgi_pass unix:/tmp/php-cgi.sock;
73 fastcgi_index index.php;
74 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
75 include fastcgi.conf;
76 }
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf #測試配置檔案是否正確
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 或者/usr/local/nginx/sbin/nginx
四、測試
cd /usr/local/nginx/html/
echo “<?phpinfo();?>” >phpinfo.php
使用瀏覽器訪問 http://122.225.32.135/phpinfo.php
如果能夠正常顯示PHP的資訊,基本就算成功了。
五、優化和安全
1、
關於fastcgi存在的一個上傳漏洞,
詳見:
http://www.80sec.com/nginx-securit.html
2、php禁用函式,注意,是一行
disable_functions = set_time_limit,system,exec,shell_exec,,passthru,proc_open,proc_close,proc_get_status,checkdnsrr,getmxrr,getservbyname,getservbyport,syslog,popen,show_source,highlight_file,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname,dl,socket_listen,socket_create,socket_bind,socket_accept,socket_connect,stream_socket_server,stream_socket_accept,stream_socket_client,ftp_connect,ftp_login,ftp_pasv,ftp_get,zlib.compress,gzopen,gzpassthru,gzcompress,phpinfo