Ubuntu下PHP扩展cURL

开发php的时候遇到一个错误,

Fatal error: Call to undefined function curl_init()

Google了一下,网上基本都是你抄我,我抄你,还不能解决,我勒个擦。还是自己动手吧,结合以前经验,解决方法如下:

0. 前提。我的php开发环境是用源码包编译、安装而成的。并且保留了php的源码包。

1. 安装cURL。
1.1 进入/usr/local/src目录,命令如下:
$ cd /usr/local/src

1.2 下载cURL源码包,可以通过命令下载,也可以直接去http://curl.haxx.se/download/选择版本下载,然后copy到该目录。如果是敲命令,如下:
$ sudo wget http://curl.haxx.se/download/curl-7.17.1.tar.gz

1.3 配置。在当前目录下执行命令:
$ sudo ./configure –prefix=/usr/local/curl

1.4 编译,命令如下:
$ sudo make

1.5 安装,命令如下:
$ sudo make install

如果安装成功以后,在/usr/local/curl/目录下将生成bin、include、lib和share四个目录。
Selection_135

2. 扩展php。
2.1 进入php源码包(不是安装以后的)位置/ext/curl/目录,我的在/usr/local/src/php-5.3.22/ext/curl,如下图所示Selection_134

2.2 在当前目录下,通过phpize可以建立php的外挂模块,命令如下:
$ sudo /usr/local/php/bin/phpize
其中/usr/local/php/是我的php安装路径,有可能与各位不一样。

2.3 配置扩展,命令如下:
$ sudo ./configure –with-php-config=/usr/local/php/bin/php-config –with-curl=/usr/local/curl

2.4 编译,命令如下:
$ sudo make

2.5 安装,命令如下:
$ sudo make install

安装成功后,会在/usr/local/php/lib/php/extensions目录下生成no-debug-zts-20090626(php版本不同,这个名称也许不同)目录,该目录下就能看到生成的curl.so文件,如下图所示。
Selection_136

2.6 修改php.ini配置文件,添加extension=”/usr/local/php/lib/php/extensions/no-debug-zts-20090626/curl.so”,如下图所示
Selection_137

2.7 重启apache服务器,完成。

Ubuntu搭建LAMP环境(jpeg-6b 安装错误 ,找不到libtool命令)

继续安装php开发环境,

jpeg-6b make的时候错误:

./libtool –mode=compile gcc -O2 -I. -c ./jcapimin.c
make: ./libtool: Command not found
make: *** [jcapimin.lo] Error 127

看提示应该是没有安装libtool,由于才拿到手里的服务器,什么都没装,出现这个错误也正常。

解决办法:安装libtool

1 在上面的链接或者网上下载 libtool-2.2.6a.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录libtool-2.2.6下,并进入libtool-2.2.6目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf libtool-2.2.6a.tar.gz           // 解压缩
$ cd libtool-2.2.6                                         // 进入目录

2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下:
$ ./configure
安装到默认路径就可以。

3 使用make命令编译源码文件并生成安装文件,命令如下:
$ sudo make                                                    // 编译

4 使用make install命令进行安装,命令如下:
$ sudo make install                                         // 安装

5 复制libtool中的config.sub和config.guess文件至jpeg-6b根目录,命令如下:
$ cd /usr/local/src/jpeg-6b/
$ sudo cp /usr/local/share/libtool/config/config.sub .
$ sudo cp /usr/local/share/libtool/config/config.guess .

6 重新配置并编译、安装jpeg-6b,命令如下:
$ sudo ./configure \
> –prefix=/usr/local/jpeg6/ \                             // 安装时将软件安装到/usr/local/jpeg6目录下
> –enable-shared \                                              // 建立共享库使用的GNU的libtool
> –enable-static                                                   // 建立静态库使用的GNU的libtool
$ sudo make                                                        // 编译
$ sudo make install                                             // 安装

7 Done.
————————————-华丽丽的分割线,下面是英语版———————–

English Version:

Continue to install the PHP environment.
An error occured when make jpeg-6b:

./libtool –mode=compile gcc -O2 -I. -c ./jcapimin.c
make: ./libtool: Command not found
make: *** [jcapimin.lo] Error 127

According the prompt, the libtool isn’t installed. It’s normal to have this error on a bare machine.

Solution: install libtool, of course!

1. Download the file libtool-2.2.6a.tar.gz on the above link or the official site, put it under /usr/local/src/, and extract it into libtool-2.2.6/ and then enter the current directory. The commands as follows:

$ cd /usr/local/usr/            // enter the directory where the source code is
$ sudo tar zxvf libtool-2.2.6a.tar.gz           // extract the file
$ cd libtool-2.2.6                              // enter the current directory

2. Check and configure the installation environment with “configure” command, which will generate installation configuration file.  The command line as follows:
$ ./configure
we can just install it in the default path.

3. use the make command to compile the source file and generate the installation file:
$make                                                      // compile

4. use command make install to install:
$ make install                                              // install

5. copy the config.sub and config.guess of libtool to jpeg-6b/, command as follows:
$ cd /usr/local/src/jpeg-6b/
$ sudo cp /usr/local/share/libtool/config/config.sub
$ sudo cp /usr/local/share/libtool/config/config.guess

6. reconfigure, compile and install jpeg-6b, commands as follows:
$ sudo ./configure \
> –prefix=/usr/local/jpeg6/ \                                   //install the software into /usr/local/jpeg6
> –enable-shared \                                       // GUN’s libtool will be used when creating shared lib
> –enable-static                                           // GUN’s libtool will be used when creating static  lib
$ sudo make                                                        // compile
$ sudo make install                                             // install

7. Done

ubuntu下PHP安装pdo_mysql扩展

在linux下使用yii框架的时候,遇到一个错误

“CDbConnection failed to open the DB connection: could not find drive ”

google了一下,然后去/yii路径/requirements/index.php确认了是由于PDO MYSQL extension 没有安装的原因(PDO MYSQL extension 后面出现了Warning)。

解决方法:

1.进入php源码包中的/etc/pdo_mysql目录,我的在

cd /usr/local/src/php-5.3.22/ext/pdo_mysql 

在当前目录执行phpize(在php的安装路径里的bin/目录里,我的在

/usr/local/src/php-5.3.22/ext/pdo_mysql$  /usr/local/php/bin/phpize

2.配置

在当前目录下执行

./configure –with-php-config=/usr/local/php/bin/php-config –with-pdo-mysql=/usr/local/mysql

其中/usr/local/mysql是我的mysql安装目录

3.编译安装

make一下,然后make install

安装成功以后,会在/usr/local/php/lib/php/extensions/no-debug-zts-20090626目录有pdo_mysql.so文件

其中no-debug-non-zts-20090626可能会根据你下的php源码包不同而有所不同,如no-debug-non-zts-20050922等

4.修改配置文件

修改php.ini文件,添加扩展语句

extension=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/pdo_mysql.so”

5.重启apache,完成。

6.在phpinfo中就可以看到扩展成功

Selection_101

7.在yii的/requirements/index.php中也可以看到Warning变成了Passed

Selection_102

Yii框架Register模块开发流程

本文用以下五个步骤来详细介绍:

1. 用gii创建所需Module, Model, Controller,Crud以及Form

2. 注册界面显示部分(以下则以access模块作为例子讲解)

3. 编辑逻辑部分代码

4. 修改Controller

5. 总结

一. 用gii创建所需Module, Model, Controller,Crud以及Form

在浏览器输入地址http://127.0.0.1/icampus/sns/index.php?r=gii进入gii界面,输入密码123456,进入可视化代码生成工具页面。按照module -> model -> controller -> crud -> form 的顺序分别生成代码。

1

1.选择Module Generator,在Module ID输入框中输入模块名称access(为了演示这里输入的是access2,以后类同),点击Preview,确认没错以后点击Generate即可生成代码。

2

然后可以在icampus\sns\protected\modules文件夹下看到生成的access2文件夹。

 2.把上图中代码部分添加到\icampus\sns\protected\config\main.php中的modules数组里面,以便可以访问,如下图所示。

3

3. 点击Model Generator,参照下图的输入,填入所需内容,如表名前缀icp_access;注册所需要用的表示user,所以Table Name这里填入icp_access_user;Model Class可自定义,不妨用AccessUser2来创建;然后输入正确的Model Path。

4

至此model也建立好了,可以在icampus\sns\protected\modules\access2文件夹下看到多出来一个model文件夹,里面有model文件AccessUser2.php

4. 点击Controller Generator,参照下图所示,填写具体输入框。Controller ID这里填写module名称/model名称,即access2/AccessUser2

5

然后点击Generate,即会在模块的controller文件夹(icampus\sns\protected\modules\access2\controllers)下生成AccessUser2Controlller.php

5. 点击Crud Generator,参考下图填写

6

然后点击Generate即可

6. 点击Form Generator,参考下图填写各个输入框

7

点击Generate即可生成所需要的form页面。然后会提示将下列代码添加到controller中。

8

打开AccessUser2Controlller.php,将上述方法复制进去即可。

至此,注册模块所有需要自动生成的步骤已经完成。注意:最好按顺序来(module -> model -> controller -> crud -> form)

二. 注册界面显示部分(以下则以access模块作为例子讲解)

1.由于数据库中字段如lastlogin, salt等是不需要用户输入的,所以首先必须在view中去掉这些部分;由于注册的时候需要用户重复密码以及为了防止恶意注册采取了验证码,必须在view中添加这两个字段。

打开\icampus\sns\protected\modules\access\views\accessUser文件夹中register.php

[php] <div class="row">
<?php echo $form->labelEx($model,’name’); ?>
<?php echo $form->textField($model,’name’); ?>
<?php echo $form->error($model,’name’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’password’); ?>
<?php echo $form->passwordField($model,’password’); ?>
<?php echo $form->error($model,’password’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’passwordConfirm’); ?>
<?php echo $form->passwordField($model,’passwordConfirm’); ?>
<?php echo $form->error($model,’passwordConfirm’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’verifyCode’); ?>
<?php echo $form->textField($model,’verifyCode’); ?>
<?php echo $form->error($model,’verifyCode’); ?>
</div>
<div class="row">
<?php $this->widget(‘CCaptcha’); ?>
</div>[/php]

可以看到每一个字段都是写在一个div里的,可以很方便的让我删除或者添加,div组中的

form->labelEx表示要显示的说明文字;

form->passwordField表示采取的格式;

form->error表示错误提示;

从上面代码可以看到,我们保留的字段有name,password,passwordConfirm,以及verifyCode。其中密码输入框不能明文显示,所以采用form->passwordField形式;用户名与验证码输入框需要明文显示,所以我们采用form->textField形式。

最后三行即是显示验证码图片。

效果图如下图所示。

1

三. 编辑逻辑部分代码

由于刚才我们删除了一些字段显示,又添加了一些字段显示。所以需要作一些逻辑修改。

1. 打开icampus\sns\protected\modules\access\models文件下下的AccessUser.php,首先添加两个public字段,如果不声明为public,会导致访问出错。

[php]
public $passwordConfirm;
public $verifyCode;
[/php]

2. 修改下面这个函数,将上述两个字段在要求用户输入的时候,需要显示的说明文字写上去。比如需要用户重复输入密码的时候,我希望显示的提示信息是“Confirm your password”

[php]
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
‘id’ => ‘ID’,
‘name’ => ‘Name’,
‘password’ => ‘Password’,
‘lastlogin’ => ‘Lastlogin’,
‘passwordConfirm’ => ‘Confirm your password’,
‘verifyCode’ => ‘repeat the following code’,
‘salt’ => ‘Salt’,
);
}
[/php]

3. 修改下面的函数,添加规则。由于两次密码必须一致,所以给passwordConfirm添加一条验证规则(即下面代码中的13行),验证码也需要添加规则(下面代码中的15行)。

[php]
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array(‘name, password, salt’, ‘length’, ‘max’=>255),
array(‘lastlogin’, ‘safe’),

//the "passwordConfirm" shoud be equal to the "password"
array(‘passwordConfirm’, ‘compare’, ‘compareAttribute’=>’password’),
//the verifyCode
array(‘verifyCode’, ‘captcha’, ‘on’=>’register’, ‘allowEmpty’=>!extension_loaded(‘gd’)),

// The following rule is used by search().
// Please remove those attributes that should not be searched.
array(‘id, name, password, lastlogin, salt’, ‘safe’, ‘on’=>’search’),
);
}
[/php]

4. 如果需要,重写beforeSave()函数。因为注册的时候,需要作给密码加密等操作,所以我重写了beforeSave()函数

[php]/**
* Author: HuKeping
* Date: 2013-4-1 22:08:00
* Brief: override the super beforeSave() function to do some thing before save the record to database.
* salt is a unix timestamp by the time of the very moment.
* password is encoded by md5 and then attached with the md5ed salt string and md5 the new string again.
* lastlogin is initialized with the time of the very moment.
* set the timezone to PRC is to make the timezone correct.
*
*/
public function beforeSave()
{
if($this->isNewRecord)
{
$salt = time(); //get the unix timestamp here
date_default_timezone_set(‘PRC’); //set the timezone to PRC
$this->lastlogin = date(‘Y-m-d H:i:s’, time()); //the timestamp in mysql is not the same with it in php
$salt = md5($salt); //encode the salt by md5
$password = md5(md5($this->password) . $salt); //md5 again
$this->password = $password; //set the password
$this->salt = $salt; //set the salt
}
else
{
return false;
}
return parent::beforeSave();
}[/php]

注意1:如果没有出错,一定要返回true,否则记录不会插入数据库

注意2:最好在验证以后,保存之前,在beforeSave()里进行所需要的编码(如md5加密)等操作,否则有可能会验证出错(比如密码与md5过后的密码比较),导致save()操作失败。

四. 修改Controller

需要在controller中添加访问规则以及action等。打开\icampus\sns\protected\modules\access\controllers文件夹下AccessUserController.php

1. 在下面的函数中,把‘register’以及启用验证码‘captcha’添加进所有用户的权限中

14

2. 为了使用验证码,需要添加一个action,如下图所示

[php]
/**
*
* Author: HuKeping
* Date: 2013-4-1 15:48:22
* Brief: add the verification action
* minLength is the mininum number of characters that used to as the verify code
* maxLength is the maximum number of characters that used to as the veryfy code
* when minLength == maxLength, the number of bytes is set, otherwise it’s random.
*/
public function actions()
{
return array(
‘captcha’=>array(
‘class’ => ‘CCaptchaAction’,
‘backColor’ => 0xCCCCCC,
‘minLength’ => 4,
‘maxLength’ => 4,
),
);
}
[/php]

其中数组中的各个参数已经在注释中写明。

3. 修改自动生成的actionRegister函数,如下图所示

16

至少添加最后一句 $model->save(),即更新数据库。执行这一句之前,框架会自动执行刚才写的beforeSave()。执行完save()以后,整个注册流程也到此结束。

五. 总结

总的来说,流程就是

  1. gii自动生成模块
  2. 根据需求修改视图
  3. 根据视图修改逻辑
  4. 修改权限、规则等。

不算读书笔记的笔记——《murder in Mesopotamia》

IMG_0026

Somehow,the more I get older,and the more I see of people and sadness and illness and everything,the sorrier I get for everyone
                                                                ————–Leatheran, the nurse
其实,自己几个月读的书,还不如人家两周读的书多。可也是喜欢不是么,也愿意这一小小爱好随意写写,让脑子从代码堆里暂时解放出来。

呐,在开头的开头,是偶然在未明BBS看到的一篇帖子,提到了阿加莎和她的作品,看着挺有意思,加上正好当时手头上书已经读完啦,就决定去买一本阿婆的书来瞅瞅。大家好像对《古墓之谜》评价挺高的,作为第一次读人家作品的菜鸟级人物,当然听大家的最保险啦:)

本来打算买中文版的,又见很多人说翻译得太烂(其实也许不是译者水平烂,只是文化差异在那里摆着,有很多东西翻译以后就失去那种意境、那种味道了),所以此书就在某一天落到了我的口袋里。至于为什么中文叫《古墓之谜》,英文叫《murder in Mesopotamia》,就没有去深究了,很常见的现象。

算起来这是我看的第二本英文小说,第一本《who moved my cheese》单词比较简单,这本看起来就比较费劲了,不过终于,在那天回本部的地铁上看完了,耶~!虽然不是句句清晰,甚至都不能记全书中人物的名字,但也算掌握了故事的大概。

跟所有悬疑小说一样,往往最不起眼的或者最不可能的或者在感情上最不能接受的,往往就是凶手,差别只在于作案的手法,这大概也才是吸引读者的地方。这本书自然是把这些细节描写得淋漓尽致,但我印象最深的却是他们之间的爱情纠葛以及最后小护士的一番自我体会——Somehow,the more I get older,and the more I see of people and sadness and illness and everything,the sorrier I get for everyone。不知道该怎么翻译才恰当,只是觉得自己也是这样,越大越有一种抱歉的情绪在滋生。

好啦,写完啦,所以说不像是一篇读书笔记嘛。而且本来也不咋会写的,呵呵O(∩_∩)O~.

PS:大学姐真好~今天陪我去逛书店买书,可是太累,地铁上都睡着了55。。

IMG_0311_25

 

晚安。

2013.3.28 00:48:32 @ my bed

其实,还是挺喜欢软微这座园子的

又到了周二晚上,明天周三(是的,这是废话),上午有课,下午例行跑校医院。

所以不用去实验室,所以可以翘一天班,所以心情大好,所以可以晃晃悠悠的在园子里散步,慢慢感受夜里的宁静,也感受这里的光与影。晃荡着来了兴致,索性跑回寝室把三脚架、照相机带出来,记录一下也不知道是倒数第几个还能呆在这里的夜晚。

白天的软微是荒凉的,荒凉到我只愿呆在实验室里。幸而夜色会还这里一份宁静。

本来夜里一个人出来散步就很容易有一些感触,也想写一些东西,但转念一下,老弟说得对啊,堂堂七尺男儿,矫情你妹儿,于是作罢。直接上图。

IMG_3597_1280

这是每天从寝室到实验室必经的石板小道,设计得还不错。

右边就是女生宿舍,拍的时候大学姐不知什么时候站我身后了,,,,,啊啊啊啊啊啊啊啊啊啊啊啊啊~我在大学姐心目中的形象毁了啊啊啊啊啊啊啊啊啊啊啊啊啊啊~好了,上图。

IMG_3625_25

大学姐也出来散步了,hurry!!!!!!!果断拉一起同行啊:)

那就不能继续拍这里了~~转拍那边转弯的路口吧,过去拍了挺多,选了一张自己感觉比较合适的。就是下面这张啦。

IMG_3645_25

嘿嘿,大学姐也觉得这张不错,心情一好,决定赐一个合拍机会~于是有了下面这张HoHoHo~

IMG_3639_25

可为什么我的鞋子下面那么黑啊。。。。。。。。。。。。

不说了,说多了都是泪,再传一张白天校园草地的图吧,在下雨,光线不是很好~~附带大学姐一枚:)

IMG_5587_12.5

草地中间那些一块儿一块儿的是园丁师傅修剪草坪以后留下来的枯草,让他们重回泥土当肥料有木有,天然绿色有机肥O(∩_∩)O哈哈~

再传一张小花园的

IMG_0320_3

 

这就是花园区啦,正确面是宿舍楼和某些专业的实验小别墅楼。

Enjoy!

整整一个曾经

这是我最喜欢的一只猫,喵名——哈士奇。

和它结缘的时候,还只是一只小奶喵,整天被他们扔来扔去的,可怜又可爱,没少到实验室来皮:)IMG_0098_2_25

已经很久很久不见它了,估计走了吧,也或许是死了。哦对了,它知道自己叫哈士奇,每次一叫它名字,多远也会跑过来,每当这个时候,一点点傲娇情绪会很自然的升起——看,哥一叫它就过来了,吼吼。

可是已经很久很久没看到过它了。

一直它都是作为桌面来着,平时也就不怎么特别想它。今天晚上,大家都在实验室加班,快到凌晨了,想吃东西,和大学姐一起去买,回来在小花园碰到了一只黑猫,新生的,嗯,我肯定。以前都没见过它。外面又已经零下了,和学姐开门让它进屋,招呼几下就过来了,真乖。上楼拿吃的下来喂它,当转身的那一刹那,哈士奇那虎圆虎圆的大蛮腰视觉冲击迎面扑来,就这么回忆上了。

“快吃快吃,死猫”,也许只有骂它才能止得住。

想想这鱼挺咸的,上去削一个纸杯给它喝水吧,刚接好水下来就看见它巴巴的望着我。蹲下喂喂水,吃饱喝足了,赶紧把它送出门。

回来坐到工位上,看着桌面上的哈士奇,看着学姐发失败的黑猫照片。是有点点想它了。以前应该是爱它的吧,

也许爱了整整一个曾经。

 

2013.3.26 00:29:27 @ 十号楼西边二楼