2014年3月31日月曜日

[Sublime Text]SublimeTextXdebugでcontext画面で変数の深い階層にnestされた値が見れない時

ここを参考にした。

Edit Projectで以下の値を挿入した。

"max_children": 128,
"max_depth": 3,
"max_data": 512,

[CakePHP]Access forbidden!が出た時

画面に以下の様に出て、
Access forbidden!

要求されたオブジェクトへのアクセス権がありません。 読み込みが許可されていないか、 サーバが読み込みに失敗したかでしょう。

サーバーの障害と思われる場合は、ウェブ管理者までご連絡ください。

Error 403

error_logに以下のように出てる時、

[Mon Mar 31 18:07:45.124983 2014] [authz_core:error] [pid 35957] [client 127.0.0.1:51200] AH01630: client denied by server configuration: /path/to/git/inqueue/home

対象アプリのhttpd.confのDirectoryタグ、virtulhostを利用している場合は、httpd-vhosts.confのVirtualHostタグ内のDirectoryタグに、以下を入れる。

Require all granted

[xdebug]php.iniの設定

PHP:  syntax error, unexpected $end, expecting TC_DOLLAR_CURLY or TC_QUOTED_STRING or '"' in /Applications/XAMPP/xamppfiles/etc/php.ini on line 1938

こんな感じのエラーが出た時、xdebugの設定を一番下ではなく、少し上にしてあげるとなぜか直りました。

[CakePHP]pcfg_openfile: unable to check htaccess file, ensure it is readable and that 'app/webroot/' is executable

[Mon Mar 31 13:57:42.425142 2014] [core:crit] [pid 11472] (13)Permission denied: [client ::1:55072] AH00529: /path/to/git/test01/app/webroot/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/path/to/git/test01/app/webroot/' is executable


error_logにこんなようなエラーが出たら、webrootをchmod 777したなおりました。

[XAMPP]xdebug 導入

ここの 「Installation From Source」 「Compiling」を見てインストールしました。
githubから持ってくるやりかたでやりました。

念のため、$PATHに/Applications/XAMPP/binを入れてからやりました。

それのおかげかわかりませんが、compile後、「/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/」というところにxdebug.soができていました。

しかも、php.iniでの指定は、フルパスではなく、以下のようでないとだめみたいです。
zend_extension= xdebug.so

phpinfo()の画面でxdebugのセクションが出来ていればインストール完了です。

[XAMPP]MAMPは無料版だとxdebug導入できなさそうなのでお引っ越し。

MAMPを使っていたんだけど、php.iniでxdebugの設定しても、どうもテンプレートのphp.iniが反映されるようで、使えなかった。
※使い方わかる方教えて下さい。

なのでXAMPP(1.8.3)をインストールしました。

無事に使えました。

2014年3月24日月曜日

[MAMP]MySQLから取得した日本語文字列がクエスチョンマークになる件

※MAMP_MAMP_PRO_3.0.2.pkgを使用

my.cnfを編集しますが、デフォルトではmy.cnfは存在しないので、テンプレートからコピーしてきます。

 cp -p /Applications/MAMP/Library/support-files/my-large.cnf /Applications/MAMP/conf/my.cnf

そして、my.cnfの[mysqld]の直下に以下の2行を追加します。

skip-character-set-client-handshake
character-set-server = utf8

MAMPを再起動します。

以上。





2014年3月16日日曜日

[CakePHP]error.logのfailed to open stream: Permission denied

以下のようなエラーが出た。



なので、以下で対応。

sudo chmod 774 app/tmp/logs/error.log

このあたりを参考にした。

2014年3月14日金曜日

[CakePHP]Console/cake実行時のエラーへの対処

※CakePHP2.4.6を使用

migrationを実行しようとし、以下のコマンドを実行した。

 $ Console/cake Migrations.migration generate

 そしたら次のようなエラーが。

PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in /Users/araky/git/test01/Vendor/cakephp/cakephp/lib/Cake/Cache/CacheEngine.php on line 60
Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in /Users/araky/git/test01/Vendor/cakephp/cakephp/lib/Cake/Cache/CacheEngine.php on line 60
PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in /Users/araky/git/test01/Vendor/cakephp/cakephp/lib/Cake/Cache/CacheEngine.php on line 60
Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in /Users/araky/git/test01/Vendor/cakephp/cakephp/lib/Cake/Cache/CacheEngine.php on line 60
Cake Migration Shell
---------------------------------------------------------------
Do you want generate a dump from current database? (y/n) [y] >

 以下のサイトの通りに対処で消えた。
CakePHPのインストールでエラーを消していく


他のサイトで、php.iniの設定をいじるのがあったけど直らなかった。
また、core.phpではなく、bootstrap.phpに同じ設定を入れてみたが、エラーは消えなかった。

2014年3月13日木曜日

[CakePHP]Composerでインストールした場合のpluginsディレクトリの指定

※CakePHP 2.4.6を使用

ComposerでCakePHPをインストールすると、pluginsフォルダはapp内には入らないのが普通。外に出してライブラリ管理するため。

なので、そのままの設定だと、デフォルトの画面で以下のようなエラーが出る。


なので、以下のようにbootstrap.phpで指定する。

App::build(array(
 'Plugin' => array(
  ROOT .'/plugins/',
 ),
));
CakePlugin::loadAll();

[CakePHP]Composerを使用した場合にApacheのDocumentRootの設定をどうするか

※CakePHP 2.4.6を使用

以下とかでcomposerを使用したCakePHPのインストール方法が紹介されている。

ComposerでCekePHPをインストール¶
CakePHP 2.xをComposerでインストールする

ただ、一つ気に入らない点がある。
ApacheのDocumentRootをapp/webrootに指定しなければならないことだ。
apache側の設定を変えるのは環境依存要因を増やすことになるので嫌だ。

なので、対策を考えた。
プロジェクトのルートディレクトリ(composer.jsonが配置されているディレクトリ)に以下の2ファイルを追加することだ。
これらは、普通に(Composerを使わずに)CakePHPをインストールした場合に、プロジェクトのルートディレクトリに入っているものを使う。ただ、.htaccessはそのままでよいが、index.phpは38行目のみ修正が必要である。

.htaccess

   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]


index.php

<?php
/**
 * Requests collector.
 *
 *  This file collects requests if:
 *	- no mod_rewrite is available or .htaccess files are not supported
 *  - requires App.baseUrl to be uncommented in app/Config/core.php
 *	- app/webroot is not set as a document root.
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */

/**
 *  Get CakePHP's root directory
 */
define('APP_DIR', 'app');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);

/**
 * This only needs to be changed if the "cake" directory is located
 * outside of the distributed structure.
 * Full path to the directory containing "cake". Do not add trailing directory separator
 */
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
	define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'Vendor/cakephp/cakephp/lib');
}

require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';