2012年5月6日 星期日

LAMP or LNMP ( Cacti 運行環境 )

LNMP (Linux、Nginx、MySQL、PHP)

LAMP (Linux、Apache、MySQL、PHP)

在 WEB Server 的市佔率上,除了 Apache 外.另一個常見的是  Nginx (http://nginx.org/)
同樣是可以建立 PHP + MySql 的網站環境,在使用上也是一個不錯的選項之一.

以建構 Cacti 的網管監控來說.這兩者之間並無太大的差異存在.
但 Nginx 則必需透過 php-fpm 來取代 php5-cgi 或 spawn-fcgi 來取代 php5-cgi
方可支援 PHP!

對傳統 Apache的使用者來說,這是最大的不同之處.也就是說PHP的設定或功能支援上,
有所異動時,
除了要 restart web service 外( service httpd/nginx restart) 也要 restart php-cgi
如 service php-fpm restart or service spawn-fcgi restart.


nginx.conf

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }


#!/bin/bash
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 6 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid


spawn-fcgi
wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz

php-fpm
http://php-fpm.org/

如使用php-fpm (FastCGI Process Manager)
其限制條件為 php 5.2.13以後的版本方可使用.
所以 php 可能會需要 upgrade 的問題

mysql 在 upgrade 無法啟用問題之解法為 先移除後安裝

yum remove mysql mysql-*

wget ftp://fr2.rpmfind.net/linux/epel/5/i386/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
yum --enablerepo=remi update php php-* php_mysql
yum --enablerepo=remi list mysql mysql-server
yum --enablerepo=remi install mysql mysql-server

/etc/init.d/mysqld restart (service mysqld restart)

mysql_upgrade


參考上述方式可將 php Upgrade 至可支援 php-fpm 的版本.

LNMP 的使用環境一樣可以使用下列這些常見的PHP加速套件.

eAccelerator
ZendGuardLoader (限 php 5.3 以上)
ZendOptimizer (限 php 5.2 以下)

eAccelerator 的安裝方式如下.
# phpize
# ./configure
# make
# make install

#mkdir /tmp/eaccelerator
#chmod 0777 /tmp/eaccelerator

vi /etc/php.ini

cgi.fix_pathinfo=1

; zend_optimizer.optimization_level=15
; zend_extension=/usr/lib/php/modules/ZendOptimizer.so

zend_extension=/usr/lib/php/modules/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=

extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/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"

安裝完成後.

[root@nginx /]# php -v
PHP 5.3.12 (cli) (built: May  3 2012 20:26:56)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
    with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
[root@nginx /]#

cacti

沒有留言:

張貼留言