AB Lab

abgata20000 blog.

PHPでmongodbを使えるようにする

依存パッケージをインストール

1
2
3
4
5
sudo yum -y install php-pear
sudo yum -y install php-devel
sudo yum -y install httpd-devel
sudo yum -y install gcc
sudo yum -y install make

pcelでインストール

1
pecl install mongo

mongodb用の設定ファイルを追加

1
vim /etc/php.d/mongo.ini
/etc/php.d/mongo.ini
1
2
[mongo]
extension=mongo.so

apacheを再起動して設定を反映

1
service httpd restart

Gemでインストールするもの

とりあえずインストールしておくと便利そうなものをピックアップ

gem install sinatra
gem install sinatra-contrib
gem install sqlite3
gem install bundler
gem install haml
gem install activerecord
gem install wsse
gem install xml-simple
gem install nokogiri

gem install unicorn

gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
gem install mysql2 -- --with-mysql-config=/usr/bin/mysql_config


gem install activerecord-mysql-adapter
gem install activerecord-mysql2-adapter

↓のコマンド実行しないとシンボリックが生成されない??

rbenv rehash

GitのプッシュでHPの更新(反映)

gitのグローバル設定

1
2
3
git config --global user.name "abgata20000"
git config --global user.email "abgata@abgata.jp"
git config --global color.ui true

gitの設定確認

1
git config -l

現在のディレクトリを共有リポジトリにする

1
git init --bare --share

レポジトリをクローンする

1
git clone /git/smaple.git

pushされた際のhooks(post-receive)

1
2
cd hooks
vim post-receive
post-receive
1
2
3
#!/bin/sh
cd /var/www/vhosts/
git --git-dir=.git pull origin master

実行権限を付与

1
chmod +x post-receive

Rubyをapacheで稼働する

passengerをインストール

1
2
3
4
5
6
7
8
9
10
11
12
gem install passenger

passenger-install-apache2-module
# パスとおっていない場合は場所を探す

sudo find / -name passenger-install-apache2-module

sudo yum install -y curl-devel

/usr/local/rbenv/versions/2.0.0-p247/bin/passenger-install-apache2-module

# 3回くらい質問されるがとりあえずenter連打

インストール完了後のコメント

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
The Apache 2 module was successfully installed.

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /usr/local/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.17/buildout/apache2/mod_passenger.so
   PassengerRoot /usr/local/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.17
   PassengerDefaultRuby /usr/local/rbenv/versions/2.0.0-p247/bin/ruby

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!

Press ENTER to continue.


--------------------------------------------
Deploying a Ruby on Rails application: an example

Suppose you have a Rails application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:

   <VirtualHost *:80>
      ServerName www.yourhost.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /somewhere/public
      <Directory /somewhere/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </Directory>
   </VirtualHost>

And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:

  /usr/local/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.17/doc/Users guide Apache.html

Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
https://www.phusionpassenger.com

Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.

apacheの設定ファイルを変更白みたいなことが書いてあるので変更する

1
vim /etc/httpd/conf.d/passenger.conf
/etc/httpd/conf.d/passenger.conf
1
2
3
LoadModule passenger_module /usr/local/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.17/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.17
PassengerDefaultRuby /usr/local/rbenv/versions/2.0.0-p247/bin/ruby

apahceの設定ファイルでドキュメントルート、バーチャルホストを変更

1
vim /etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd.conf
1
DocumentRoot /var/www/ruby/public

ドキュメントルートのディレクトリ作成

1
2
3
4
5
cd /var/www
mkdir ruby
cd ruby
mkdir public
mkdir tmp

実行用の設定ファイル作成

1
vim config.ru
config.ru
1
2
3
4
5
6
require 'bundler'
Bundler.require

require './app'

run App

実行用ファイルの作成

1
2
3
4
5
6
7
8
9
class App < Sinatra::Base
  register Sinatra::Reloader

  get '/' do
      #
      'hello sinatra by apache.'

  end
end

webブラウザ等でアクセスしてみる

Padrinoの使い方

1
2
3
4
5
6
padrino generate project rss -t shoulda -e haml -c sass -s jquery -d mongoid


padrino generate project rss3 -t shoulda -e haml -c sass -s jquery -d activerecord

padrino generate project rss4 -t shoulda -e haml -c scss -s jquery -d activerecord -a mysql2 -b

テンプレートを使ってプロジェクトを作成

1
padrino g project sample001 --template template.rb && cd sample001

Accountモデルを作成

1
2
3
4
padrino g model Account provider:string uid:string name:string email:string role:string token:string

padrino rake ar:create
padrino rake ar:migrate