English Sentence Loading...
英语句子加载中...
预览模式: 普通 | 列表

[Ubuntu] user is not in the sudoers file. 的解决方法

今天突然遇到了这个问题,估计是修改用户组的时候出错了。找遍了网上所有的解决办法,几乎所有的都是切换到root用户,但是ubuntu是没有root密码的。经过多次尝试,解决方法如下:

重启系统,在系统启动时按住shift,直到看到grub引导菜单,选择恢复模式(recovery mode),在恢复模式中我们选择root模式。然后我们就可以敲 visudo 啦,把你想加入的用户加到这个文件里。

liubing    ALL=(ALL) ALL
或者我们可以把用户加入到admin组中即可

sudo usermod -G admin liubing
保存退出,然后重启系统即可。
标签: ubuntu sudoers linux

php 生成 xml 添加 BOM

前两天做公司网站的CMS,因为xml的问题郁闷了好几天,明明是utf-8的xml,可是前台的flash却总是在读取中文xml时出现乱码。
找了几天原来要在写xml文件时添加BOM信息。代码如下:

下载: adddom.php
  1. <?php
  2. $bom = pack("C3",239,187,191);
  3. $xml = $bom;
  4. ...
  5. $xml.= "...";
  6. file_put_contents($filename,$xml);
  7. ?>
标签: php BOM

php 生成缩略图

  1. <?php
  2.     /*
  3.      *  Create Thumbnail picture
  4.      *  Author: Liubing
  5.      *  Last Modify: 2010-05-06 12:09
  6.      *
  7.      *  How to use it:
  8.      *
  9.      *    $source_pic = dirname(__FILE__).'/1920VectorLove008.png';
  10.      *    $thumb = new Thumbnail($source_pic,250,100);
  11.      *    $thumb->create();
  12.      */
  13.     class Thumbnail
  14.     {
  15.         /* source picture */
  16.         var $source_pic;
  17.       
  18.         /* source picture width */
  19.         var $source_w;
  20.       
  21.         /* source picture height */
  22.         var $source_h;
  23.       
  24.         /* source picture mimetype */
  25.         var $source_mime;
  26.       
  27.         /* source picture is valid or not */
  28.         var $source_valid;
  29.       
  30.         /* thumb picture directory */
  31.         var $dest_dir;
  32.       
  33.         /* thumb picture name */
  34.         var $dest_pic;
  35.       
  36.         /* thumb picture width */
  37.         var $dest_w;
  38.       
  39.         /* thumb picture height */
  40.         var $dest_h;
  41.       
  42.         /* assign mimetype to function name */
  43.         var $mime2func;
  44.       
  45.         function Thumbnail($source_pic,$width="400",$height="300",$dest_dir="")
  46.         {
  47.             $this->source_pic   = $source_pic;
  48.             $this->source_valid = false;
  49.             $this->dest_dir     = $dest_dir == "" ? dirname(__FILE__) : $dest_dir;
  50.             $this->dest_w       = intval($width);
  51.             $this->dest_h       = intval($height);
  52.             $this->mime2func    = array("image/jpeg" => "jpeg", "image/gif" => "gif", "image/png" => "png");
  53.             $this->readSource();
  54.         }
  55.       
  56.         /* Read Source Picture */
  57.         function readSource()
  58.         {
  59.             if(file_exists($this->source_pic)){
  60.                 $picinfo = getimagesize($this->source_pic);
  61.                 if(is_array($picinfo)){
  62.                     $this->source_w     = $picinfo[0];
  63.                     $this->source_h     = $picinfo[1];
  64.                     $this->source_mime  = $picinfo['mime'];
  65.                     $this->source_valid = true;
  66.                   
  67.                     $basename           = basename($this->source_pic);
  68.                     $this->dest_pic     = substr(md5(rand()),0,10)."_".$this->dest_w."_".$this->dest_h."_".$basename;
  69.                   
  70.                     $this->setRealSize();
  71.                 }
  72.             }
  73.         }
  74.       
  75.         //Set Thumb Size (keep proportion)
  76.         function setRealSize()
  77.         {
  78.             if(!$this->source_valid) return;
  79.             if($this->dest_w < 1 || $this->dest_w >= $this->source_w) $this->dest_w = 0;
  80.             if($this->dest_h < 1 || $this->dest_h >= $this->source_h) $this->dest_h = 0;
  81.             if($this->dest_w == 0 && $this->dest_h == 0) return;
  82.           
  83.             if($this->dest_w > 0 && $this->dest_h > 0){
  84.                 if(($this->source_w / $this->dest_w) > ($this->source_h / $this->dest_h)){
  85.                     $this->dest_h = ceil(($this->source_h * $this->dest_w) / $this->source_w);
  86.                 }else{
  87.                     $this->dest_w = ceil(($this->source_w * $this->dest_h) / $this->source_h);
  88.                 }
  89.             }elseif($this->dest_w > 0){
  90.                 $this->dest_h = ceil(($this->source_h * $this->dest_w) / $this->source_w);
  91.             }else{
  92.                 $this->dest_w = ceil(($this->source_w * $this->dest_h) / $this->source_h);
  93.             }
  94.         }
  95.       
  96.         function create()
  97.         {
  98.             if(!$this->source_valid || $this->mime2func[$this->source_mime] == '') return;
  99.           
  100.             //create folder
  101.             if(substr($this->dest_dir,-1,1) != "/") $this->dest_dir .= "/";
  102.             $this->dest_dir .= "thumb/".date("Y-m");
  103.             if(!is_dir($this->dest_dir)) mkdir($this->dest_dir);
  104.           
  105.             //copy source to thumb
  106.             if($this->dest_w == 0 || $this->dest_h == 0){
  107.                 copy($this->source_pic,$this->dest_dir."/".$this->dest_pic);
  108.                 return;
  109.             }
  110.           
  111.             //create thumb
  112.             $createfunc = "imagecreatefrom".$this->mime2func[$this->source_mime];
  113.             $outputfunc = "image".$this->mime2func[$this->source_mime];
  114.             $d_im = imagecreatetruecolor($this->dest_w,$this->dest_h);
  115.             $s_im = $createfunc($this->source_pic);
  116.             imagecopyresized($d_im, $s_im, 0, 0, 0, 0, $this->dest_w, $this->dest_h, $this->source_w, $this->source_h);
  117.           
  118.             //save
  119.             $outputfunc($d_im,$this->dest_dir."/".$this->dest_pic);
  120.           
  121.             //destroy
  122.             imagedestroy($d_im);
  123.             imagedestroy($s_im);
  124.         }
  125.   
  126.     }
  127. ?>
标签: php 缩略图

mysql create function 的简单举例

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 function

Ubuntu/CentOS 安装 Memcache

平台: 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. 测试

下载: memcache.php
  1. <?php
  2.     $mc = new Memcache;
  3.     $mc->connect("127.0.0.1",11211);
  4.     $item = $mc->get('item');
  5.     if(!is_array($item)){
  6.         echo "Add item to memcache";
  7.         $mc->add('item',array('item'));
  8.     }
  9.     $item = $mc->get('item');
  10.     var_dump($item);
  11. ?>

多刷新几次浏览器,我们会发现,只有第一次出现了Add item to memcache。

文档请参阅:http://php.net/manual/en/book.memcache.php

CentOS下按此步骤安装测试无误。