#ruby #rvm #環境構築

ruby 1.9.2p290へ更新しました。rvmもついでに。

# update rvm  
$ rvm get head  
# or older versions such as 1.0.0  
$ rvm update --head  
# you need to run reload to reflect the update  
$ rvm reload         
$ rvm -v
  rvm 1.7.2 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]

# install ruby 1.9.2.p290  
$ rvm install 1.9.2-p290
  ...  
$ rvm list
  ruby-1.9.2-p0
  ruby-1.9.2-p180  
# you need to replace the p0 based on your environment  
$ rvm upgrade ruby-1.9.2-p0 ruby-1.9.2-p290
yes  
yes  
yes  ...  
Upgrade complete!  
$ rvm list
  ruby-1.9.2-p290 [ x86_64 ]  
$ rvm --default use 1.9.2
$ ruby -v
  ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
git clone https://github.com/enormego/EGOTextMateFullScreen.git /tmp/EGOTextMateFullScreen

xcodebuild -project /tmp/EGOTextMateFullScreen/EGOTextMateFullScreen.xcodeproj -target EGOTextMateFullScreen

cp -R /tmp/EGOTextMateFullScreen/build/Release/EGOTextMateFullScreen.tmplugin ~/Library/Application\ Support/TextMate/PlugIns

# after installed
rm -rf /tmp/EGOTextMateFullScreen/

これが完成図!

Textmate Fullscreen

coffee-scriptをMacportsを使ってインストールし、TextMateのcoffee-script bundleでコンパイルするメモです。 注意すべきなのはたとえターミナルでcoffeeが実行できても、TextMateはPATHをインクルードしないので(インクルードしているのは/usr/binらしい)、/usr/binにcoffeeのシンボリックを作る必要があります。 またcoffee-scriptをコンパイルするにはnodejsとnpm(Node Package Manager)が前提条件となるため、それらのインストールも必要です。

これでtextmateでcommand + Bでコンパイル後のJavascriptが表示できるようになります!

#ruby #mac #sinatra #環境構築

Sinatraを試したところこのようなエラーになりました。

ruby -rubygems myapp.rb
no such file to load -- ubygems (LoadError)

ググッてみたらやはりPATHが間違ったっぽいです。 Macportでrubygemsをインストールすることで解決できるそうです。 その後はgemを再度インストールする必要があるらしいです。 操作の流れ:

#パスの確認
which gem
/usr/bin/gem

sudo port install rb-rubygems
...
# Terminal再起動
# パスの確認
which gem
/opt/local/bin/gem

sudo gem install sinatra

一旦はこれで解決です。

参考になったサイト: http://d.hatena.ne.jp/holypp/20110319/1300556202 http://d.hatena.ne.jp/Kuna/20090315/1237121262

問題

新しい mysqlnd ライブラリは、MySQL 4.1 用の41バイトの新しいパスワードフォーマットを使用します。 古い16バイトのパスワードを使うと、mysql_connect() 系の関数は次のようなエラーメッセージを生成します。”mysqlnd cannot connect to MySQL 4.1+ using old authentication”

MacPortでインストールしたPHP5.3では、

mysqlnd(php5.3のmysql native client)が適用される。 しかし、CentOSなどのyumでインストールできるMySQLサーバーとの相性がよろしくない。 PHP Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using old authentication というエラーが現れ、接続することができません。 mysqlndを利用しないよう再コンパイルが必要となる。

解決方法

portでインストールしたモジュールを確認、mysqlndがactiveなってるはず。

sudo port installed

php5-mysql @5.3.5_0+mysqlnd (active)

そしてmysql5のvariantsを指定で再インストール。

% sudo port install php5-mysql +mysql5

--->  Computing dependencies for php5-mysql
--->  Fetching php5-mysql
--->  Verifying checksum(s) for php5-mysql
--->  Extracting php5-mysql
--->  Configuring php5-mysql
--->  Building php5-mysql
--->  Staging php5-mysql into destroot
--->  Installing php5-mysql @5.3.5_0+mysql5
--->  Deactivating php5-mysql @5.3.5_0+mysqlnd
--->  Cleaning php5-mysql
--->  Activating php5-mysql @5.3.5_0+mysql5
--->  Cleaning php5-mysql

再度port installedで確認すればmysql5がactiveになるはず。これで解決。

php5-mysql @5.3.5_0+mysqlnd
php5-mysql @5.3.5_0+mysql5 (active)

参考

【php】mysqlndを使うとMySQLに接続できない http://www.softel.co.jp/blogs/tech/archives/2225

SnowLeopard + PHP5.3でのMySQLリモート接続 http://taikimen.blogspot.com/2010/10/snowleopard-php53mysql.html

PHP: mysqlnd cannot connect to MySQL 4.1+ using old authentication http://www.bitshop.com/Blogs/tabid/95/EntryId/67/PHP-mysqlnd-cannot-connect-to-MySQL-4-1-using-old-authentication.aspx

おまけ

mysqlが古い16バイトのパスワードを使ってるかを確認する方法です。 mysqlにログインして下記コマンドを実行:

mysql> select password('aa');

+------------------+
| password('aa')         |
+------------------+
| 0123456789abcdef |
+------------------+

16位だっだら古いです。40位なら新しいってことです。

MacportでPHPをインストールし、CakePHPを動かしたら「Strict Standards」エラーが出ました。 当時のエラー本文は残ってませんので、Googleで検索したエラー本文を貼り付けます。パス以外は同じのはずです。

Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/basics.php on line 279
Strict Standards: Redefining already defined constructor for class Object in /Applications/MAMP/htdocs/xxxx/cake/libs/object.php on line 65
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/object.php on line 92
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/inflector.php on line 65
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/configure.php on line 96
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/configure.php on line 154
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/cache.php on line 71
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/cache.php on line 157
Strict Standards: Non-static method Configure::getInstance() should not be called statically in /Applications/MAMP/htdocs/xxxx/cake/bootstrap.php on li

解決方法

これはCakePHPの問題ではなく、PHPのerror_reportingの設定問題だそうです。 php.iniを開いてerror_reportingで検索します。 値をE_ALLに変更すれば解決です。

ちなみにMacportでPHPをインストールしたときのphp.iniパスは/opt/local/etc/php5/php.iniになります。

参考リンク

http://oldblog.awpny.com/2007/12/mamp-php5-cakephp-and-strict-standards/

#php #php #xampp #oracle #環境構築

Oracle Instantclientをインストールすることで、PHPからOracleデータベースへの接続が可能になります。

XAMPPのデフォルトインストールではそれが無効となっています。確認方法はphpinfoのページから’oci8’を検索して何もなかったらつまり接続できてないことです。

手順

  • php.ini(XAMPP/phpのパスにある)の中から;extension=php_oci8.dllを検索して、セミコロン(;)を削除。
  • Oracleから“Instant Client Package – Basic” for Windowsをダウンロードし、任意の場所に解凍。ここではc:\instantclient_11_1とする。
  • Windowsの環境変数pathに上記instantclientが解凍されたパスを追加(c:\instantclient_11_1)
  • そしてWindowsを再起動!
  • Apacheを再起動

確認

phpinfoのページからoci8を検索してあれば成功!

その他

  • ORACLE_HOMEやORACLE_SIDなどの環境変数はInstant Clientでは必要ないから設定しなくても大丈夫だそう。
  • パス設定後Windowsを再起動しないと、”unable to load dynamic library php_oci8.dll”のようなエラーが出た。
#linux #環境構築

環境構築の記事でよく目にすると思いますが このsudoコマンド。 気になってて調べてみたんです。

sudo is a Terminal command used to execute a command as another user, by default, the root user.

あるコマンドを別のユーザとして実行する、デフォルトではルートユーザ、だそうです。

例えばルートユーザとしてあるアプリを実行したい時は:

sudo open ....
#rails #ruby #mac #環境構築

MacにはデフォルトでRubyが入ってそうです。 ターミナルを開いてrails -vを叩いたらバージョン情報が出てきました。

ruby 1.8.7 (2009-06-08 patchlevel 173) *universal-darwin10.0*

そしてRubyだけじゃなくRailsも入ってましてびっくりしました。 すごいですねMacは。。。 て、railsのバージョンもrails -vで確認できますが、 デフォルトのバージョンは古いそうで下記のコマンドでアップグレードできます。

sudo gem update rails

するとこんなログ情報が出ます。

Updating installed gems
Updating rails
WARNING:  Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
	  /usr/bin aren't both writable.
WARNING:  You don't have /Users/zolo/.gem/ruby/1.8/bin in your PATH,
	  gem executables will not run.
Successfully installed activesupport-2.3.8
Successfully installed activerecord-2.3.8
Successfully installed rack-1.1.0
Successfully installed actionpack-2.3.8
Successfully installed actionmailer-2.3.8
Successfully installed activeresource-2.3.8
Successfully installed rails-2.3.8
Gems updated: activesupport, activerecord, rack, actionpack, actionmailer, activeresource, rails
Installing ri documentation for activesupport-2.3.8...
Installing ri documentation for activerecord-2.3.8...
Installing ri documentation for rack-1.1.0...
Installing ri documentation for actionpack-2.3.8...
Installing ri documentation for actionmailer-2.3.8...
Installing ri documentation for activeresource-2.3.8...
Installing ri documentation for rails-2.3.8...
Installing RDoc documentation for activesupport-2.3.8...
Installing RDoc documentation for activerecord-2.3.8...
Installing RDoc documentation for rack-1.1.0...
Installing RDoc documentation for actionpack-2.3.8...
Installing RDoc documentation for actionmailer-2.3.8...
Installing RDoc documentation for activeresource-2.3.8...
Installing RDoc documentation for rails-2.3.8...

多少時間がかかります。 これでMacでのRuby開発の準備は完了です。

更新

gem update railsにsudoを付けないとこんなエラーが出るかも

WARNING:  Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
	  /usr/bin aren't both writable.
WARNING:  You don't have /Users/paku-k/.gem/ruby/1.8/bin in your PATH,
	  gem executables will not run.
ERROR:  Error installing rails:
	bundler requires RubyGems version >= 1.3.6
#php #smarty #mac #環境構築

Smartyのインストールはphp.iniにインクルードパスを書く方法と書かない方法があります。ここではphpのインクルードパスに書く方法を紹介します。

1 Smartyをダウンロード

http://www.smarty.net/download.phpからダウンロードします。今回は3.0rc3にしました。

2 ファイルの解凍

できたフォルダ名はSmarty-3.0rc3で、それをsmartyにリネームして、/Applications/XAMPP/xamppfiles/lib/phpに移動します。こうするのはここがXAMPPの場合のinclude_pathになるからです。

3 php.iniを変更して、smartyを読み込ませる

php.ini中のinclude_pathに”.:/Applications/XAMPP/xamppfiles/lib/php/smarty/libs”の記述を追加します。 できたイメージはこうなります。

include_path=".:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear.:/Applications/XAMPP/xamppfiles/lib/php/smarty/libs"

4 smartyが必要なフォルダを作成します。

smartyは四つのフォルダが必要です:

  • templates
  • templates_c
  • cache
  • config

templates_cとcacheフォルダには適切な書き込み権限を付与しなければなりません。 場所は任意のはずです。ここではこんな形にしました。htdocsはXAMPPのウェブルートフォルダです。

  • /Applications/XAMPP/xamppfiles/htdocs/smarty/templates
  • /Applications/XAMPP/xamppfiles/htdocs/smarty/config
  • /Users/zolo/Develop/smarty/templates_c
  • /Users/zolo/Develop/smarty/cache

5 smartyテンプレートを作成

上記templatesフォルダにsmarty.tplというファイルを作成します。

<html>
<body>
Hello, {$name}!
</body>
</html>

6 テンプレートに値をセットするphpファイルを作成

/Applications/XAMPP/xamppfiles/htdocs/にsmarty.phpというファイルを作成します。

<?php

// load Smarty library
require('Smarty.class.php');

$smarty = new Smarty;

$smarty->template_dir = '/Applications/XAMPP/xamppfiles/htdocs/smarty/templates';
$smarty->config_dir = ' /Applications/XAMPP/xamppfiles/htdocs/smarty/config';
$smarty->cache_dir = '/Users/zolo/Develop/smarty/cache';
$smarty->compile_dir = '/Users/zolo/Develop/smarty/templates_c';

$smarty->assign('name','kinopyo!');

$smarty->display('smarty.tpl');
?>

7 動作確認

php.iniを編集したため、まずはapacheを再起動します。 そしてhttp://127.0.0.1/smarty.phpにアクセスしてエラーがなければOKです。

参考リンク:

http://news.php.net/php.smarty.dev/2703

#php #php #smarty #環境構築

ダウンロード

http://wiki.github.com/MrAnchovy/kohana-module-smarty/

インストール

githubでも手順がとても分かりやすいので直接引用させていただきます。

  1. Download the latest version from the links above
  2. Unpack the downloaded file
  3. Move the smarty directory into the Kohana modules directory
  4. Enable the module in your application’s bootstrap.php
Kohana::modules(array(
  'auth' => MODPATH.'auth', // Basic authentication
  // 'cache' => MODPATH.'cache', // Caching with multiple backends
  // 'codebench' => MODPATH.'codebench', // Benchmarking tool
  'database' => MODPATH.'database', // Database access
  // 'image' => MODPATH.'image', // Image manipulation
  'orm' => MODPATH.'orm', // Object Relationship Mapping
  'pagination' => MODPATH.'pagination', // Paging of results
  'userguide' => MODPATH.'userguide', // User guide and API documentation
  'smarty' => MODPATH.'smarty', // smarty template module.
));
  1. Visit the page www.yoursite.com/smarty to confirm all is OK

その他リンク

このモジュールのファイル構造: http://github.com/MrAnchovy/kohana-module-smarty/wiki/file-structure

#php #php #memcache #環境構築

前提条件

memcacheとphp_memcache extensionがインストールされたこと。 https://kinopyo.com/ja/blog/install-memcache-and-php-extension-in-mac-xampp/を参考してください。

手順

1. application/bootstrap.phpを編集

Kohana::modulesのcacheのコメントを外します。 Kohana active cache in bootstrap.php

2. 下記の内容でconfig/cache.phpを作成

場所はapplication/configでもいいしsystem/config、modules/configでもいいです。

<?php defined('SYSPATH') or die('No direct script access.');
return array
(
	'default'  => array
	(
		'driver'             => 'memcache',
		'default_expire'     => 3600,
		// Use Zlib compression (can cause issues with integers)
		'compression'        => FALSE,
		'servers'            => array
		(
			array
			(
				// Memcache Server
				'host'             => '127.0.0.1',
				// Memcache port number
				'port'             => 11211,
				// Persistent connection
				'persistent'       => FALSE,
			),
		),
	),

);

3. 動作確認

まずはmemcacheを立ち上がってください。(ターミナルでmemcached -m 8 -l 127.0.0.1 -p 11211 -d ) そしてbootstrap.phpの最後にテスト用のコードを追記します。

$cache = Cache::instance();
$cache->set('hello','world');
die(var_dump($cache->get('hello')));

これで任意のページを開いて下記の内容が表示されれば成功ってことです。 string(5) “world”

テスト成功したらbootstrap.phpからテスト用のコードを削除してください。

#php #php #mac #memcache #環境構築

環境情報

  • Mac OSX Snow Leopard 10.6.4
  • XAMPP 1.7.3

手順書

1. Apple Developer Tools (Xcode)の最新版をインストール

2. XAMPP Developer Packageをインストール

http://www.apachefriends.org/en/xampp-macosx.htmlより下記赤線のリンクをダウンロードします。 xampp develop package for mac 参考リンク:http://blog.m-schmidt.eu/2010/03/30/develop-memcached-web-apps-with-xampp-under-mac-os-x/ ダウンロードしたdmgファイルを開いてDevel-Package.mpkgをダブルクリックでインストールします。

3. ターミナルを開いて(/Applications/Utilities/Terminal)下記コマンドを実行

cd /tmp
pecl download memcache
tar xzf memcache-2.2.5.tgz
cd memcache-2.2.5
/Applications/XAMPP/xamppfiles/bin/phpize-5.3.1
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-5.3.1
make
sudo make install

成功したら/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-xxxxのフォルダ(xxは20090626みたいな日付)にmemcache.soというファイルが生成されます。

4. php.iniファイルの編集

/Applications/XAMPP/xamppfiles/etc/php.iniファイルを開いて”Dynamic Extensions”のブロックを検索し、下記内容を追記します。私の環境では538行くらいでした。

extension=memcache.so

こんあ感じです。 Add memcache extention to php.ini

5.memcacheを立ち上がる

ターミナルで下記コマンドを実行します。

memcached -m 8 -l 127.0.0.1 -p 11211 -d

これは自分の環境でmemcacheをIP:127.0.0.1、ポート:11211、8MBのRAMスペースで立ち上がる意味です。

6. phpで動作確認

下記ファイルを用意します。ファイル名は任意です(ここではmemcache.phpとしました)。

<?php

$memcache = memcache_connect('127.0.0.1', 11211);

if ($memcache) {
	$memcache->set("str_key", "String to store in memcached");
	$memcache->set("num_key", 123);

	$object = new StdClass;
	$object->attribute = 'test';
	$memcache->set("obj_key", $object);

	$array = Array('assoc'=>123, 345, 567);
	$memcache->set("arr_key", $array);

	var_dump($memcache->get('str_key'));
	var_dump($memcache->get('num_key'));
	var_dump($memcache->get('obj_key'));
}
else {
	echo "Connection to memcached failed";
}
?>

これを/Applications/XAMPP/xamppfiles/htdocsに置いて、ブラウザでhttp://localhost/memcache.php(あるいはhttp://127.0.0.1/memcache.php)を開きます。 下記のようなページが表示されればOKです。 memcache test in php

ちなみにmemcacheを停止するコマンドは:

killall memcached