msの日記

久しぶりに勉強したくなりプログラミングをは始めてみる。

cakephpにcomposerを使う3

composerを使う利点http://www.engineyard.co.jp/blog/2013/install-cakephp-on-composer/

  1. フレームワークの最新版へのアップデートが自動化される
  2. リポジトリ内にフレームワーク本体を含める必要がなく、シンプルになる
  3. Composerを経由してさらに他のライブラリもインストールし運用できる

$ mkdir ~/Sites/composer_test4

composer_test4のディレクトリにcomposer.jsonを配置

$ vi composer.json
~~~
{
"name": "example-app",
"repositories": [
{
"type": "pear",
"url": "http://pear.cakephp.org"
}
],
"require": {
"pear-cakephp/cakephp": ">=2.3.4"
},
"config": {
"vendor-dir": "Vendor/"
}
}
~~~
$ mkdir vagrant
$ cd vagrant
$ vagrant init
vagrantfileをいじる
~~~

cakephpにcomposerを使う2

composerhttps://github.com/composer/composer
Sites以下にexample_appフォルダを作り、移動。

$mkdir sample_app
$cd sample_app

composerをインストール

$curl -sS https://getcomposer.org/installer | php
#!/usr/bin/env php
Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

えらー。。
phpにoptionをつける

$curl -sS https://getcomposer.org/installer | php -d detect_unicode=off
Composer successfully installed to: Sites/example_app/composer.phar
Use it: php composer.phar

成功!

properties

*name The name of the package. It consists of vendor name and project name, separated by /.
*require packge links:All of the following take an object which maps package names to version constraints.
*repositories By default composer just uses the packagist repository. By specifying repositories you can get packages from elsewhere.
*config A set of configuration options. It is only used for projects.

composer.jsonファイルを新規作成

$vi example_app/composer.json

{
"name": "example-app",
"repositories": [
{
"type": "pear",
"url": "http://pear.cakephp.org"
}
],
"require": {
"pear-cakephp/cakephp": ">=2.4.1"
},
"config": {
"vendor-dir": "Vendor/"
}
}<<

cakephpにcomposerを使う

Composerを使ってCakePHP2.4.1とDebugKitをインストールするまで

  1. PHP5.3.2 ,依存性管理ツール
  2. composerコマンドで必要なライブラリを自動的に集めてくれる
  3. Symfony2の機能だった
  4. 現在はデファクトスタンダード
  5. フレームワークの最新版へのアップデートが自動化される
  6. リポジトリ内にフレームワーク本体を含める必要がなく、シンプルになる
  7. Composerを経由してさらに他のライブラリもインストールし運用できる

vagrantの最新版を使う

gemでvagrant をインストールしたらver.1.0.7。
公式サイトではver.1.3.4。http://www.vagrantup.com/‎

1.3.4を使いたい!!

1.既存のvagrant をuninstall

$gem uninstall vagrant 

rbenvでrubyのヴァージョン違いを使っていたため

The `vagrant' command exists in these Ruby versions:1.9.3-p392

と怒られる。1.9.3-p392に切り替えて再度uninstall。
2.公式サイトからパッケージをインストール。
3.

$ vagrant -v
-bash: /Users/butagorira/.rbenv/shims/vagrant: No such file or directory

あれ?
助けて、他サイトさん!
Vagrant で仮想マシンを管理する
4.vagrant のディレクトリにPATHを通す

$ export PATH=/Applications/Vagrant/bin:$PATH
$ vagrant -v
Vagrant 1.3.4

git clone vagrant

NFS UNIXシステムで利用されるファイル共有システム。Sun Microsystems社によって開発され、UNIX系OSにおける標準的な分散ファイルシステムとなっている。NFSを使うと離れた場所にあるコンピュータのファイルを、あたかも自分のコンピュータにあるファイルのように操作することができる。ファイルを他のコンピュータに提供するコンピュータをNFSサーバ、他のコンピュータにあるファイルを利用するコンピュータをNFSクライアントという。UNIX以外のプラットフォームからも利用することができる。

vagrant Synced Folderのoption :NFS

vagrant ,chef ,git を使いcakephpを立ち上げるまでの道のり。〜脱線2〜

やっと成功。
までの道のり。
vagrantfile

Vagrant::Config.run do |config|
  config.vm.box = "Centi386"
  config.vm.provision :shell, :path => "provision.sh"
  config.vm.network :hostonly, "192.168.33.66"
end

provision.shをvagrantfileと同じディレクトリに配置。

sudo yum -y install httpd
sudo service httpd start
sudo chkconfig httpd on
sudo service iptables stop
sudo chkconfig iptables off 

cakephpをインストール

展開したcakephpフォルダを/vagrant に設置(synced-folder)

[vagrant@localhost ~]$ sudo cp -r cakephp/ /var/www/html
chkconfig サーバー起動時にチェックする項目
auditd         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
blk-availability	0:off	1:on	2:on	3:on	4:on	5:on	6:off
crond          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
dkms_autoinstaller	0:off	1:off	2:on	3:on	4:on	5:on	6:off
htcacheclean   	0:off	1:off	2:off	3:off	4:off	5:off	6:off
httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
ip6tables      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
iptables       	0:off	1:off	2:off	3:off	4:off	5:off	6:off
iscsi          	0:off	1:off	2:off	3:on	4:on	5:on	6:off
iscsid         	0:off	1:off	2:off	3:on	4:on	5:on	6:off
lvm2-monitor   	0:off	1:on	2:on	3:on	4:on	5:on	6:off
mdmonitor      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
multipathd     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
netfs          	0:off	1:off	2:off	3:on	4:on	5:on	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
nfs            	0:off	1:off	2:off	3:off	4:off	5:off	6:off
nfslock        	0:off	1:off	2:off	3:on	4:on	5:on	6:off
postfix        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
puppet         	0:off	1:off	2:off	3:off	4:off	5:off	6:off
rdisc          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
restorecond    	0:off	1:off	2:off	3:off	4:off	5:off	6:off
rpcbind        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
rpcgssd        	0:off	1:off	2:off	3:on	4:on	5:on	6:off
rpcidmapd      	0:off	1:off	2:off	3:on	4:on	5:on	6:off
rpcsvcgssd     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
rsyslog        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
saslauthd      	0:off	1:off	2:off	3:off	4:off	5:off	6:off
sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
udev-post      	0:off	1:on	2:on	3:on	4:on	5:on	6:off
vboxadd        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
vboxadd-service	0:off	1:off	2:on	3:on	4:on	5:on	6:off
vboxadd-x11    	0:off	1:off	2:off	3:on	4:off	5:on	6:off

vagrant ssh

$ vagrant ssh
[vagrant@localhost ~]$ cd /var/www/html
#
[vagrant@localhost ~]$ vi who.php
#<?php echo `whoami` ?>
#192.168.33.66/who.phpで表示される →apache
[vagrant@localhost ~]$  sudo chown -R apache blog/app/tmp

データベース設定などは後述。

/sbin/ifconfig ipアドレスを調べられる

Hosterを使うとipアドレスを楽に扱える。

vagrant ,chef ,git を使いcakephpを立ち上げるまでの道のり。〜脱線〜

chef,gitは置いといてvagrantのみでcakephp起動までする。
cakephpのフォルダを設置する場所がわからない。

SHELL PROVISIONER

Provisioner name: "shell"

The shell provisioner allows you to upload and execute a script as the root user within the guest machine.

vagrantfile編集

Vagrant::Config.run do |config|
config.vm.box = "Cent64"
config.vm.provision :shell,:inline=> "echo Hello, World"
config.vm.network :hostonly, "192.168.22.33"

vagrantfileのディレクトリにprovision.shを配置。

yum -y install httpd
service httpd start
sudo chkconfig httpd on
sudo service iptables stop
sudo chkconfig iptables off