@blog.justoneplanet.info

JavaScript、PHP、MySQLを使ったり

CentOSにおけるパッケージインストールまとめ

■ソースからインストール

ソースパッケージをダウンロードしてコンパイル・ビルド。(gcc・・・)

【メリット】

  • 環境に依存したどうこうに関係なくインストールできる。

インストールするときにインストールするマシン自身が自分でビルドする為。

【デメリット】

  • 「依存関係」の考慮が必要で面倒
  • 必要な他プログラムなどあれば別途自分でインストールする等

■RPMでインストール

あらかじめ別のマシンでコンパイルしたものをそのままコピーする。

【メリット】

  • 自分でコンパイルしないだけ簡単

【デメリット】

  • コンパイルしたマシンと環境が異なる場合は使えない
  • コンパイルしたマシンで指定したオプションに限定され、必要なオプションが指定できない
  • パッケージはあらゆる人が公開してるから、探したりダウンロードしたり記録したり、などが面倒

■yumでインストール

パッケージ群を公開しているリポジトリからRPMを探し、ダウンロードして、インストールしてくれるツール

【デメリット】

  • 依存関係や付属プログラムや、そもそもそれらの有無なども、すべて他人が決めたもの
  • たくさんのリポジトリを参照するようにyumに追加設定すると依存関係のトラブルが起きたりする

【ポイント】

リポジトリは信頼できるところにしておいたほうが良い。

  • ~redhat.com
  • 有名どころとか
  • 各ディストリビューションのベンダーなど・・・

Windows XPでPHPとimageMagickを使用する

■ImageMagick

以下のサイトからWindows版をダウンロードしてインストールする。

http://www.imagemagick.org/script/binary-releases.php?ImageMagick=pjjjn3udinf3ldej2osq7k8nj1#windows

Program Files配下などのスペースを含むパスにインストールせず、cドライブ直下が望ましいらしい。

環境変数

設定>コントロールパネル>システム>詳細設定>環境変数>システム環境変数

変数名はMAGICK_HOMEとし値はインストールしたパスを入力する。

■Microsoft Visual C++ 2005 SP1

以下のサイトからインストール

http://www.microsoft.com/downloads/details.aspx?familyid=200B2FD9-AE1A-4A14-984D-389C36F85647&displaylang=ja

■php_imagick

以下のサイトからインストールする。

http://www.sk89q.com/2010/03/vc6-windows-binaries-for-imagick-2-3-0/

リンクが切れている場合はここ

上手くいかない場合は以下のサイトのdllを使用した方が良いかもしれない。

http://valokuva.org/?page_id=50

extension_dir = "C:\xampp\php\ext"

php.iniが上述のような場合は「C:\xampp\php\ext」にファイルを配置する。

php.ini

以下の設定を追加(パスは環境に合わせて変更してください)

extension=php_imagick.dll

Windowsを再起動すると使用可能になる。

CentOSにSubversionをインストールする

■インストール

yumでサクッとインストールだ!

yum install subversion

■リポジトリの作成

以下のようにするとhogeディレクトリが生成される。

mkdir -p /home/svn/repos/
cd /home/svn/repos/
mkdir hoge
svnadmin create hoge

adminユーザでコミットするなら以下のようにしておく。。。

chown -R admin:admin hoge
chmod -R 0700 hoge

複数ユーザがコミットするときはグループとかで管理しないとなー

Redisをインストールする

■コマンド

wget http://redis.googlecode.com/files/redis-1.2.6.tar.gz
tar xvzf redis-1.2.6.tar.gz
cd redis-1.2.6
make

make完了!

エラー

以下のようなエラーが出るかもしれない。

cc -c -std=c99 -pedantic -O2 -Wall -W -g -rdynamic -ggdb   adlist.c
make: cc: コマンドが見つかりませんでした
make: *** [adlist.o] エラー 127
対策

gccのインストールだ。

yum install gcc

■管理

/usr/local/libに移動することにした。

mv redis-1.02 /usr/local/lib/redis-1.02
mv redis-1.2.6 /usr/local/lib/redis-1.2.6
ln -s /usr/local/lib/redis-1.2.6/ /usr/local/lib/redis

■操作

起動

以下のコマンドでRedisサーバが起動する。

/usr/local/lib/redis-server

操作

以下のコマンドでRedisを操作する。

/usr/local/lib/redis-cli set mykey somevalue
#OK
/usr/local/lib/redis-cli get mykey
#somevaalue

停止

以下のコマンドでRedisを停止できる。

/usr/local/lib/redis-cli shutdown

■PHPからの使用

phpredis

http://github.com/owlient/phpredis

phpizeが必要になるかもしれないがインストールされていないかもしれない。そんな時は以下のコマンドを実行する。

yum install php-devel

以下のコマンドを実行するとインストールできる。

wget http://github.com/owlient/phpredis/tarball/master
tar xvzf owlient-phpredis-1.2.0-46-g66ac97b.tar.gz
cd owlient-phpredis-66ac97b/
phpize
./configure
make
make install

以下のように表示されるが、まだ使用不可能である。

Installing shared extensions:     /usr/lib/php/modules/

ちゃんとPHPに組み込まないとね。(*^◇^)/゚

cp /etc/php.d/dbase.ini /etc/php.d/redis.ini

/etc/php.d/redis.iniには以下のように記述する。

; Enable redis extension module
extension=redis.so

apacheを再起動する。

/etc/init.d/httpd restart

以下のコマンドを実行して確かめる。

php -r 'var_dump(get_declared_classes());'
array(54) {
  [0]=>
  string(8) "stdClass"
  [1]=>
  string(9) "Exception"
  [2]=>
  string(14) "ErrorException"
  [3]=>
  string(11) "LibXMLError"
  [4]=>
  string(22) "__PHP_Incomplete_Class"
  [5]=>
  string(15) "php_user_filter"
  [6]=>
  string(9) "Directory"
  [7]=>
  string(16) "SimpleXMLElement"
  [8]=>
  string(25) "RecursiveIteratorIterator"
  [9]=>
  string(16) "IteratorIterator"
  [10]=>
  string(14) "FilterIterator"
  [11]=>
  string(23) "RecursiveFilterIterator"
  [12]=>
  string(14) "ParentIterator"
  [13]=>
  string(13) "LimitIterator"
  [14]=>
  string(15) "CachingIterator"
  [15]=>
  string(24) "RecursiveCachingIterator"
  [16]=>
  string(16) "NoRewindIterator"
  [17]=>
  string(14) "AppendIterator"
  [18]=>
  string(16) "InfiniteIterator"
  [19]=>
  string(13) "EmptyIterator"
  [20]=>
  string(11) "ArrayObject"
  [21]=>
  string(13) "ArrayIterator"
  [22]=>
  string(22) "RecursiveArrayIterator"
  [23]=>
  string(11) "SplFileInfo"
  [24]=>
  string(17) "DirectoryIterator"
  [25]=>
  string(26) "RecursiveDirectoryIterator"
  [26]=>
  string(13) "SplFileObject"
  [27]=>
  string(17) "SplTempFileObject"
  [28]=>
  string(17) "SimpleXMLIterator"
  [29]=>
  string(14) "LogicException"
  [30]=>
  string(24) "BadFunctionCallException"
  [31]=>
  string(22) "BadMethodCallException"
  [32]=>
  string(15) "DomainException"
  [33]=>
  string(24) "InvalidArgumentException"
  [34]=>
  string(15) "LengthException"
  [35]=>
  string(19) "OutOfRangeException"
  [36]=>
  string(16) "RuntimeException"
  [37]=>
  string(20) "OutOfBoundsException"
  [38]=>
  string(17) "OverflowException"
  [39]=>
  string(14) "RangeException"
  [40]=>
  string(18) "UnderflowException"
  [41]=>
  string(24) "UnexpectedValueException"
  [42]=>
  string(16) "SplObjectStorage"
  [43]=>
  string(19) "ReflectionException"
  [44]=>
  string(10) "Reflection"
  [45]=>
  string(18) "ReflectionFunction"
  [46]=>
  string(19) "ReflectionParameter"
  [47]=>
  string(16) "ReflectionMethod"
  [48]=>
  string(15) "ReflectionClass"
  [49]=>
  string(16) "ReflectionObject"
  [50]=>
  string(18) "ReflectionProperty"
  [51]=>
  string(19) "ReflectionExtension"
  [52]=>
  string(5) "Redis"
  [53]=>
  string(14) "RedisException"
}

(^○^)お!(^□^)め!(^◇^)で!(^▽^)と!(^・^)う!

サンプルコード
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

■起動スクリプト

/usr/local/lib/redis/redis.conf

Redisはデフォルトではデーモンとして動作しないので、設定ファイルを以下のように編集する。

daemonize yes

スクリプト

http://blog.fulltext-search.biz/archives/2010/04/redis-server-initialize-script-for-centos.html

/etc/profileを編集して任意のコマンドを通す

/etc/profile

以下の行の下あたりがいいかな(。・ω・)ノ

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

以下の行を付加する。

export PATH=$PATH:/usr/local/cassandra/bin

任意のコマンドが使えるようになる。

cassandra-cli

上述のコマンドで全ユーザがコマンドcassandraを使用できる。任意のユーザに限定する場合は各ユーザのホームディレクトリの.bash_profileファイルに追記すれば良い。

参考

パス(PATH)の確認と設定方法は?