我爱linux

我是一个linux运维从业者,这个网站记录一些平时调试linux相关文档及生活随笔

Archive for the ‘nginx’ Category

Debian 6(Squeeze)编译搭建shopex或ecshop环境

without comments

Debian 6(Squeeze)编译搭建shopex或ecshop环境 Nginx+php5.2.x+Mysql+ZendOptimizer

shopex环境目前只支持php5.2.x,是因为它只支持Zend Optimizer,高版本的Zend Guard是不支持的, 而debian 6 默认安装php是5.3.x,这个版本的php是不支持Zend Optimizer,只支持Zend Guard.所以很矛盾呀,要想使用shopex系统,要么使用debian5 ,但又纠结于想用更高版本的debian6 ,所以我们这里讲述如何在debian6 系统上手动编译安装 支

shopex环境的搭建。真是没办法,老实说不愿破坏debian自带的软件包管理系统

一、安装nginx

添加nginx源 vi /etc/apt/sources.list

deb http://nginx.org/packages/debian/ squeeze nginx
deb-src http://nginx.org/packages/debian/ squeeze nginx

apt-get update
apt-get install nginx

这样我们就能升级到最新稳定版本的nginx,截至目前是1.0.10

二、安装mysql-server及编译所需库文件

apt-get install mysql-server libmysqlclient15-dev

三、编译安装php5.2.x

准备php编译所需的依赖包

aptitude install libgd2-noxpm-dev libxml2-dev libcurl3-dev libmhash-dev libmcrypt-dev libxslt-dev libpspell-dev libbz2-dev libglobus-openssl-dev

安装编译环境

apt-get install build-essential

下载php3.2.17
wget http://am.php.net/distributions/php-5.2.17.tar.gz

下载php-fpm补丁
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
gzip -d php-5.2.17-fpm-0.5.14.diff.gz

tar zvxf php-5.2.17.tar.gz

cd php-5.2.17
patch -p1 < ../php-5.2.17-fpm-0.5.14.diff

./configure –prefix=/usr/local/php5 –with-iconv –with-zlib –enable-xml –enable-fastcgi –enable-fpm –with-curl –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-mhash –enable-sockets –with-xmlrpc –enable-zip –with-mysql –with-mysqli –enable-ftp –with-jpeg-dir –with-freetype-dir –with-png-dir –enable-bcmath –enable-calendar –enable-exif –with-openssl –with-bz2

make
make install

cp php.ini-dist /usr/local/php5/lib/php.ini

vi /usr/local/php5/etc/php-fpm.conf

去掉前面的注释

<value name=”user”>nobody</value>
<value name=”group”>nogroup</value>

ln -s /usr/local/php5/sbin/php-fpm /etc/init.d/php-fpm

/etc/init.d/php-fpm start

修改默认主机的配置:

vi /etc/nginx/conf.d/default.conf

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

注意:/usr/share/nginx/html$fastcgi_script_name; 前面的目录是默认主目录的位置,请根据你自己的实际情况修改,默认从nginx.org源安装的nginx最新版本,默认主目录

是/usr/share/nginx/html

/etc/init.d/nginx restart

好了,写个info文件,测试一下nginx+php+mysql是否完美结合了:)

四、安装ZendOptimizer

下载ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz,这是ZendOptimizer的最后一个版本了,也是shopex和ecshop能支持的ZendOptimizer,更高的版本是ZendGuardLoader,

但目前shopex等都不支持呀,非常让人纠结,要不今天我们也不会写这篇文章指导大家搭建合适的环境。

make /usr/local/zend
把解压后的so文件,拷贝到刚才建立的目录
vi /usr/local/php5/lib/php.ini
增加:
zend_extension= /usr/local/zend/ZendOptimizer.so

重启一下 php-fpm 应该马上生效了

自此,shopex或者ecshop的安装环境已经搭建成功。

后续:

五、加入memcache支持

aptitude install memcached

apt-get install m4 autoconf

wget http://pecl.php.net/get/memcache-2.2.6.tgz
tar zvxf memcache-2.2.6.tgz

cd memcache-2.2.6

/usr/local/php5/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

./configure –enable-memcache –with-php-config=/usr/local/php5/bin/php-config –with-zlib-dir
make
make install

Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/

修改php.ini
vi /usr/local/php5/lib/php.ini

增加下面4句

extension_dir = “/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/”
extension = memcache.so
memcache.chunk_size = 32768
memcache.hash_strategy = consistent

一般教程都是只加上面2句,建议把下面2句也加上,修改一下默认的一些参数,使memcache的使用性能更加有效率

六、加入eAccelerator支持

wget http://cdnetworks-kr-1.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip
unzip eaccelerator-0.9.6.1.zip
cd eaccelerator-0.9.6.1

/usr/local/php5/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php5/bin/php-config
make
make install

修改php.ini
vi /usr/local/php5/lib/php.ini

extension=”eaccelerator.so”
eaccelerator.shm_size=”32″
eaccelerator.cache_dir=”/var/cache/eaccelerator”
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.session = “disk_only”
eaccelerator.content = “disk_only”

保存

make /var/cache/eaccelerator
chmod -R 777 /var/cache/eaccelerator

因为之前安装memcache,已经加了extension_dir = “/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/”,所以安装eaccelerator就不加这句了,如果实际操作

中没装memcache,那就需要在php.ini中加入这句,或者直接指定eaccelerator.so的绝对路径

重启一下 php-fpm 应该马上生效了

Written by zhangweibo

十二月 10th, 2011 at 5:03 上午

nginx编译错误解决

without comments

准备在我的debian 5上把nginx的升级到最新版,默认的版本实在有点老,但在编译过程中发现如下错误

 

./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module
 
make
然后出现如下错误:
 
make -f objs/Makefile
make[1]: Entering directory `/root/tmp/nginx-1.0.8'
cd /usr \
        && if [ -f Makefile ]; then make distclean; fi \
        && CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
        ./configure –disable-shared
/bin/sh: line 2: ./configure: No such file or directory
make[1]: *** [/usr/Makefile] Error 127
make[1]: Leaving directory `/root/tmp/nginx-1.0.8'
make: *** [build] Error 2
 
解决方法:
安装libpcre3-dev就行
apt-get install libpcre3-dev
 
然后再次编译没问题了

Written by zhangweibo

十二月 4th, 2011 at 4:25 下午

Posted in nginx

Tagged with ,

nginx的访问日志log用logrotate来做日志轮询

without comments

在vps上做网站,切记做好日志的轮询工作,如果你的访问量比较大的,如果不进行好的处理,长期积累,日志会撑爆你的vps空间容量,嘿嘿,本身我们的空间容量就有限。

早些年,都是用cronolog来做日志轮询,不过这个是为了方便在自己的服务器上统计访问速度,后来随着网站的访问量越来越大,发现站点统计比较耗费系统资源,所以索性都交给了google或者百度进行网站统计,毕竟他们都是实时统计。

ok,那我们就用最简单的方法做一下nginx的日志轮询处理,哈哈,我就是个大懒人,能简单处理,绝不复杂化

默认logrotate其实已经对nginx做了轮询处理,只不过默认配置也会占用不少空间,如果你的小站访问量不大,那问题不大,如果访问量中等,建议把配置稍微改一下

/var/log/nginx/*.log {
daily
missingok
rotate 3
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
endscript
}

默认rotate 是52 有点太多了,天哪,得占用多少空间,我直接改成7,转存储7个文件就够了
然后默认是每天处理,我觉得不用改了

修改好以后,让新的配置生效
logrotate -f /etc/logrotate.conf

好了,vps爱好者们,基本你们不用愁日志会占满你们的空间了。

Written by zhangweibo

十二月 3rd, 2011 at 6:24 上午

Posted in nginx

Tagged with , ,

在nginx服务器上配置shopex的rewrite静态化重写规则

without comments

如果你的shopex建立在nginx服务器上,那rewrite重写规则如下,很简单的3行

 

if (!-e $request_filename) {
rewrite ^(.*)/(.+\.(html|xml|json|htm|php|jsp|asp|shtml))$ $1/index.php?$2 last;
}
大概意思,就是所有的访问链接都统一扔给index.php去处理静态化

Written by zhangweibo

十二月 2nd, 2011 at 2:42 下午

Posted in nginx,shopex

Tagged with , ,