English Sentence Loading...
英语句子加载中...
[Ubuntu] user is not in the sudoers file. 的解决方法
作者:蘑菇 日期:2010-05-28 17:45
今天突然遇到了这个问题,估计是修改用户组的时候出错了。找遍了网上所有的解决办法,几乎所有的都是切换到root用户,但是ubuntu是没有root密码的。经过多次尝试,解决方法如下:
重启系统,在系统启动时按住shift,直到看到grub引导菜单,选择恢复模式(recovery mode),在恢复模式中我们选择root模式。然后我们就可以敲 visudo 啦,把你想加入的用户加到这个文件里。
liubing ALL=(ALL) ALL
或者我们可以把用户加入到admin组中即可
sudo usermod -G admin liubing
保存退出,然后重启系统即可。
重启系统,在系统启动时按住shift,直到看到grub引导菜单,选择恢复模式(recovery mode),在恢复模式中我们选择root模式。然后我们就可以敲 visudo 啦,把你想加入的用户加到这个文件里。
liubing ALL=(ALL) ALL
或者我们可以把用户加入到admin组中即可
sudo usermod -G admin liubing
保存退出,然后重启系统即可。
php 生成 xml 添加 BOM
作者:蘑菇 日期:2010-05-27 21:20
php 生成缩略图
作者:蘑菇 日期:2010-05-06 11:56
下载: thumbclass.php
- <?php
- /*
- * Create Thumbnail picture
- * Author: Liubing
- * Last Modify: 2010-05-06 12:09
- *
- * How to use it:
- *
- * $source_pic = dirname(__FILE__).'/1920VectorLove008.png';
- * $thumb = new Thumbnail($source_pic,250,100);
- * $thumb->create();
- */
- class Thumbnail
- {
- /* source picture */
- var $source_pic;
- /* source picture width */
- var $source_w;
- /* source picture height */
- var $source_h;
- /* source picture mimetype */
- var $source_mime;
- /* source picture is valid or not */
- var $source_valid;
- /* thumb picture directory */
- var $dest_dir;
- /* thumb picture name */
- var $dest_pic;
- /* thumb picture width */
- var $dest_w;
- /* thumb picture height */
- var $dest_h;
- /* assign mimetype to function name */
- var $mime2func;
- function Thumbnail($source_pic,$width="400",$height="300",$dest_dir="")
- {
- $this->source_pic = $source_pic;
- $this->source_valid = false;
- $this->dest_dir = $dest_dir == "" ? dirname(__FILE__) : $dest_dir;
- $this->dest_w = intval($width);
- $this->dest_h = intval($height);
- $this->mime2func = array("image/jpeg" => "jpeg", "image/gif" => "gif", "image/png" => "png");
- $this->readSource();
- }
- /* Read Source Picture */
- function readSource()
- {
- if(file_exists($this->source_pic)){
- $picinfo = getimagesize($this->source_pic);
- if(is_array($picinfo)){
- $this->source_w = $picinfo[0];
- $this->source_h = $picinfo[1];
- $this->source_mime = $picinfo['mime'];
- $this->source_valid = true;
- $basename = basename($this->source_pic);
- $this->dest_pic = substr(md5(rand()),0,10)."_".$this->dest_w."_".$this->dest_h."_".$basename;
- $this->setRealSize();
- }
- }
- }
- //Set Thumb Size (keep proportion)
- function setRealSize()
- {
- if(!$this->source_valid) return;
- if($this->dest_w < 1 || $this->dest_w >= $this->source_w) $this->dest_w = 0;
- if($this->dest_h < 1 || $this->dest_h >= $this->source_h) $this->dest_h = 0;
- if($this->dest_w == 0 && $this->dest_h == 0) return;
- if($this->dest_w > 0 && $this->dest_h > 0){
- if(($this->source_w / $this->dest_w) > ($this->source_h / $this->dest_h)){
- $this->dest_h = ceil(($this->source_h * $this->dest_w) / $this->source_w);
- }else{
- $this->dest_w = ceil(($this->source_w * $this->dest_h) / $this->source_h);
- }
- }elseif($this->dest_w > 0){
- $this->dest_h = ceil(($this->source_h * $this->dest_w) / $this->source_w);
- }else{
- $this->dest_w = ceil(($this->source_w * $this->dest_h) / $this->source_h);
- }
- }
- function create()
- {
- if(!$this->source_valid || $this->mime2func[$this->source_mime] == '') return;
- //create folder
- if(substr($this->dest_dir,-1,1) != "/") $this->dest_dir .= "/";
- $this->dest_dir .= "thumb/".date("Y-m");
- if(!is_dir($this->dest_dir)) mkdir($this->dest_dir);
- //copy source to thumb
- if($this->dest_w == 0 || $this->dest_h == 0){
- copy($this->source_pic,$this->dest_dir."/".$this->dest_pic);
- return;
- }
- //create thumb
- $createfunc = "imagecreatefrom".$this->mime2func[$this->source_mime];
- $outputfunc = "image".$this->mime2func[$this->source_mime];
- $d_im = imagecreatetruecolor($this->dest_w,$this->dest_h);
- $s_im = $createfunc($this->source_pic);
- imagecopyresized($d_im, $s_im, 0, 0, 0, 0, $this->dest_w, $this->dest_h, $this->source_w, $this->source_h);
- //save
- $outputfunc($d_im,$this->dest_dir."/".$this->dest_pic);
- //destroy
- imagedestroy($d_im);
- imagedestroy($s_im);
- }
- }
- ?>
mysql create function 的简单举例
作者:蘑菇 日期:2010-04-29 14:51
mysql > use test;
mysql > delimiter $ //定义分隔符
mysql > create function myfunc(s varchar(255)) returns varchar(255)
mysql > begin
mysql > declare pos int;
mysql > set pos = instr(s, 'eduicc');
mysql > return if(pos > 0, substr(s, 1, pos-1), s);
mysql > end $
mysql > delimiter ;
mysql >
mysql > select myfunc('testeduicc');
+-----------------------------+
| myfunc('testeduicc') |
+-----------------------------+
| test |
+-----------------------------+
1 row in set (0.00 sec)
mysql > show function status;
mysql > delimiter $ //定义分隔符
mysql > create function myfunc(s varchar(255)) returns varchar(255)
mysql > begin
mysql > declare pos int;
mysql > set pos = instr(s, 'eduicc');
mysql > return if(pos > 0, substr(s, 1, pos-1), s);
mysql > end $
mysql > delimiter ;
mysql >
mysql > select myfunc('testeduicc');
+-----------------------------+
| myfunc('testeduicc') |
+-----------------------------+
| test |
+-----------------------------+
1 row in set (0.00 sec)
mysql > show function status;
Ubuntu/CentOS 安装 Memcache
作者:蘑菇 日期:2010-04-22 12:00
平台: Ubuntu 9.10 + Nginx 0.7.65 + Mysql 5.1.45 + php 5.2.10 FastCGI
1. 下载memcache: http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
2. 解压安装
$ tar -zxvf memcached-1.4.5.tar.gz
$ cd memcached-1.4.5
$ ./configure
$ make
$ sudo make install
3. 启动
$ sudo /usr/local/bin/memcached -d -c 128 -u root -P /tmp/memcached.pid
4. 安装php-memcache扩展
下载:http://pecl.php.net/get/memcache-2.2.4.tgz
#解压安装
$ tar -zxvf memcache-2.2.4.tgz
$ cd memcache-2.2.4
$ /usr/local/php/bin/phpize
$ ./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache
$ make
$ sudo mkdir /usr/local/php/extensions/
$ sudo cp modules/memcache.so /usr/local/php/extensions/
#在php.ini中加入扩展
[vi /usr/local/php/etc/php.ini]
extension_dir = "/usr/local/php/extensions/"
extension = "memcache.so"
重新启动php-fpm
$ sudo /usr/local/php/sbin/php-fpm restart
5. 测试
1. 下载memcache: http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
2. 解压安装
$ tar -zxvf memcached-1.4.5.tar.gz
$ cd memcached-1.4.5
$ ./configure
$ make
$ sudo make install
3. 启动
$ sudo /usr/local/bin/memcached -d -c 128 -u root -P /tmp/memcached.pid
4. 安装php-memcache扩展
下载:http://pecl.php.net/get/memcache-2.2.4.tgz
#解压安装
$ tar -zxvf memcache-2.2.4.tgz
$ cd memcache-2.2.4
$ /usr/local/php/bin/phpize
$ ./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache
$ make
$ sudo mkdir /usr/local/php/extensions/
$ sudo cp modules/memcache.so /usr/local/php/extensions/
#在php.ini中加入扩展
[vi /usr/local/php/etc/php.ini]
extension_dir = "/usr/local/php/extensions/"
extension = "memcache.so"
重新启动php-fpm
$ sudo /usr/local/php/sbin/php-fpm restart
5. 测试
下载: memcache.php
- <?php
- $mc = new Memcache;
- $mc->connect("127.0.0.1",11211);
- $item = $mc->get('item');
- if(!is_array($item)){
- echo "Add item to memcache";
- $mc->add('item',array('item'));
- }
- $item = $mc->get('item');
- var_dump($item);
- ?>
多刷新几次浏览器,我们会发现,只有第一次出现了Add item to memcache。
文档请参阅:http://php.net/manual/en/book.memcache.php
CentOS下按此步骤安装测试无误。

