Ubuntu下安装淘宝开源Webserver tengine详细步骤教程

1、安装tengine之前需要安装PCRE库的安装

最新下载地址   ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

tar –zxvf pcre-8.21.tar.gz,解压目录为:pcre-8.21

然后进入到cd pcre-8.21,进行配置、编译、安装

安装zlib库安装

tar -zxvf zlib-1.2.5.tar.gz
cd zlib-1.2.5

./configure

make

makeinstall

安装openSSL库

下载页面:http://www.openssl.org/source/

tar –zxvf openssl-1.0.0.tar.gz,解压目录为:openssl-1.0.0

然后进入到cd openssl-1.0.0,进行配置、编译、安装

配置

./configure或./config

编译

make

安装

make install

2、安装 tengine

# cd /usr/local/src
# tar zxvf tengine-1.2.0.tar.gz
# cd tengine
# ./configure –prefix=/usr/local/nginx –conf-path=/usr/local/nginx/conf/nginx.conf –with-http_concat_module –with-http_realip_module –with-http_addition_module –with-http_gzip_static_module –with-http_random_index_module –with-http_stub_status_module –with-openssl=/usr/ –with-http_sub_module –with-http_dav_module –with-pcre=/usr/local/src/pcre-8.21
注意:–with-pcre=/usr/local/src/pcre-8.13指向的是源码包解压的路径,而不是安装的路径,否则会报错。
# make
# make install
# /usr/local/nginx/sbin/nginx   #启动
# chown nobody.nobody -R /usr/local/nginx/html
# chmod 700 -R /usr/local/nginx/html
设置tengine开启启动
vi /etc/rc.d/init.d/nginx  #编辑启动文件添加下面内容
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: – 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it’s not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog=”nginx”
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo “nginx already running….”
exit 1
fi
echo -n $”Starting $prog: “
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $”Stopping $prog: “
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $”Reloading $prog: “
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case “$1″ in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $”Usage: $prog {start|stop|restart|reload|status|help}”
exit 1
esac
exit $RETVAL
保存退出
# chmod 775 /etc/rc.d/init.d/nginx   #赋予文件执行权限
# chkconfig nginx on   #设置开机启动
# /etc/rc.d/init.d/nginx restart
# service nginx restart

教程:Amazon EC2/Ubuntu系统下搭建PPTP VPN环境

以下是基于Amazon EC2/Ubuntu搭建PPTPD服务提供VPN连接的过程记录。至于为什么要搞VPN,大家都懂的。。。而我主要是要访问Python的一些网站以及使用我非常喜欢的Google docs。

PPTP采用TCP 1723端口,因此在Amazon EC2的防火墙配置中,必须打开这个端口,否则client端无法接入。(网上有文章说也需要打开47端口(GRE端口),我在Amazon EC2上试验的结论是不需要特别设置。)

step1: 安装pptpd

很简单的命令:sudo apt-get install pptpd

step2: 修改pptpd的配置

有三个文件需要修改:

(1)修改/etc/pptpd.conf,添加以下内容(原文件中可能已经有这些内容,确认即可)

localip 192.168.0.1

remoteip 192.168.0.100-110

localip是指VPN建立后,client可以用这个地址访问VPN server。

remoteip就是指分配给client的地址。

(2)修改/etc/ppp/pptpd-options文件,增加以下内容:

ms-dns 8.8.8.8

ms-dns 8.8.4.4

这个配置是使用Google的DNS解析。至于原因,你也懂的。。。

(3)修改/etc/ppp/chap-secrets文件,设置客户机登录的帐号和密码:

# client server secret IP addresses

hilinux * 1234 *

“client”是用户名,“server”是服务器地址,”secret”是登录密码,”IP addresses”是分配的地址,如果指定*,则由系统自动分配。

step3: 重起PPTPD服务:sudo service pptpd restart

step4:配置IP转发

修改/etc/sysctl.conf文件,打开以下的注释:

net.ipv4.ip_forward=1

step5: 重新加载IP转发配置

sudo sysctl -p

step6: 修改Iptables,设置网络地址翻译

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

上述设置在重起后悔丢失,因此需要修改 /etc/rc.local文件, 在exit 0之前添加以下语句:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

step7: 配置DDNS

Amazon EC2每次重起都会变换地址,因此我们需要配置DDNS来获取动态域名解析。在这一步之前,需要在DynDNS上申请一个免费的域名。国内类似的服务商是“花生壳”,我没有进行过测试,不知道“花生壳”是否也适合以下配置。

申请到DynDNS帐号后,下载并安装ddclient:

sudo apt-get install ddclient

安装过程中, 会有简单的界面进行配置, 设置dyndns的相关帐户即可。设置完成后, 配置信息会自动写入/etc/ddclient.conf文件。

完成上述步骤后,就可以在windows客户端拨号建立VPN连接了。

教程php更改目录及子目录下所有的文件后缀

今天遇到要改变当前目录下指定类型的文件类型,本来想要用批处理来做这个,结果没找到合适。就自己去查了下资料,用Php来处理一下。

不是很经常处理文件,所以对遍历目录还不是很熟悉,找了一下资料,自己修改一下。

让大家看看是否需要完善的

代码主要的目的是 批量更改 文件后缀 由于淘宝数据包图片类型的不同 所以要改一下适合的。 (全文…)

PHP MemCached高级缓存配置

1.Memcache相关介绍

memcache是一个高性能的分布式的内存对象缓存系统,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。

使用Memcache的网站一般流量都是比较大的,为了缓解数据库的压力,让Memcache作为一个缓存区域,把部分信息保存在内存中,在前端能够迅速的进行存取。 (全文…)

ubuntu 编译安装php 5.3.3+memcache

//编译安装php 5.3.3

由于php5.3.X已经自带了php-fpm所以不需要打补丁

# sudo ./configure  –prefix=/usr/local/php-5.3.3 –with-mcrypt –with-gettext –with-mysql –with-gd –with-jpeg-dir –with-png-dir –with-curl –with-freetype-dir –enable-gd-native-ttf –enable-mbstring –enable-sockets –with-png-dir –with-pdo-mysql –enable-fpm –with-zlib –with-fpm-user=daemon –with-fpm-group=daemon
#  sudo rm -rf /usr/local/php-5.3.3
#  sudo make
#  sudo make install

//编译安装 memcache

sudo /usr/local/php-5.3.3/bin/phpize

sudo ./configure –with-php-config=/usr/local/php-5.3.3/bin/php-config

//修改php.ini配置文件

添加:

extension_dir = “/usr/local/php-5.3.3/lib/php/extensions/no-debug-non-zts-20090626/”

extension=memcache.so

PHP MemCached 高级缓存应用

Memcache常用方法

Memcache::add — 添加一个值,如果已经存在,则返回false
Memcache::addServer — 添加一个可供使用的服务器地址
Memcache::close — 关闭一个Memcache对象
Memcache::connect — 创建一个Memcache对象
Memcache::debug — 控制调试功能
Memcache::decrement — 对保存的某个key中的值进行减法操作
Memcache::delete — 删除一个key值
Memcache::flush — 清除所有缓存的数据
Memcache::get — 获取一个key值
Memcache::getExtendedStats — 获取进程池中所有进程的运行系统统计
Memcache::getServerStatus — 获取运行服务器的参数
Memcache::getStats — 返回服务器的一些运行统计信息
Memcache::getVersion — 返回运行的Memcache的版本信息
Memcache::increment — 对保存的某个key中的值进行加法操作
Memcache::pconnect — 创建一个Memcache的持久连接对象
Memcache::replace — R对一个已有的key进行覆写操作
Memcache::set — 添加一个值,如果已经存在,则覆写
Memcache::setCompressThreshold — 对大于某一大小的数据进行压缩
Memcache::setServerParams — 在运行时修改服务器的参数

Memcache方法使用

1 <?php
2  $memcache = new memcache;
3  $memcache->connect(‘127.0.0.1′, 11211) or die(“连接失败”);
4  $memcache->set(‘name’, ‘张三’);
5 $val = $memcache->get(‘name’);
6 ?>

注:set方法的完整版本,set(键名,键值,是否压缩,保持时间)

1 <?php
2 $memcache = new memcache;
3 $memcache -> connect(‘127.0.0.1′, 11211) or die(“连接失败”);
4 $memcache -> set(‘name’, array(‘一个’,'两个’));
5 $val = $memcache->get(‘name’);
6 print_r($val);
7 $memcache -> close();
8 ?>

php 如何清空字符串中的HTML标签过滤Html

要过滤字符串中所有的html标签有两种方法一种是我们自己写一个函数,用正则过滤,一个是用php自带函数strip_tags哦。
function clear_html_label($html)
{
$search = array (“‘<script[^>]*?>.*?</script>’si”, “‘<[/!]*?[^<>]*?>’si”, “‘([rn])[s]+’”, “‘&(quot|#34);’i”, “‘&(amp|#38);’i”, “‘&(lt|#60);’i”, “‘&(gt|#62);’i”, “‘&(nbsp|#160);’i”, “‘&(iexcl|#161);’i”, “‘&(cent|#162);’i”, “‘&(pound|#163);’i”, “‘&(copy|#169);’i”, “‘&#(d+);’e”);
$replace = array (“”, “”, “1″, “”", “&”, “<”, “>”, ” “, chr(161), chr(162), chr(163), chr(169), “chr(1)”);
return preg_replace($search, $replace, $html);
}
//实例应用
$string =’aaa<br /> <script>fdsafsa’;
echo clear_html_label($string);//aaa fdsafsa
//利用php自带函数strip_tags();
echo strip_tags($string);//aaa fdsafsa
总结,
上面二个函数得出的结果完全相同,一个是用户自定义的过滤所有html函数,一个是php内置函数,但在效绿上来说php的strip_tags()函数,肯定要高很多。至少为什么我就不说多了。
php 如何清空字符串中的HTML标签

要过滤字符串中所有的html标签有两种方法一种是我们自己写一个函数,用正则过滤,一个是用php自带函数strip_tags哦。 function clear_html_label($html) {  $search = array (“‘<script[^>]*?>.*?</script>’si”, “‘<[/!]*?[^<>]*?>’si”, “‘([rn])[s]+’”, “‘&(quot|#34);’i”, “‘&(amp|#38);’i”, “‘&(lt|#60);’i”, “‘&(gt|#62);’i”, “‘&(nbsp|#160);’i”, “‘&(iexcl|#161);’i”, “‘&(cent|#162);’i”, “‘&(pound|#163);’i”, “‘&(copy|#169);’i”, “‘&#(d+);’e”);      $replace = array (“”, “”, “1″, “”", “&”, “<”, “>”, ” “, chr(161), chr(162), chr(163), chr(169), “chr(1)”);      return preg_replace($search, $replace, $html); }  //实例应用 $string =’aaa<br /> <script>fdsafsa’; echo clear_html_label($string);//aaa fdsafsa  //利用php自带函数strip_tags(); echo strip_tags($string);//aaa fdsafsa  总结, 上面二个函数得出的结果完全相同,一个是用户自定义的过滤所有html函数,一个是php内置函数,但在效绿上来说php的strip_tags()函数,肯定要高很多。至少为什么我就不说多了。php 如何清空字符串中的HTML标签

PHP获取表单textarea数据中的换行问题

闲来无事,在网上看到一篇关于php表单转换textarea换行符的文章,看完后,根据以往经验,感觉上这篇文章中的一些信息并不准确…于是便自己亲自对php获取表单数据中的换行符问题进行研究:
测试页面代码:

闲来无事,在网上看到一篇关于php表单转换textarea换行符的文章,看完后,根据以往经验,感觉上这篇文章中的一些信息并不准确…于是便自己亲自对php获取表单数据中的换行符问题进行研究:测试页面代码: (全文…)

PHP解压网页GZIP 函数

现在很多网页都是GZIP压缩的,如果用PHP取过来发现是一堆乱码,可以用GZIP函数类解压,但有时候PHP编译没编译GZIP
可用下面函数代替:
<?php
if (!function_exists ( ‘gzdecode’ )) {
$flags = ord ( substr ( $data, 3, 1 ) );
$headerlen = 10;
$extralen = 0;
$filenamelen = 0;
if ($flags & 4) {
$extralen = unpack ( ‘v’, substr ( $data, 10, 2 ) );
$extralen = $extralen [1];
$headerlen += 2 + $extralen;
}
if ($flags & 8) // Filename
$headerlen = strpos ( $data, chr ( 0 ), $headerlen ) + 1;
if ($flags & 16) // Comment
$headerlen = strpos ( $data, chr ( 0 ), $headerlen ) + 1;
if ($flags & 2) // CRC at end of file
$headerlen += 2;
$unpacked = @gzinflate ( substr ( $data, $headerlen ) );
if ($unpacked === FALSE)
$unpacked = $data;
return $unpacked;
}

现在很多网页都是GZIP压缩的,如果用PHP取过来发现是一堆乱码,可以用GZIP函数类解压,但有时候PHP编译没编译GZIP可用下面函数代替:<?phpif (!function_exists ( ‘gzdecode’ )) { $flags = ord ( substr ( $data, 3, 1 ) ); $headerlen = 10; $extralen = 0; $filenamelen = 0; if ($flags & 4) { $extralen = unpack ( ‘v’, substr ( $data, 10, 2 ) ); $extralen = $extralen [1]; $headerlen += 2 + $extralen; } if ($flags & 8) // Filename  $headerlen = strpos ( $data, chr ( 0 ), $headerlen ) + 1; if ($flags & 16) // Comment  $headerlen = strpos ( $data, chr ( 0 ), $headerlen ) + 1; if ($flags & 2) // CRC at end of file  $headerlen += 2; $unpacked = @gzinflate ( substr ( $data, $headerlen ) ); if ($unpacked === FALSE) $unpacked = $data; return $unpacked;}

CentOS 5.5 使用yum来安装 LAMP (Apache+Mysql+php5)

今天用yum方法搭建起了个LAMP环境,中间遇到了很多问题,经过google和各位前辈的帮助,终于将环境搭建起来,现在把完整的步骤记录下来,
1.  换源,sohu的相当好用。
1.1备份CentOS-Base.repo
cd /etc/yum.repos.d/
cp CentOS-Base.repo CentOS-Base.repo.bak
(全文…)