Cakephp是一套MVC Framework,它很容易安裝,也是我有在使用的PHP MVC Framework,以下是安裝步驟
一、先把LAMP開發環境架構安裝好
可參考此篇文章
在ubuntu(12.0LTS)上安裝Apache+Php+Mysql+Phpmyadmin
二、下載Cakephp
可至Cakephp的Github上下載
https://github.com/cakephp/cakephp/tags
下載後解壓縮至妳的網站跟目錄即可。
之後打開網址可能會出現以下錯誤
Warning: _cake_core_ cache was unable to write 'cake_dev_zh-tw' to File cache in /var/www/cake/lib/Cake/Cache/Cache.php on line 310 Warning: /var/www/cake/app/tmp/cache/persistent/ is not writable in /var/www/cake/lib/Cake/Cache/Engine/FileEngine.php on line 337 Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured.' in /var/www/cake/lib/Cake/Cache/Cache.php:166 Stack trace: #0 /var/www/cake/lib/Cake/Cache/Cache.php(136): Cache::_buildEngine('_cake_core_') #1 /var/www/cake/app/Config/core.php(336): Cache::config('_cake_core_', Array) #2 /var/www/cake/lib/Cake/Core/Configure.php(78): include('/var/www/cake/a...') #3 /var/www/cake/lib/Cake/bootstrap.php(171): Configure::bootstrap(true) #4 /var/www/cake/app/webroot/index.php(97): include('/var/www/cake/l...') #5 /var/www/cake/index.php(43): require('/var/www/cake/a...') #6 {main} thrown in /var/www/cake/lib/Cake/Cache/Cache.php on line 166
有點噁心的字串,原因在於目錄權限沒有打開
將以下目錄權限更正為777
chmod 777 app/tmp/cache
chmod 777 app/tmp/cache/persistent
chmod 777 app/tmp/cache/models
到了這步驟應該可以看到Cakephp預設畫面,但還是有很多錯誤,原因是因為Cakephp沒有配置好,請看第三步驟。
三、配置Cakephp
a.首先至app/Config/core.php修改以下兩行程式碼
Configure::write(‘Security.salt’, ‘DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi’);
Configure::write(‘Security.cipherSeed’, ‘76859309657453542496749683645’);
將後面的亂數值更正成其他的即可。
b.修正URL Rewrite
這部分請參考Cakephp官網說明:
http://book.cakephp.org/2.0/en/installation/url-rewriting.html
這部分有點複雜,基本上就是參考上面Cakephp官方網站說明修改即可,若有問題就請教google大神吧。
c.連結Database
將app/Config/database.php.default複製一份為database.php
然後編輯database.php,將裡面的database連結設定好即可。
d.將app/tmp修改為可寫入
chmod 777 app/tmp
e.將app/tmp/logs目錄修改為777
chmod 777 app/tmp/logs
四、最後測試
最後開啟網域
http://yourdomain.com/index
應該會看到預設的Cakephp error page
Missing Controller Error: IndexController could not be found. Error: Create the class IndexController below in file: app/Controller/IndexController.php class IndexController extends AppController { }
上面的意思是你沒有建立IndexController
從這一步開始就可以開始建立你的Cakephp 網站囉。