lizongbo at 618119.com 工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC

2010年11月2日

Ubuntu10.04上编译安装php5.3.3和wordpress3.0.1

Filed under: Linux,mysql,nginx — 标签:, , , , , — lizongbo @ 20:46

Ubuntu10.04上编译安装php5.3.3和wordpress3.0.1

1.先下载php5.3.3的源代码:
root@618119.com:/usr/local/app# wget http://cn2.php.net/get/php-5.3.3.tar.gz/from/am.php.net/mirror
来源:http://www.php.net/downloads.php

2.解压php的源代码:
root@618119.com:/usr/local/app# tar -zxvf php-5.3.3.tar.gz

3.进入php源码目录:
准备编译:

./configure –prefix=/usr/local/app/php –enable-fastcgi –with-mysql=/usr/local/app/mysql –enable-zend-multibyte –with-config-file-path=/usr/local/app/php/conf –enable-discard-path –enable-force-cgi-redirect

提示:
configure: error: xml2-config not found. Please check your libxml2 installation

root@618119.com:/usr/local/app/php-5.3.3# sudo apt-get install libxml2-dev

4.make编译安装
root@618119.com:/usr/local/app/php-5.3.3# make
root@618119.com:/usr/local/app/php-5.3.3# make install

5.参考http://wiki.nginx.org/PHPFcgiExample 建立php-fcgi服务,
root@618119.com:/etc/init.d# vi php-fcgi
root@618119.com:/etc/init.d# chmod +x php-fcgi
root@618119.com:/etc/init.d# sudo /usr/sbin/update-rc.d -f php-fcgi defaults

php-fcgi的脚本如下:
root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# more /etc/init.d/php-fcgi
#!/bin/bash
BIND=127.0.0.1:9000
USER=root
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000

PHP_CGI=/usr/local/app/php/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS=”- USER=$USER PATH=/usr/local/app/php/bin PHP_FCGI_CHILDREN=$PHP_FC
GI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND”
RETVAL=0

start() {
echo -n “Starting PHP FastCGI: ”
start-stop-daemon –quiet –start –background –chuid “$USER” –exec /usr
/bin/env — $PHP_CGI_ARGS
RETVAL=$?
echo “$PHP_CGI_NAME.”
}
stop() {
echo -n “Stopping PHP FastCGI: ”
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo “$PHP_CGI_NAME.”
}

case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo “Usage: php-fastcgi {start|stop|restart}”
exit 1
;;
esac
exit $RETVAL

配置blog域名的虚拟主机:
root@618119.com:/usr/local/app/nginx# mkdir vhost
root@618119.com:/usr/local/app/nginx# cd vhost/
root@618119.com:/usr/local/app/nginx/vhost# mkdir blog.618119.com
root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# cd blog.618119.com/

下载wordpress最新3.0.1版程序
root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# wget http://wordpress.org/latest.tar.gz
来源: http://wordpress.org/download/
root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# tar -zxvf latest.tar.gz
root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# cp -r ./wordpress/* ./
root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# rm -rf wordpress/
下载wordpress的中文语言包:
root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# wget http://wpcn.googlecode.com/files/WordPress.v3.0.1.Simp.Chinese.Pack.Only.v1-wpcng.tar.gz
来源:http://code.google.com/p/wpcn/downloads/list
root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# tar -zxvf WordPress.v3.0.1.Simp.Chinese.Pack.Only.v1-wpcng.tar.gz
root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# cp -r ./wordpress/* ./
root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# rm -rf wordpress/

root@618119.com:/usr/local/app/nginx/vhost/blog.618119.com# vi ./wp-config.php

define (‘WPLANG’, ‘zh_CN’);

nginx.conf配置:

server {
server_name  blog.618119.com;
location / {
root   vhost/blog.618119.com;
index  index.html index.htm index.php;
}
}

参考:http://wiki.nginx.org/PHPFcgiExample

root@618119.com:/etc/init.d# service php-fcgi start

root@618119.com:/usr/local/app/nginx/conf# /usr/local/app/nginx/sbin/nginx -s reload

2009年04月6日

jsp拦截JspWriter实现类似php的ob_get_contents

Filed under: cache,Java — 标签:, , , , — lizongbo @ 22:29

jsp拦截JspWriter实现类似php的ob_get_contents
php可以通过ob_start和ob_get_contents可以拦截并得到echo等方式输出的内容,并可以方便的进行二次处理。java的jsp也是可以非常方便就实现这样的功能,那就是实现一个自定义的JspWriter.
oscache的功能强大的jsp缓存标签就是这样干的。
前段时间作了个简单的rss输出,由于避免访问量过大影响到数据库和接口调用。
于是需要对生成的rss文本进行缓存。原有的jsp代码都已经写好,大概动就太麻烦了,于是用TextJspWriter继承javax.servlet.jsp.JspWriter,然后在jsp作小改造就搞定了。
php的用法参考: http://cn2.php.net/ob_get_contents
TextJspWriter.java的代码为:
[code]

package com.lizongbo.util;

import java.io.IOException;
import java.io.StringWriter;

import javax.servlet.jsp.JspWriter;

public class TextJspWriter extends JspWriter {
public String getString() {
return sb.toString();
}

private StringBuilder sb = null;

public TextJspWriter() {
this(8192, true);
}

public TextJspWriter(int bufferSize, boolean autoFlush) {
super(bufferSize, autoFlush);
sb=new StringBuilder(bufferSize);
}

@Override
public void clear() throws IOException {
sb = new StringBuilder();

}

@Override
public void clearBuffer() throws IOException {
sb = new StringBuilder();

}

@Override
public void close() throws IOException {

}

@Override
public void flush() throws IOException {

}

@Override
public int getRemaining() {
return 0;
}

@Override
public void newLine() throws IOException {
sb.append(“\n”);

}

@Override
public void print(boolean arg0) throws IOException {
sb.append(arg0);

}

@Override
public void print(char arg0) throws IOException {
sb.append(arg0);

}

@Override
public void print(int arg0) throws IOException {
sb.append(arg0);

}

@Override
public void print(long arg0) throws IOException {
sb.append(arg0);

}

@Override
public void print(float arg0) throws IOException {
sb.append(arg0);

}

@Override
public void print(double arg0) throws IOException {
sb.append(arg0);

}

@Override
public void print(char[] arg0) throws IOException {
sb.append(arg0);

}

@Override
public void print(String arg0) throws IOException {
sb.append(arg0);

}

@Override
public void print(Object arg0) throws IOException {
sb.append(arg0);

}

@Override
public void println() throws IOException {
sb.append(“\n”);

}

@Override
public void println(boolean arg0) throws IOException {
sb.append(arg0);
println();

}

@Override
public void println(char arg0) throws IOException {
sb.append(arg0);
println();

}

@Override
public void println(int arg0) throws IOException {
sb.append(arg0);
println();

}

@Override
public void println(long arg0) throws IOException {
sb.append(arg0);
println();

}

@Override
public void println(float arg0) throws IOException {
sb.append(arg0);
println();

}

@Override
public void println(double arg0) throws IOException {
sb.append(arg0);
println();

}

@Override
public void println(char[] arg0) throws IOException {
sb.append(arg0);
println();

}

@Override
public void println(String arg0) throws IOException {
sb.append(arg0);
println();

}

@Override
public void println(Object arg0) throws IOException {
sb.append(arg0);
println();

}

@Override
public void write(char[] cbuf, int off, int len) throws IOException {
sb.append(cbuf, off, len);
}

}

[/code]

jsp代码:

[code]
《%//读取缓存
String textStr==rssTextCache.get(cacheKey);
if(textStr==null){
JspWriter oldout=out;
out= new com.lizongbo.util.TextJspWriter();
%》
《% //正常输出rss内容%》

《%
textStr=((com.lizongbo.util.TextJspWriter)out).getString();
out=oldout;//放入缓存中
rssTextCache.put(cacheKey,textStr);
}
%》
《%=textStr%》

[/code]

2009年01月10日

用rawurldecode和iconv解决php的编码问题

Filed under: 杂七杂八 — 标签:, , , — lizongbo @ 22:11

我在给wordpress加上记录Combined格式的时候,也加了个从referer里获取搜索关键字的功能(参考javaeye的“您正在搜索”加关键字高亮的功能)。
由于google的url里是标准的UTF-8编码,而百度的url里,一般却是GBK编码的。
当时实现这个功能的时候,导致rawurldecode只对google 的url得到了正确的汉字。
今天在网上重新搜索了相关信息,发现其实是有办法解决的。
解决的方法很简单,代码如下:
[code]
$lzb_searchkeyword=rawurldecode($lzb_searchkeywordstr);
$lzb_searchkeyword=iconv(“GBK”,”UTF-8″,$lzb_searchkeyword) ;//
通过这一行就把百度来的GBK汉字转成了UTF-8的,在页面上就可以正常显示了。
$lzb_searchurl=’http://www.baidu.com/s?wd=’.$lzb_searchkeywordstr;
[/code]

以后文章正文下方的recent related 1 searches的地方,基本不会再出现乱码了。

Older Posts »

Powered by WordPress