您的位置:首页 > 编程语言 > PHP开发

Cakephp 2.5.0 安装配置

2014-05-14 16:36 369 查看
安装环境如下:

httpd-2.2.21-win32-x86-openssl-0.9.8r.msi(Apache2.2.21
openssl版本)

mysql-5.5.20-win32.msi(MySQL5.5.20)

php-5.3.10-Win32-VC9-x86.zip(PHP5.3.10
thread safe版本)

Windows 7 Ultimate 32bit

1. 安装和配置cakephp

从cakephp的官方网站(
http://cakephp.org )下载一个最新版本(cakephp-cakephp-2.5.0-0-g780132f.zip),

解压后把app、lib、plugins、vendors、index.php等复制或剪切到apache服务器的documentroot或者它下面的某个目录,我这里假设放在E:/htdocs目录下。

1.1 进入app/config/目录,把database.php.default重命名为database.php,打开这个文件就可以看到关于数据库用户名密码之类的设置了。

Note:Makesure the database has been created in MySQL, and tMy configurations are asbelow.

public $default = array(

'datasource'=> 'Database/Mysql',

'persistent' =>false,

'host' =>'127.0.0.1',

'login' => 'root',

'password' =>'yourpassword',,

'database' =>'testcakephp',
//Makesure the table hasbeen created in MySQL

'prefix' => '',

//'encoding' =>'utf8',

);

public $test = array(

'datasource' =>'Database/Mysql',

'persistent' =>false,

'host' =>'127.0.0.1',

'login' => 'root',

'password' => ''yourpassword'',

'database' =>'testcakephp',

'prefix' => '',

//'encoding' => 'utf8',

);

1.2 进入app/config/目录,修改core.php文件中的Security.salt和Security.cipherSeed变量,对应后面的字符串没有限制,只要不与原来相同即可。

Before:

Configure::write('Security.salt','DYhG93b0q365475676niR2G0FgaC9mi');

Configure::write('Security.cipherSeed','7685930965745sfdgdfgh35424963645');

After:

Configure::write('Security.salt','DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaCvob');

Configure::write('Security.cipherSeed','76859309657453542496749683123');

2 配置Apache

2.1 Change thedirectory

Note: Please notice that thedirectory in your side may be different with that of me.

将原来的目录,

DocumentRoot "E:/htdocs "

<Directory "E:/htdocs">

修改为

DocumentRoot"E:/htdocs/app/webroot"

<Directory"E:/htdocs/app/webroot">

1.2 Enable Rewrite

Cakephp的url传参数的时候不是用平常的get格式,而是用controlleraction名后面的“/”分隔的字符作为这个controlleraction的参数(action是一个函数)。也因为这样,需要apache服务器支持rewrite,

First,

在httpd.conf里使能LoadModulerewrite_module modules/mod_rewrite.so,即把前面的#去掉,或者直接添加一句。

Second,

在httpd.conf找到<Directory>,有两处:

Change the following settings

<Directory />

Options FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all

</Directory>

to

<Directory />

Options FollowSymLinks

AllowOverride all

# Order deny,allow

# Deny from all

</Directory>

Change the following settingsto

<Directory"E:/htdocs/app/webroot">

Options FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all

</Directory>

to

<Directory"E:/htdocs/app/webroot">

Options FollowSymLinks

AllowOverride all

# Order deny,allow

# Deny from all

</Directory>

3 安装调试工具

如果不安装,则测试的时候会看到下面的内容。不过如果不需要调试也可以不安装。

DebugKit is not installed. Itwill help you inspect and debug different aspects of your application.

You can install it from
GitHub

下载:从GitHub
下载最新的release branch上的2.2.3,

安装:
GitHub的Installer步骤

------------------------------------------------------------------------------------------------------------

Clone/Copy the files in this directory into app/Plugin/DebugKit

Thiscan be done with the git submodule command

git submodule addhttps://github.com/cakephp/debug_kit.git app/Plugin/DebugKit

Ensure the plugin is loaded in app/Config/bootstrap.php by calling CakePlugin::load('DebugKit');

Include the toolbar component in your app/Controller/AppController.php:

class AppController extends Controller{

public $components = array('DebugKit.Toolbar');

}

Set Configure::write('debug', 1); in app/Config/core.php.

Make sure to remove the 'sql_dump' element from your layout (usually app/View/Layouts/default.ctp if you want to experience the awesome that is the debug kit SQL log.

----------------------------------------------------------------------------------------------------------

3.1
解压到app/Plugin/下,并且把文件名更名为DebugKit。

3.2
修改app/Config/bootstrap.php文件,添加以下两行代码:

CakePlugin::loadAll(); // Loads all plugins at once

CakePlugin::load('DebugKit'); //Loads a single plugin named DebugKit

3.3 app/Controller/AppController.php文件,改为如下代码:

class AppController extendsController {

public $components = array('DebugKit.Toolbar'); //添加此句

}

3.4
修改app/Config/core.php文件,找到Configure::write('debug',2),将其修改为1,即开发级别

Configure::write('debug', 1);

3.5
如果你希望能够看到sql的log的话,打开app/View/Layouts/default.ctp文件,找到如下代码并将其删掉即可:

<?php echo $this->element('sql_dump'); ?>

4 测试

打开http://127.0.0.1/,看到“CakePHPis able to connect to the database”的说明配置成功了。

Release Notes for CakePHP2.5.0

Your version of PHP is 5.2.8or higher.

Your tmp directory iswritable.

The FileEngine is being usedfor core caching. To change the config edit APP/Config/core.php

Your database configurationfile is present.

CakePHP is able to connect tothe database.

DebugKit plugin is present
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: