2010年10月15日 #sqlite #ruby #rails #linux

経緯

何も考えずにGemfileにsqlite3を定義してbundleを流したらこんなエラーが出ました。

$ gem install sqlite3-ruby
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3-ruby:
        ERROR: Failed to build gem native extension.

/home/user/.rvm/rubies/ruby-head/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal' or 'yum install sqlite3-devel'
###  extconf.rb failed ###
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/user/.rvm/rubies/ruby-head/bin/ruby
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/lib


Gem files will remain installed in /home/user/.rvm/gems/ruby-head/gems/sqlite3-ruby-1.3.0 for inspection.
Results logged to /home/user/.rvm/gems/ruby-head/gems/sqlite3-ruby-1.3.0/ext/sqlite3/gem_make.out

キーのメッセージは「sqlite3.h is missing. Try 'port install sqlite3 +universal' or 'yum install sqlite3-devel'」なのでそのとおりコマンドを流しましたが、portはそのコマンドがないと、yumはsqlite3-develを見つからないと返事したんです。。。

なのでsqlite本家でソースをダウンロードしビルドしてインストールする必要があります。

sqlite3のインストール

http://www.sqlite.org/download.htmlからsqlite-amalgamation-x.x.x.tar.gz(この記事を書いてる時点では3.7.3)のTarballバージョンのファイルをダウンロードします。上から二番目のリンクです。

$ wget http://www.sqlite.org/sqlite-amalgamation-3.7.3.tar.gz
$ tar vxzf sqlite-amalgamation-3.7.3.tar.gz
$ cd sqlite-amalgamation-3.7.3
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

sqlite-ruby gemのインストール

後は普通にgem installでもいいしbundle installでもOKです。

$ gem install sqlite3-ruby
2010年10月 4日 #linux

ターミナルの自動補完でTabキーを使ってますが、よくビープ音が鳴ってうるさいです。。それを消去する方法です。

「効果音の設定」ダイアログが表示されるので「ビープ音」タブをクリックし「システムビープ音を有効にする(E)」のチェックを無効にし、「閉じる©」ボタンを押下。

Menu-sound

Disable-beep

2010年10月 3日 #linux #vmware

VMware Player/ WorkstationでゲストOS(ここではCentOS)をインストールした後、ホストOSとクリップボードを共有するためにはVMware Toolsをインストールする必要があります。

インストール

VMware ToolsはゲストOS、つまり仮想マシン上のOSにインストールします。
VMware Player/Workstationのメニューから VM-> VMware Toolsのインストールを選択します。
出てくるダイアログに従ってファイルをダウンロード、解凍、インストールファイルの実行でやればいいです。インストールが成功すればクリップボードの共有は自動的に有効になるはずです。

おまけに

VMware Toolsをインストールするときディスプレイの解像度を設定できます。インストール後も自由に変更できるようになります。
もう一つはVMwareのウィンドウから透明切り替えができるようになります。

2010年9月25日 #mac #php #環境構築 #smarty

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

2010年9月25日 #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

2010年9月25日 #php #php #smarty

Smarty templateの作成

application/viewsにhello.tplというファイルを作成します。

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>{$title}</title>
</head>
<body>
    hello, {$name}
</body>
</html>

Controllerの作成

hello.phpというControllerを作成します。

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Hello extends Controller {

    public function action_index()
    {
        $view = View::factory("smarty:hello");
        $view->name = "kinopyo!";
        $view->title = "Smarty & Kohana Sample";
        $this->request->response = $view;
    }
}

View::factoryに"smarty:"というプリフィックスを書くことでSmartyテンプレートとして認識してくれます。

動作確認

http://127.0.0.1/myapp/helloにアクセスし、"hello, kinopyo!"が表示されれば成功です。

Controller_Templateの場合

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Hello extends Controller_Template {

    public $template = 'smarty:hello';

    public function action_index()
    {
        $this->template->name = 'kinopyo!';
        $this->template->title = "Hello Title";
    }

}
2010年9月24日 #php #php #環境構築 #memcache

前提条件

memcacheとphp_memcache extensionがインストールされたこと。
http://www.kinopyo.com/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からテスト用のコードを削除してください。

2010年9月24日 #mac #php #php #環境構築 #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
2010年9月20日 #mac #svn #環境構築

The command contextual menu

The command contextual menu.

Repository checkout

Repository checkout.
For more screenshots
Download

After download, drag the application to the Finder toolbar.

日本語

The command contextual menu

コンテキストメニューであらゆるコマンドが実行できる。

Repository checkout

リポジトリチェックアウト.

For more screenshots
Download

ダウンロードしたらApplicationフォルダからアイコンをFinderのツールバーにドラッグしてね。

参考サイト:
http://blog.creamu.com/mt/2009/04/macsvn2.html