いよいよComposerとかを入れて環境を仕上げるの巻

だいぶ疲れてきましたがあとちょっとです。
多分これが最終回。

Composerと今回使いたかったrodneyrehm/plistとついでにごにょごにょ。


まず何はともあれComposerをいれなければ始まりませんので入れてしまいます。
[cc lang=”teraterm”]
[root@centos src]# cd ~
[root@centos ~]# curl -sS https://getcomposer.org/installer | php
#!/usr/bin/env php
Some settings on your machine may cause stability issues with Composer.
If you encounter issues, try to change the following:

Your PHP (5.3.3) is quite old, upgrading to PHP 5.3.4 or higher is recommended.
Composer works with 5.3.2+ for most people, but there might be edge case issues.

Downloading…

Composer successfully installed to: /root/composer.phar
Use it: php composer.phar
[root@centos ~]#
[/cc]

まてまてwww
/root
はないだろwwwww

/usr/local/bin/
あたりでいいですかね。

[cc lang=”teraterm”]
[root@centos ~]# rm composer.phar
rm: remove 通常ファイル ‘composer.phar’? y
[root@centos ~]# cd /usr/local/bin/
[root@centos bin]# curl -sS https://getcomposer.org/installer | php
#!/usr/bin/env php
Some settings on your machine may cause stability issues with Composer.
If you encounter issues, try to change the following:

Your PHP (5.3.3) is quite old, upgrading to PHP 5.3.4 or higher is recommended.
Composer works with 5.3.2+ for most people, but there might be edge case issues.

Downloading…

Composer successfully installed to: /usr/local/bin/composer.phar
Use it: php composer.phar
[root@centos bin]# ln -s composer.phar composer
[root@centos bin]#
[/cc]

動作確認。
[cc lang=”teraterm”]
[root@centos bin]# cd ~
[root@centos ~]# composer
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version e126c925258e6920433b9c57d97042025754dff1 2013-11-22 15:17:02

Usage:
[options] command [arguments]

Options:
–help -h Display this help message.
–quiet -q Do not output any message.
–verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
–version -V Display this application version.
–ansi Force ANSI output.
–no-ansi Disable ANSI output.
–no-interaction -n Do not ask any interactive question.
–profile Display timing and memory usage information
–working-dir -d If specified, use the given directory as working directory.

Available commands:
about Short information about Composer
archive Create an archive of this composer package
config Set config options
create-project Create new project from a package into given directory.
depends Shows which packages depend on the given package
diagnose Diagnoses the system to identify common errors.
dump-autoload Dumps the autoloader
dumpautoload Dumps the autoloader
global Allows running commands in the global composer dir ($COMPOSER_HOME).
help Displays help for a command
init Creates a basic composer.json file in current directory.
install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
licenses Show information about licenses of dependencies
list Lists commands
require Adds required packages to your composer.json and installs them
run-script Run the scripts defined in composer.json.
search Search for packages
self-update Updates composer.phar to the latest version.
selfupdate Updates composer.phar to the latest version.
show Show information about packages
status Show a list of locally modified packages
update Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
validate Validates a composer.json
[root@centos ~]#
[/cc]

おk.

次にアプリケーションルートディレクトリにcomposer.jsonを作るわけですが、
VirtualBoxのフォルダ共有機能を使用して、CentOSにWindowsのフォルダーをマウントさせます。

前回だか前々回だか忘れましたが、Guest Additionsを入れたのはこれのためと言っても過言ではないでしょう…
入れておかないとそんなファイルタイプしらねーっす!って怒られます。

[デバイス→共有フォルダー設定…]
フォルダーのパス:[c:\foo\bar]
フォルダー名:[bar]
[ ]読み取り専用
[*]自動マウント
[*]永続化する

これでCentOSを再起動すると、勝手に/media/sf_barにc:\foo\barがマウントされます。

ここで地味に厄介なのが、sf_bar配下の所有権がroot:vboxsfになります。
もしroot以外で作業するならvboxsfグループにユーザを所属させてあげましょう。
(今回はローカルな環境なのでrootしか使う予定なし!)

マウントできたらWindows側でcomposer.jsonを作ります。
[cc lang=”javascript”]
{
“require”: {
“rodneyrehm/plist”: “dev-master”
}
}
[/cc]

(余談)今回のフォルダ構成は…
[cc lang=”teraterm”]
.
├── application
│   └── composer.json
└── public
└── index.php
[/cc]
こんな感じ。

Apacheのaliasでpublicを公開フォルダにします。
/etc/httpd/conf.d/bar.conf
[cc lang=”apache”]
Alias /bar/ “/media/sf_bar/public/”

Options ExecCGI Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

[/cc]
[cc lang=”teraterm”]
[root@centos conf.d]# /etc/init.d/httpd restart
httpd を停止中: [ OK ]
httpd を起動中: httpd: Could not reliably determine the server’s fully qualified domain name, using centos.kurosuke.org for ServerName
[ OK ]
[root@centos conf.d]#
[/cc]

さて、いよいよ目的であったrodneyrehm/plistのインストールです。
[cc lang=”teraterm”]
[root@centos application]# cd /media/sf_bar/application/
[root@centos application]# composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
– Installing rodneyrehm/plist (dev-master 80e965a)
Cloning 80e965a5ca0185f3a87295d03eb9becfd96fe862

Writing lock file
Generating autoload files
[root@centos application]#
[/cc]
すんなり成功。
Development Toolsを入れてあるのでgitとかもひとしきり入ってますしね。

これでapplication配下にvendorというフォルダーが出来、その配下にもごもごとファイルが配置されました。
PHPからvendor/autoload.phpを読みこめばおkです。

[cc lang=”php”]
add($dict = new CFDictionary());
$dict -> add(‘Name’, new CFString(‘xxxkurosukexxx’));

var_dump($plist -> toArray());
[/cc]

で、ホストマシンのブラウザからhttp://localhost:8080/bar/にアクセス!

Forbidden

You don’t have permission to access /plist/ on this server.

ちーん。。。
なむなむ。。。。。

さっき自分で

ここで地味に厄介なのが、sf_bar配下の所有権がroot:vboxsfになります。
もしroot以外で作業するならvboxsfグループにユーザを所属させてあげましょう。
(今回はローカルな環境なのでrootしか使う予定なし!)

と声高々に宣言しました。
が。

apacheユーザがreadできなかったです… :(

[cc lang=”teraterm”]
[root@centos ~]# usermod -a -G vboxsf apache
[root@centos ~]# /etc/init.d/httpd restart
httpd を停止中: [ OK ]
httpd を起動中: httpd: Could not reliably determine the server’s fully qualified domain name, using centos.kurosuke.org for ServerName
[ OK ]
[root@centos ~]#
[/cc]

で、ホストマシンのブラウザからhttp://localhost:8080/bar/にアクセス!

array(1) {
[“Name”]=>
string(14) “xxxkurosukexxx”
}

できた :)

[cc lang=”teraterm”]
.
├── application
│   ├── composer.json
│   ├── composer.lock ←インストールされた物のバージョン情報とかが記載されている
│   └── vendor ←インストールされたブツたちが格納される
└── public
└── index.php
[/cc]

さて、長々となりましたがこれでようやく環境が整いました。
ちょうどおやつの時間になりそうですね。

長々とお付き合いいただきありがとうございますた。
ここわかりづれーよ!ってツッコミお待ちしております。

(ボクもググりながら実際にやりながらせっせと記事にコピペしてたのでわかりきってない部分もありますが…)

ではまたそのうち。

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください