Zend_Paginator分页代码

Standard

Models
Book.php

class Book extends Zend_Db_Table {
  ...
}

Controllers
IndexController.php

class IndexController extends Zend_Controller_Action {
 
  function init() {
    $this->initView();
    //set baseUrl
    $this->view->baseUrl = $this->_request->getBaseUrl();
  }
 
  function indexAction() {
    $this->view->title = "Title";
    $book = new Book();
    $this->view->books = $book->index();
 
    $pageNumber = 2;
    $paginator = Zend_Paginator::factory($this->view->books);
    $paginator->setItemCountPerPage($pageNumber);
    $paginator->setCurrentPageNumber($this->_getParam('page'));
    Zend_Paginator::setDefaultScrollingStyle('Sliding');
    $paginator->setView($this->view);
 
    $this->view->books = $paginator;
 
    $this->view->paginator = $paginator;
 
    $this->render();
  }
}

Views
views\scripts\index\index.phtml

<?php foreach ($this->books as $item) {?>
<ul id='ul_<?php echo $this->escape($item->id) ?>'>
  <li>
  <table width="100%"><tr><td width="60%">[<?php echo $this->escape($item->username) ?>]</b> Create by:<?php echo $this->escape($item->pubdate) ?></td><td align="right"><a href="<?php echo $this->baseUrl ?>/index/add/id/<?php echo $item->id ?>?height=280&width=280" class="thickbox" title="Edit">EDIT</a> <a href="#" id="del_<?php echo $this->escape($item->id) ?>" class="del">DEL</a></td></tr></table>
  </li>
  <li class="bottom"><?php echo nl2br($this->escape($item->content)) ?></li>
</ul>
<?php } ?>
<ul>
  <li>
  <?php echo $this->paginationControl($this->paginator, 'Elastic', 'pagelist.phtml'); ?>
  </li>
</ul>

views\scripts\pagelist.phtml

<?php if ($this->pageCount): ?>
<!-- yemaosheng.com -->
<div class="paginationControl">
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
   <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'index', 'page'=>$this->previous)); ?>">< 上一页</a> |
<?php else: ?>
   <span class="disabled">< 上一页</span> |
<?php endif; ?>
<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
  <?php if ($page != $this->current): ?>
     <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'index', 'page'=>$page)); ?>"><?= $page; ?></a> |
  <?php else: ?>
    <?= $page; ?> |
  <?php endif; ?>
<?php endforeach; ?>
<!-- Next page link -->
<?php if (isset($this->next)): ?>
   <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'index', 'page'=>$this->next)); ?>">下一页 ></a>
<?php else: ?>
   <span class="disabled">下一页 ></span>
<?php endif; ?>
</div>
<?php endif; ?>

转载请写明出处: http://yemaosheng.com

ZendFramework zend_form登录验证码

Standard
<?php
class LoginForm extends Zend_Form
{
    public function init()
    {
        $username = $this->addElement('text', 'username', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                'Alpha',
                array('StringLength', false, array(3, 20)),
            ),
            'required'   => true,
            'label'      => '用户名:',
        ));
 
        $password = $this->addElement('password', 'password', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                'Alnum',
                array('StringLength', false, array(6, 20)),
            ),
            'required'   => true,
            'label'      => '密 码:',
        ));
 
        $captcha = $this->addElement('captcha', 'captcha', array(
            'captcha' =>  array(  
                // First the type...  
                'captcha' => 'Image',
                // Length of the word...  
                'wordLen' => 6,
                'fontsize'=>16,
                'width' => 100,
                'height' => 38,
                'dotNoiseLevel'=>2,
                // Captcha timeout, 5 mins  
                'timeout' => 300,  
                // What font to use...  
                'font' => $_SERVER["DOCUMENT_ROOT"].'/webapp/views/scripts/arial.ttf',  
                // Where to put the image  
                'imgDir' => $_SERVER["DOCUMENT_ROOT"].'/webroot/images/',  
                // URL to the images  
                // This was bogus, here's how it should be... Sorry again :S  
                'imgUrl' => 'http://yemaosheng.com/webroot/images/',
            ),
            'label' => '验证码:'
        ));
 
        $login = $this->addElement('submit', 'login', array(
            'required' => false,
            'ignore'   => true,
            'label'    => '登录',
        ));
 
        // We want to display a 'failed authentication' message if necessary;
        // we'll do that with the form 'description', so we need to add that
        // decorator.
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')),
            array('Description', array('placement' => 'prepend')),
            'Form'
        ));
    }
}
?>
<?php
public function loginAction() {
 
	$request = $this->getRequest();
 
        if (!$request->isPost()) {
            return $this->_helper->redirector('index');
        }
 
	/* 用$form->isValid的话这一段可以不用
	// Get out from the $_POST array the captcha part...
	$captcha = $request->getPost('captcha');
	// Actually it's an array, so both the ID and the submitted word
	// is in it with the corresponding keys
	// So here's the ID...
	$captchaId = $captcha['id'];
	// And here's the user submitted word...
	$captchaInput = $captcha['input'];
	// We are accessing the session with the corresponding namespace
	// Try overwriting this, hah!
	$captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_'.$captchaId);
	// To access what's inside the session, we need the Iterator
	// So we get one...
	$captchaIterator = $captchaSession->getIterator();
	// And here's the correct word which is on the image...
	$captchaWord = $captchaIterator['word'];
	// Now just compare them...
	if($captchaInput != $captchaWord){
		echo "验证码Error";
		exit;
	} 
	*/
 
        $form = $this->getForm();
        if (!$form->isValid($request->getPost())) {
            // Invalid entries
            $this->view->form = $form;
            return $this->render('index'); // re-render the login form
        }
}
public function getForm()
{
	return new LoginForm(array(
            'action' => '/user/login',
            'method' => 'post',
	));
}
?>

编译安装LAMP+SVN+Trac+Memcached

Standard
##
## 转载请注明出处: http://yemaosheng.com
##
 
## 环境:Dell1950  CentOS5.3 x86
 
## 新建软件安装目录
 
mkdir /home/lib
mkdir /home/apache
mkdir /home/mysql
mkdir /home/memcached
mkdir /home/php
mkdir /home/svn
mkdir /home/trac
 
## 安装依赖包
 
# gettext-devel
yum install -y gettext-devel.x86_64
 
# zlib
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/home/lib/zlib
make
make install
cd ..
 
# openssl
tar zxvf openssl-0.9.8g.tar.gz
cd openssl-0.9.8g
./config \
	--prefix=/home/lib/openssl \
	--openssldir=/home/lib/openssl \
	--with-zlib-lib=/home/lib/zlib/lib \
	--with-zlib-include=/home/lib/zlib/include \
	shared \
	zlib \
	threads 
make
make test
make install
echo "/home/lib/openssl/lib" >> /etc/ld.so.conf.d/openssl.conf
ldconfig
cd ..
 
# apr
tar zxvf apr-1.3.5.tar.gz
cd apr-1.3.5
./configure --prefix=/home/lib/apr
make
make install
cd ..
 
# apr-util
tar zxvf apr-util-1.3.7.tar.gz
cd apr-util-1.3.7
./configure \
	--prefix=/home/lib/apr-util \
	--with-apr=/home/lib/apr
make
make install
cd ..
 
## 安装Apache
 
rm -rf /usr/lib/libexpat.so
ln -s /usr/lib64/libexpat.so /usr/lib/
tar zxvf httpd-2.2.11.tar.gz
cd httpd-2.2.11
./configure \
	--prefix=/home/apache \
	--enable-track-vars \
	--enable-rewrite \
	--enable-proxy \
	--enable-proxy-http  \
	--enable-cache \
	--enable-disk-cache \
	--enable-mem-cache \
	--enable-so \
	--enable-ssl \
	--enable-mods-shared=all \
	--enable-rewrite=shared \
	--enable-proxy=shared \
	--enable-proxy-http=shared \
	--with-mpm=worker \
	--sysconfdir=/home/apache/conf \
	--with-ssl=/home/lib/openssl \
	--with-z-dir=/home/lib/zlib \
	--with-apr=/home/lib/apr \
	--with-apr-util=/home/lib/apr-util \
	--with-perl 
make 
make install
cd ..
 
mv /etc/init.d/httpd /etc/init.d/httpd.bak
cp /home/apache/bin/apachectl /etc/init.d/httpd
chmod +x /etc/init.d/httpd
 
## 安装依赖包
 
# icon
tar zxvf libiconv-1.12.tar.gz
cd libiconv-1.12
./configure --prefix=/home/lib/iconv
make
make install
cd ..
 
# libpng
tar jxvf libpng-1.2.23.tar.bz2   
cd libpng-1.2.23
env \
	CPPFLAGS="-I/home/lib/zlib/include" \
	LDFLAGS="-L/home/lib/zlib/lib" \
	./configure \
	--prefix=/home/lib/libpng
make
make check 
make install
cd ..
 
# curl
tar zxvf curl-7.19.5.tar.gz
cd curl-7.19.5
./configure --prefix=/home/lib/curl
make
make install
cd ..
 
# freetype
tar jxvf freetype-2.3.5.tar.bz2 
cd freetype-2.3.5
env \
	CPPFLAGS="-I/home/lib/zlib/include" \
	LDFLAGS="-L/home/lib/zlib/lib" \
	./configure \
	--prefix=/home/lib/freetype2
make
make install
cd ..
 
# jpeg
mkdir -p \
	/home/lib/jpeg6/bin \
	/home/lib/jpeg6/lib \
	/home/lib/jpeg6/include \
	/home/lib/jpeg6/man1 \
	/home/lib/jpeg6/man/man1 
 
tar zxvf jpegsrc.v6b.tar.gz    
cd jpeg-6b
./configure \
	--prefix=/home/lib/jpeg6 \
	--enable-shared --enable-static
make
make install-lib  
make install
cd ..
 
# libxml
tar -zxvf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30
./configure \
	--prefix=/home/lib/libxml2 \
	--with-zlib=/home/lib/zlib
make
make install
cd ..
 
# gd
tar -jvxf gd-2.0.35.tar.bz2
cd gd-2.0.35 
./configure \
	--prefix=/home/lib/gd2 \
	--with-freetype=/home/lib/freetype2 \
	--with-png=/home/lib/libpng \
	--with-jpeg=/home/lib/jpeg6 \
	CPPFLAGS="-I/home/lib/zlib/include" \
	LDFLAGS="-L/home/lib/zlib/lib"
make
make install 
cd ..
 
## 安装Mysql
 
groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.1.34.tar.gz
cd mysql-5.1.34
./configure \
	--prefix=/home/mysql \
	--enable-assembler \
	--without-debug \
	--with-mysqld-ldflags=-all-static \
	--with-charset=utf8 \
	--with-extra-charsets=all \
	--with-innodb \
	--with-unix-socket-path=/home/mysql/mysql.sock \
	--enable-thread-safe-client \
	--with-mysqld-user=mysql
make
make install
cd ..
cp /home/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld 
if [ -f my.cnf.slave ]; then mv my.cnf.slave /etc/my.cnf; else mv my.cnf.mast /etc/my.cnf; fi; mkdir -p /data/mysqllog/binlog /data/mysqllog/relaylog ; chown mysql.0 /data/mysqllog/binlog /data/mysqllog/relaylog  /home/mysql; cp /home/mysql/share/mysql/mysql.server /etc/init.d/mysqld ; /home/mysql/bin/mysql_install_db --user=mysql; /etc/init.d/mysqld start
 
## 安装PHP
 
tar zxvf php-5.2.9.tar.gz
cd php-5.2.9
./configure \
	--prefix=/home/php \
	--with-zlib=/home/lib/zlib \
	--with-zlib-dir=/home/lib/zlib \
	--with-apxs2=/home/apache/bin/apxs \
	--with-mysql=/home/mysql \
	--with-mysql-sock=/home/mysql \
	--with-pdo-mysql=/home/mysql \
	--with-libxml-dir=/home/lib/libxml2 \
	--with-gd=/home/lib/gd2 \
	--with-jpeg-dir=/home/lib/jpeg6 \
	--with-png-dir=/home/lib/libpng \
	--with-freetype-dir=/home/lib/freetype2 \
	--with-libxml-dir=/home/lib/libxml2 \
	--with-openssl=/home/lib/openssl \
	--with-iconv-dir=/home/lib/iconv \
	--with-curl=/home/lib/curl \
	--with-ttf \
	--with-gettext \
	--enable-gd-native-ttf \
	--enable-mbstring \
	--enable-xml \
	--enable-pcntl \
	--enable-soap \
	--enable-sockets \
	--enable-zip \
	--with-bz2 \
	--disable-debug 
 
make
make install
cp php.ini-dist /home/php/lib/php.ini 
cd ..
 
## 安装PHP扩展
 
# memcached
tar zxvf memcache-2.2.1.tgz
cd memcache-2.2.1
/home/php/bin/phpize
./configure --with-php-config=/home/php/bin/php-config --enable-memcach
make 
make install
cd ..
 
# APC
tar zxvf APC-3.0.19.tgz 
cd APC-3.0.19
/home/php/bin/phpize
./configure --enable-apc --enable-apc-mmap --with-apxs=/home/apache/bin/apxs --with-php-config=/home/php/bin/php-config 
make
make install
cd ..
 
# xdebug
tar zxvf xdebug-2.0.4.tgz
cd xdebug-2.0.4
/home/php/bin/phpize
./configure --enable-xdebug --with-php-config=/home/php/bin/php-config
make
make install
cd ..
 
sed -i 's#extension_dir = "./"#extension_dir = "/home/php/lib/php/extensions/no-debug-zts-20060613/"\n\nextension = "memcache.so"\nextension = "apc.so"\nextension = "xdebug.so"#' /home/php/lib/php.ini
sed -i 's#expose_php = On#expose_php = Off#' /home/php/lib/php.ini
 
#xdebug.auto_trace=on 监测函数调用过程
#xdebug.collect_params=on 收集函数参数
#xdebug.collect_return=on 收集函数返回值
#xdebug.profiler_enable=on 效能监测器
#xdebug.trace_output_dir="/tmp" 函数调用监测信息的输出文件的路径
#debug.profiler_output_dir="/tmp" 效能监测信息输出文件的路径
#sed -i 's#extension = "xdebug.so"#xdebug.auto_trace=on\nxdebug.collect_params=on\nxdebug.collect_return=on\nxdebug.profiler_enable=on\nxdebug.trace_output_dir="/tmp"\ndebug.profiler_output_dir="/tmp"#' /home/php/lib/php.ini
 
 
sed -i 's#DirectoryIndex index.html#DirectoryIndex index.html index.php#' /home/apache/conf/httpd.conf
sed -i 's#TypesConfig conf/mime.types#TypesConfig conf/mime.types\nAddType application/x-httpd-php .php#' /home/apache/conf/httpd.conf
 
tar zxvf phpmyadmin.tar.gz
mv phpmyadmin /home/apache/htdocs/
 
## 安装memcached
tar zxvf libevent-1.4.10-stable.tar.gz 
cd libevent-1.4.10-stable
./configure --prefix=/home/lib/libevent
make
make install
cd ..
 
tar zxvf memcached-1.2.8.tar.gz
cd memcached-1.2.8
./configure \
	--prefix=/home/memcached \
	--with-libevent=/home/lib/libevent \
	--enable-64bit
make
make install
ln -s /home/lib/libevent/lib/libevent-1.4.so.2 /usr/lib64/libevent-1.4.so.2
/home/memcached/bin/memcached -l 127.0.0.1 -d -p 11211 -u nobody -m 128
cd ..
 
## 安装SVN
tar zxvf subversion-1.6.2.tar.gz
tar zxvf subversion-deps-1.6.2.tar.gz
tar zxvf sqlite-amalgamation-3.6.14.2.tar.gz
 
cd subversion-1.6.2
./configure \
	--prefix=/home/svn \
	--with-apxs=/home/apache/bin/apxs \
	--enable-maintainer-mode
 
make
make install
 
make swig-py
make install-swig-py 
 
cd ..
 
echo /home/svn/lib/svn-python > /usr/lib/python2.4/site-packages/subversion.pth
 
# Create SVN Repo
mkdir /srv/svn
mkdir /srv/trac
 
/home/svn/bin/svnadmin create /srv/svn/project
 
touch /srv/svn/project.htpasswd
htpasswd -m /srv/svn/project.htpasswd svnroot
echo -e "<Location /svn>\nDAV svn\nSVNParentPath /srv/svn\nAuthType Basic\nAuthName \"project Repository\"\nAuthzSVNAccessFile /srv/svn/svn-acl-conf\nAuthUserFile /srv/svn/project.htpasswd\nRequire valid-user\n</Location>" >> /home/apache/conf/httpd.conf
echo -e "[project:/]\nsvnroot =  rw" >> /srv/svn/svn-acl-conf
 
## 安装Trac
yum install flex
tar zxvf mod_python-3.3.1.tgz
cd mod_python-3.3.1
./configure \
	--with-apxs=/home/apache/bin/apxs \
	--with-python=/usr/bin/python2.4 \
	--with-max-locks=32
make
make install_dso
make install_py_lib
cd ..
 
yum install -y python-setuptools
rpm -i clearsilver-0.10.4-1.el5.rf.i386.rpm
rpm -i python-clearsilver-0.10.4-1.el5.rf.i386.rpm
 
tar zxvf Trac-0.11.4.tar.gz
cd Trac-0.11.4
python setup.py build && python setup.py install
 
# vi /home/apache/conf/httpd.conf
# Add: LoadModule python_module modules/mod_python.so
 
trac-admin /srv/trac/project initenv
sed -i 's#php_path = php#php_path = /home/php/bin/php#' /srv/trac/project/conf/trac.ini
# vi /srv/trac/project/conf/trac.ini 在 [mimeviewer] 后加上 pygments_default_style = trac 修改[trac] default_charset = utf-8
 
chown -R apache.apache /srv/svn/project
chown -R apache.apache /srv/trac/project
 
# 生成trac的用户名密码
touch /srv/trac/project.htpasswd
htpasswd -m /srv/trac/project.htpasswd tracroot
# 生成tracroot用户的权限
trac-admin /srv/trac/project permission add tracroot TRAC_ADMIN
 
echo -e "<Location /trac/project>\nSetHandler mod_python\nPythonHandler trac.web.modpython_frontend\nPythonOption TracEnv /srv/trac/project\nPythonOption TracUriRoot /trac/project\n</Location>\n<Location "/trac/project/login">\nAuthType Basic\nAuthName \"trac\"\nAuthUserFile /srv/trac/project.htpasswd\nRequire valid-user\n</Location>" >> /home/apache/conf/httpd.conf
 
/etc/init.d/httpd restart
 
## OK
 
http://127.0.0.1/svn/project
http://127.0.0.1/trac/project
memcached: telnet 127.0.0.1 11211
 
/home/lib (关联库)
/home/apache  (2.2.11)
/home/mysql  (5.1.34)
/home/php  (5.2.9)
/home/memcached  (1.2.8)
/home/svn  (1.6.2)
/home/trac  (0.11.4)

apache2.2.6+php5.2.9+mysql5.1.34编译安装

Standard
rpm -ivh gettext-devel-0.14.1-13.x86_64.rpm
 
# zlib
tar -zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/usr/local/zlib
make
make install
cd ..
 
# openssl
tar -zxvf openssl-0.9.8g.tar.gz
cd openssl-0.9.8g
./config \
	--prefix=/usr/local/openssl \
	--openssldir=/usr/local/openssl \
	--with-zlib-lib=/usr/local/zlib/lib \
	--with-zlib-include=/usr/local/zlib/include \
	shared \
	zlib \
	threads 
make
make test
make install
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf.d/openssl.conf
ldconfig
cd ..
 
# http
tar jxvf httpd-2.2.6.tar.bz2
cd httpd-2.2.6
./configure \
	--prefix=/usr/local/apache \
	--enable-track-vars \
	--enable-rewrite \
	--enable-proxy \
	--enable-proxy-http  \
	--enable-cache \
	--enable-disk-cache \
	--enable-mem-cache \
	--enable-so \
	--enable-ssl \
	--enable-mods-shared="cache disk_cache mem_cache" \
	--enable-rewrite=shared \
	--enable-proxy=shared \
	--enable-proxy-http=shared \
	--with-mpm=worker \
	--sysconfdir=/usr/local/apache/conf \
	--with-ssl=/usr/local/openssl \
	--with-z-dir=/usr/local/zlib \
	--with-perl 
make 
make install
cd ..
 
# DirectoryIndex index.php
# AddType application/x-httpd-php .php
# LoadModule php5_module        modules/libphp5.so
 
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
chmod +x /etc/init.d/httpd
 
# icon
tar zxvf libiconv-1.12.tar.gz
cd libiconv-1.12
./configure --prefix=/usr/local/iconv
make
make install
cd ..
 
# libpng
tar jxvf libpng-1.2.23.tar.bz2   
cd libpng-1.2.23
env \
	CPPFLAGS="-I/usr/local/zlib/include" \
	LDFLAGS="-L/usr/local/zlib/lib" \
	./configure \
	--prefix=/usr/local/libpng
make
make check 
make install
cd ..
 
# freetype
tar jxvf freetype-2.3.5.tar.bz2 
cd freetype-2.3.5
env \
	CPPFLAGS="-I/usr/local/zlib/include" \
	LDFLAGS="-L/usr/local/zlib/lib" \
	./configure \
	--prefix=/usr/local/freetype2
make
make install
cd ..
 
# jpeg
mkdir -p \
	/usr/local/jpeg6/bin \
	/usr/local/jpeg6/lib \
	/usr/local/jpeg6/include \
	/usr/local/jpeg6/man1 \
	/usr/local/jpeg6/man/man1 
 
tar zxvf jpegsrc.v6b.tar.gz    
cd jpeg-6b
./configure \
	--prefix=/usr/local/jpeg6 \
	--enable-shared --enable-static
make
make install-lib  
make install
cd ..
 
# libxml
tar -zxf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30
./configure \
	--prefix=/usr/local/libxml2 \
	--with-zlib=/usr/local/zlib
make
make install
cd ..
 
# gd
tar -jvxf gd-2.0.35.tar.bz2
cd gd-2.0.35 
./configure \
	--prefix=/usr/local/gd2 \
	--with-freetype=/usr/local/freetype2 \
	--with-png=/usr/local/libpng \
	--with-jpeg=/usr/local/jpeg6 \
	CPPFLAGS="-I/usr/local/zlib/include" \
	LDFLAGS="-L/usr/local/zlib/lib"
make
make install 
cd ..
 
#mysql
groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.1.34.tar.gz
cd mysql-5.1.34
./configure \
	--prefix=/usr/local/mysql \
	--enable-assembler \
	--without-debug \
	--with-mysqld-ldflags=-all-static \
	--with-charset=utf8 \
	--with-extra-charsets=all \
	--with-innodb \
	--with-unix-socket-path=/usr/local/mysql/mysql.sock \
	--enable-thread-safe-client \
	--with-mysqld-user=mysql
make
make install
 
cd ..
if [ -f my.cnf.slave ]; then mv my.cnf.slave /etc/my.cnf; else mv my.cnf.mast /etc/my.cnf; fi; mkdir -p /data/mysqllog/binlog /data/mysqllog/relaylog ; chown mysql.0 /data/mysqllog/binlog /data/mysqllog/relaylog  /usr/local/mysql; cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld ; /usr/local/mysql/bin/mysql_install_db --user=mysql; /etc/init.d/mysqld start
 
# php
tar zxvf php-5.2.9.tar.gz
cd php-5.2.9
./configure \
	--prefix=/usr/local/php \
	--with-zlib=/usr/local/zlib \
	--with-zlib-dir=/usr/local/zlib \
	--with-apxs2=/usr/local/apache/bin/apxs \
	--with-mysql=/usr/local/mysql \
	--with-mysql-sock=/usr/local/mysql \
	--with-pdo-mysql=/usr/local/mysql \
	--with-libxml-dir=/usr/local/libxml2 \
	--with-gd=/usr/local/gd2 \
	--with-jpeg-dir=/usr/local/jpeg6 \
	--with-png-dir=/usr/local/libpng \
	--with-freetype-dir=/usr/local/freetype2 \
	--with-libxml-dir=/usr/local/libxml2 \
	--with-openssl=/usr/local/openssl \
	--with-iconv-dir=/usr/local/iconv \
	--with-ttf \
	--with-gettext \
	--enable-gd-native-ttf \
	--enable-mbstring \
	--enable-xml \
	--enable-pcntl \
	--enable-sockets \
	--enable-zip \
	--with-bz2 \
	--disable-debug 
make
make install
cp php.ini-dist /usr/local/php/lib/php.ini 
cd ..
 
# memcache
tar zxvf memcache-2.2.1.tgz
cd memcache-2.2.1
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcach
make 
make install
cd ..
 
sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20060613/"\n\nextension = "memcache.so"\n#' /usr/local/php/lib/php.ini
sed -i 's#expose_php = On#expose_php = Off#' /usr/local/php/lib/php.ini
 
# soap
cd php-5.2.9/ext/soap
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-soap
make
make install
cd
 
sed -i 's#extension = "memcache.so"#extension = "memcache.so"\nextension = "soap.so"#' /usr/local/php/lib/php.ini

LD_DEBUG

Standard

The dynamic library loader used in linux (part of glibc) has some neat tricks. One of these is that you can set an environment variable called

LD_DEBUG

to show how symbols (variables and functions, for example) are resolved for a dynamic executable. This can sometimes help resolve obscure bugs where your application isn’t doing what you expect (assuming it is caused by symbols being resolved differently to what you were expecting).

This is very useful if you get segmentation violations or aborts for a program – this can sometimes be caused by linking against the wrong version of a library. This is also a really good way to understand what happens when you run any program! It has some self-documentation – for the impatient, you can do

$ LD_DEBUG=help /path/to/some/dynamic/executable

eg

$ LD_DEBUG=help ls

prints out:

Valid options for the LD_DEBUG environment variable are:

libs display library search paths
reloc display relocation processing
files display progress for input file
symbols display symbol table processing
bindings display information about symbol binding
versions display version dependencies
all all previous options combined
statistics display relocation statistics
help display this help message and exit

To direct the debugging output into a file instead of standard output a
filename can be specified using the LD_DEBUG_OUTPUT environment variable.

As a quick example of what it does:

$ LD_DEBUG=all ls 2>&1 > /dev/null | less

13442:
13442: file=librt.so.1; needed by ls
13442: find library=librt.so.1; searching
13442: search cache=/etc/ld.so.cache
13442: trying file=/lib/librt.so.1
13442:
13442: file=librt.so.1; generating link map
13442: dynamic: 0x400263ec base: 0x40020000 size: 0x00010d14
13442: entry: 0x400219c0 phdr: 0x40020034 phnum: 6
13442:
13442:
13442: file=libc.so.6; needed by ls
13442: find library=libc.so.6; searching
13442: search cache=/etc/ld.so.cache
13442: trying file=/lib/libc.so.6
13442:
13442: file=libc.so.6; generating link map
13442: dynamic: 0x40146ce4 base: 0x40031000 size: 0x0011ab00
13442: entry: 0x4004a184 phdr: 0x40031034 phnum: 6
13442:

13442: checking for version `GLIBC_2.2′ in file /lib/librt.so.1 required by file ls
13442: checking for version `GLIBC_2.1′ in file /lib/libc.so.6 required by file ls
13442: checking for version `GLIBC_2.2.3′ in file /lib/libc.so.6 required by file ls

13442: relocation processing: /lib/libpthread.so.0 (lazy)
13442: symbol=_errno; lookup in file=ls
13442: symbol=_errno; lookup in file=/lib/librt.so.1
13442: symbol=_errno; lookup in file=/lib/libc.so.6
13442: symbol=_errno; lookup in file=/lib/libpthread.so.0
13442: symbol=_errno; lookup in file=/lib/ld-linux.so.2
13442: binding file /lib/libpthread.so.0 to /lib/libc.so.6: normal symbol `_errno’ [GLIBC_2.0]
13442: symbol=_h_errno; lookup in file=ls
13442: symbol=_h_errno; lookup in file=/lib/librt.so.1
13442: symbol=_h_errno; lookup in file=/lib/libc.so.6
13442: symbol=_h_errno; lookup in file=/lib/libpthread.so.0
13442: symbol=_h_errno; lookup in file=/lib/ld-linux.so.2
13442: binding file /lib/libpthread.so.0 to /lib/libc.so.6: normal symbol `_h_errno’ [GLIBC_2.0]

In other words, every single function and external variable in the standard library that ls(1) uses must be located each time it is run (kind of obvious, really).

$ ldd /bin/ls
librt.so.1 => /lib/librt.so.1 (0x40020000)
libc.so.6 => /lib/libc.so.6 (0x40031000)
libpthread.so.0 => /lib/libpthread.so.0 (0x4014c000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

Pureftpd + Mysql

Standard
yum install -y mysql mysql-server
 
wget http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.22.tar.gz
tar zxvf pure-ftpd-1.0.22.tar.gz
cd pure-ftpd-1.0.22
./configure \
--prefix=/usr/local/pureftpd \
--with-probe-random-dev  \
--with-paranoidmsg \
--with-altlog \
--with-puredb \
--with-extauth \
--with-pam \
--with-cookie \
--with-throttling \
--with-ratios  \
--with-quotas \
--with-ftpwho \
--with-largefile \
--with-welcomemsg  \
--with-uploadscript \
--with-virtualhosts \
--with-diraliases \
--with-virtualchroot \
--with-peruserlimits \
--with-language=simplified-chinese \
--with-mysql \
--with-tls \
--with-rfc2640
 
#如遇到 configure: error: libmysqlclient is needed for MySQL support 的话就 cp /usr/lib/mysql/libmysqlclient.sq /usr/lib/
make
make install
 
mkdir –pv /usr/local/pureftpd/etc
cp pureftpd-mysql.conf /usr/local/pureftpd/etc
cp configuration-file/pure-config.pl /usr/local/pureftpd/sbin/
cp configuration-file/pure-ftpd.conf /usr/local/pureftpd/etc/
chmod 755 /usr/local/pureftpd/sbin/pure-config.pl
 
cd contrib
cp redhat.init /etc/init.d/pureftpd
chmod u+x /etc/init.d/pureftpd
chkconfig --add pureftpd
chkconfig pureftpd on
vi /etc/init.d/pureftpd #修改其相关默认路径到 /usr/local/pureftpd/
 
wget http://machiel.generaal.net/files/pureftpd/ftp_v2.1.tar.gz
tar zxvf ftp_v2.1.tar.gz
#为其配置web访问,运行 install.php,按提示操作
#http://yemaosheng.com

Pureftp web端管理软件 ftp_v2.1.tar.gz

IP网段的计算和划分-转载

Standard
先了解基础运算
异或运算:相同为0,不同为1
与运算:两者为1时为1,有0为0
或运算:有1为1
 
IP网段的计算和划分 
 
  IP和子网掩码
  我们都知道,IP是由四段数字组成,在此,我们先来了解一下3类常用的IP
  A类IP段  0.0.0.0 到127.255.255.255 
  B类IP段  128.0.0.0 到191.255.255.255 
  C类IP段  192.0.0.0 到223.255.255.255 
 
  XP默认分配的子网掩码每段只有255或0
  A类的默认子网掩码 255.0.0.0     一个子网最多可以容纳1677万多台电脑
  B类的默认子网掩码 255.255.0.0    一个子网最多可以容纳6万台电脑
  C类的默认子网掩码 255.255.255.0   一个子网最多可以容纳254台电脑
 
  我以前认为,要想把一些电脑搞在同一网段,只要IP的前三段一样就可以了,今天,我才知道我错了。如果照我这说的话,一个子网就只能容纳254台电脑?真是有点笑话。我们来说详细看看吧。
 
  要想在同一网段,只要网络标识相同就可以了,那要怎么看网络标识呢?首先要做的是把每段的IP转换为二进制。(有人说,我不会转换耶,没关系,我们用Windows自带计算器就行。打开计算器,点查看>科学型,输入十进制的数字,再点一下“二进制”这个单选点,就可以切换至二进制了。)
 
  把子网掩码切换至二进制,我们会发现,所有的子网掩码是由一串[red]连续[/red]的1和一串[red]连续[/red]的0组成的(一共4段,每段8位,一共32位数)。
  255.0.0.0   11111111.00000000.00000000.00000000
  255.255.0.0  11111111.11111111.00000000.00000000
  255.255.255.0 11111111.11111111.11111111.00000000
  这是A/B/C三类默认子网掩码的二进制形式,其实,还有好多种子网掩码,只要是一串连续的1和一串连续的0就可以了(每段都是8位)。如 11111111.11111111.11111000.00000000,这也是一段合法的子网掩码。子网掩码决定的是一个子网的计算机数目,计算机公式是2的m次方,其中,我们可以把m看到是后面的多少颗0。如255.255.255.0转换成二进制,那就是 11111111.11111111.11111111.00000000,后面有8颗0,那m就是8,255.255.255.0这个子网掩码可以容纳 2的8次方(台)电脑,也就是256台,但是有两个IP是不能用的,那就是最后一段不能为0和255,减去这两台,就是254台。我们再来做一个。
  255.255.248.0这个子网掩码可以最多容纳多少台电脑?
  计算方法:
  把将其转换为二进制的四段数字(每段要是8位,如果是0,可以写成8个0,也就是00000000)
  11111111.1111111.11111000.00000000
  然后,数数后面有几颗0,一共是有11颗,那就是2的11次方,等于2048,这个子网掩码最多可以容纳2048台电脑。
  一个子网最多可以容纳多少台电脑你会算了吧,下面我们来个逆向算法的题。
  一个公司有530台电脑,组成一个对等局域网,子网掩码设多少最合适?
  首先,无疑,530台电脑用B类IP最合适(A类不用说了,太多,C类又不够,肯定是B类),但是B类默认的子网掩码是255.255.0.0,可以容纳6万台电脑,显然不太合适,那子网掩码设多少合适呢?我们先来列个公式。
  2的m次方=560
  首先,我们确定2一定是大于8次方的,因为我们知道2的8次方是256,也就是C类IP的最大容纳电脑的数目。
  我们从9次方一个一个试2的9次方是 512,不到560,2的10次方是1024,看来2的10次方最合适了。
  子网掩码一共由32位组成,已确定后面10位是0了,那前面的22位就是1,最合适的子网掩码就是:
  11111111.11111111.11111100.00000000,转换成10进制,那就是255.255.252.0。
 
  分配和计算子网掩码你会了吧,下面,我们来看看IP地址的网段。
  相信好多人都和偶一样,认为IP只要前三段相同,就是在同一网段了,其实,不是这样的。
  同样,我样把IP的每一段转换为一个二进制数,这里就拿IP:192.168.0.1,子网掩码:255.255.255.0做实验吧。
  192.168.0.1
  11000000.10101000.00000000.00000001
  (这里说明一下,和子网掩码一样,每段8位,不足8位的,前面加0补齐。)
  IP    11000000.10101000.00000000.00000001
  子网掩码  11111111.11111111.11111111.00000000
  在这里,向大家说一下到底怎么样才算同一网段。
  要想在同一网段,必需做到网络标识相同,那网络标识怎么算呢?各类IP的网络标识算法都是不一样的。
  A类的,只算第一段。B类,只算第一、二段。C类,算第一、二、三段。
  算法只要把IP和子网掩码的每位数AND就可以了。
  AND方法:0和1=0 0和0=0 1和1=1
  如:And 192.168.0.1,255.255.255.0,先转换为二进制,然后AND每一位
  IP      11000000.10101000.00000000.00000001
  子网掩码    11111111.11111111.11111111.00000000
  得出AND结果  11000000.10101000.00000000.00000000
  转换为十进制192.168.0.0,这就是网络标识,
  再将子网掩码反取,也就是00000000.00000000.00000000.11111111,与IP AND
  得出结果00000000.00000000.00000000.00000001,转换为10进制,即0.0.0.1,
  这0.0.0.1就是主机标识。要想在同一网段,必需做到网络标识一样。
 
  我们再来看看这个改为默认子网掩码的B类IP
  如IP:188.188.0.111,188.188.5.222,子网掩码都设为255.255.254.0,在同一网段吗?
  先将这些转换成二进制
  188.188.0.111 10111100.10111100.00000000.01101111
  188.188.5.222 10111100.10111100.00000101.11011010
  255.255.254.0 11111111.11111111.11111110.00000000
  分别AND,得
  10111100.10111100.00000000.00000000
  10111100.10111100.00000100.00000000
  网络标识不一样,即不在同一网段。
  判断是不是在同一网段,你会了吧,下面,我们来点实际的。
  一个公司有530台电脑,组成一个对等局域网,子网掩码和IP设多少最合适?
  子网掩码不说了,前面算出结果来了11111111.11111111.11111100.00000000,也就是255.255.252.0
  我们现在要确定的是IP如何分配,首先,选一个B类IP段,这里就选188.188.x.x吧
  这样,IP的前两段确定的,关键是要确定第三段,只要网络标识相同就可以了。
  我们先来确定网络号。(我们把子网掩码中的1和IP中的?对就起来,0和*对应起来,如下:)
  255.255.252.0 11111111.11111111.11111100.00000000
  188.188.x.x  10111100.10111100.??????**.********
  网络标识   10111100.10111100.??????00.00000000
  由此可知,?处随便填(只能用0和1填,不一定全是0和1),我们就用全填0吧,*处随便,这样呢,我们的IP就是
  10111100.10111100.000000**.********,一共有530台电脑,IP的最后一段1~254可以分给254台计算机,530/254=2.086,采用进1法,得整数3。这样,我们确定了IP的第三段要分成三个不同的数字。
也就是说,把000000**中的**填三次数字,只能填1和0,而且每次的数字都不一样,至于填什么,就随我们便了。
如 00000001,00000010,00000011,转换成二进制,分别是1,2,3,这样,第三段也确定了。
这样,就可以把IP分成188.188.1.y,188.188.2.y,188.188.3.y,y处随便填。只要在1~254范围之内,并且这530台电脑每台和每台的IP不一样,就可以了。

IP地址在线计算器: http://yemaosheng.com/ip_subnet_calculator.html