LoginSignup
2
2

More than 5 years have passed since last update.

PHP 5.4 の Web アプリを OpenShift で動かす

Last updated at Posted at 2015-02-22

Mac OS X を使って開発する。

$ sw_vers -productVersion 
10.10.2

Composer を使うには、この記事の手順の後で PHP - OpenShift で Composer を使う - Qiita をやる。MySQL を使うには OpenShift で PHP から MySQL 5.5 を使う - Qiita

事前準備

ssh の鍵を作っておく。後で OpenShift に公開鍵を登録するので。

アプリケーションを作る

(1) OpenShift の無料アカウントを取得する。

Create an account | OpenShift Online by Red Hat から。

(2015/02/22 16:23 現在、アカウント取得後にPCからログインできない。スマートフォンからならログインできる)

(2) アプリケーションのタイプを選ぶ。

カートリッジから PHP 5.4 を選ぶ。

アプリケーション名とネームスペース名を選ぶ。公開されるアプリケーションの URL は

http://<アプリケーション名>-<ネームスペース>.rhcloud.com

となる。以下では、http://foo-bar.rhcloud.com として説明する。

(3) アプリケーションの設定をする

事前に作っておいた ssh の公開鍵を登録する。公開鍵ですよ(秘密鍵じゃないですよ)!

画面に git clone する方法が表示される。

$ git clone ssh://xxxxxxxxx@foo-bar.rhcloud.com/~/git/foo.git/
$ cd foo
$ ls
index.php

この index.php を編集して、git add/commit/push すれば公開される。

$ vi index.php
index.php
<?php
echo "Hello, World\n";
$ git add index.php

$ git commit -m 'first commit'
[master c2ee0b4] first commit
 1 file changed, 2 insertions(+), 274 deletions(-)
 rewrite index.php (100%)

$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 318 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Stopping PHP 5.4 cartridge (Apache+mod_php)
remote: Waiting for stop to finish
remote: Waiting for stop to finish
remote: Building git ref 'master', commit c2ee0b4
remote: Checking .openshift/pear.txt for PEAR dependency...
remote: Preparing build for deployment
remote: Deployment id is 08654c3a
remote: Activating deployment
remote: Starting PHP 5.4 cartridge (Apache+mod_php)
remote: Application directory "/" selected as DocumentRoot
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
To ssh://xxxxxxxxx@foo-bar.rhcloud.com/~/git/ranking.git/
   1cf5446..c2ee0b4  master -> master

rhc で操作する

OpenShift client tool (rhc) を使えば、MySQL や cron、ssh 接続ができたりする。

事前準備

OpenShift Online for Mac/OS X | OpenShift Developers に従う。ただし、sudo は使わない。

ログインに成功すると、前の手順で作ったアプリケーションが表示される。

$ gem install rhc
$ rhc setup
rhc setup
OpenShift Client Tools (RHC) Setup Wizard

This wizard will help you upload your SSH keys, set your application namespace,
and check that other programs like Git are properly installed.

If you have your own OpenShift server, you can specify it now. Just hit enter to
use the server for OpenShift Online: openshift.redhat.com.
Enter the server hostname: |openshift.redhat.com| 

You can add more servers later using 'rhc server'.

Login to openshift.redhat.com: user@example.com
Password: ************************

OpenShift can create and store a token on disk which allows to you to access the
server without using your password. The key is stored in your home directory and
should be kept secret.  You can delete the key at any time by running 'rhc
logout'.
Generate a token now? (yes|no) yes
Generating an authorization token for this client ... lasts about 1 month

Saving configuration to /Users/user/.openshift/express.conf ... done

Checking for git ... found git version 2.2.2

Checking common problems .. done

Checking for a domain ... bar

Checking for applications ... found 1

  ranking http://foo-bar.rhcloud.com/

  You are using 1 of 3 total gears
  The following gear sizes are available to you: small

Your client tools are now configured.

以下のコマンドで、ssh 接続できる。

$ rhc ssh <アプリケーション名>
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2