■GitHub
GitHub
https://github.com/
GitHub Status
https://www.githubstatus.com/
一番メジャーだと思われる。オープンソースで公開する場合に最適。非公開リポジトリを作りたい場合は有料
…だったが、2020年4月15日現在、非公開リポジトリもチーム利用も無料になった
GitHub、チームでの利用も無料に。プライベートリポジトリ数も制限なく、チームディスカッション、ActionsによるCI/CDも可能 − Publickey
https://www.publickey1.jp/blog/20/githubactionscicd.html
新規に立てたgithubリポジトリからソースをcloneする
http://qiita.com/monhan/items/b467e5f58ebcbc5f5b3c
GitHubでリポジトリを作ってSSHでgit cloneするまで
https://cloudpack.media/416
githubから、Action Required - SSH Key Vulnerabilityなるメールが来た
http://blog.bornneet.com/Entry/328/
gitでシンプルなデプロイ環境を作る
http://qiita.com/zaburo/items/8886be1a733aaf581045
githubのwebhookを使って、push時に自動でサーバーを更新させる
http://blog.manaten.net/entry/573
■インストール(古いバージョンでダメなら試す)
# yum list installed | grep git.x86_64
… gitのインストールを確認
# yum remove git
… 古いものがあれば削除
# yum install git
… gitをインストール
■gitの動作確認
# git --version
… インストールを確認
■Apacheへログイン(nginxの場合は、以降も含めてnginx用のユーザを使う)
# passwd apache
… apacheにパスワードを設定(rootを経由するなら不要)
# su -s /bin/bash - apache
… シェルを指定してログイン
■デプロイ環境を構築
※apacheユーザで作業
※/var/www 内全体をデプロイ対象にすると、
「/var/www/.ssh/ などが存在するのでデプロイできないが、リポジトリへアクセスするためには /var/www/.ssh/ が必要」
となって作業が難しいので注意。他の場所にすることを推奨
サイト全体をデプロイ対象にするなら、バーチャルホストを設定するのが無難
# mkdir /var/www/html/test
… デプロイ先を作成
# chmod 775 /var/www/html/test/
… apacheグループのユーザに読み書き実行を許可
# ll /var/www/html/
… デプロイ先の所有者を確認
$ cd /var/www/html/test
… デプロイ先に移動
$ git clone git@github.com:refirio/test.git /var/www/html/test
… クローン実行
Initialized empty Git repository in /var/www/html/test/.git/
The authenticity of host 'github.com (192.30.252.128)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.128' (RSA) to the list of known hosts.
Permission denied (publickey).
… Permissionで弾かれている(鍵の登録が必要)
fatal: The remote end hung up unexpectedly
■鍵
※apacheユーザで作業
$ cd
… apacheのホームディレクトリで作業
$ mkdir /var/www/.ssh
$ chown -R apache:apache /var/www/.ssh/
$ ssh-keygen -t rsa
… gitへSSH接続するための鍵を作成
Generating public/private rsa key pair.
Enter file in which to save the key (/var/www/.ssh/id_rsa):
… 空Enter(デフォルトの場所に作成)
Enter passphrase (empty for no passphrase):
… 空Enter(パスワード無しの鍵を作成)
Enter same passphrase again:
… 空Enter
Your identification has been saved in /var/www/.ssh/id_rsa.
Your public key has been saved in /var/www/.ssh/id_rsa.pub.
The key fingerprint is:
42:b3:c9:c3:f9:85:e4:be:9a:3e:28:82:cf:48:83:a9 apache@refirio.net
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| o . |
| + B . |
| O S . |
|.. = . |
|+o . o |
|=oo . .. . |
|Eoo. .+o. |
+-----------------+
$ ll /var/www/.ssh/
… 鍵(id_rsa と id_rsa.pub)の作成を確認
合計 8
-rw------- 1 apache apache 1675 10月 18 12:13 2015 id_rsa
-rw-r--r-- 1 apache apache 400 10月 18 12:13 2015 id_rsa.pub
-rw-r--r-- 1 apache apache 407 10月 18 12:19 2015 known_hosts
$ vi /var/www/.ssh/id_rsa
… 秘密鍵の内容を確認
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA7QltpgTVx5XNpS3sA/qatl/NlFHxGHR55cnZw2zsGpkqadVN
〜略〜
ePtIQN8d07QbxJ/RLzzLfkgs6w0tezCv40tXtCSD7LdeJTaRwIg=
-----END RSA PRIVATE KEY-----
$ vi /var/www/.ssh/id_rsa.pub
… 公開鍵の内容を確認(アカウントとドメインが記入されているのを確認)
ssh-rsa AAAA〜略〜3PQ== apache@refirio.net
$ vi /var/www/.ssh/known_hosts
… gitへのログインを試みたので、known_hostsとして公開鍵が登録されている
github.com,192.30.252.128 ssh-rsa AAAA〜略〜AaQ==
■Protectを解除(この手順は不要かも?)
$ ssh-keygen -lf ~/.ssh/id_rsa.pub
… フィンガープリントを確認
2048 b4:dd:17:〜略〜:6e:fd:a4 /root/.ssh/id_rsa.pub (RSA)
https://github.com/settings/ssh/audit
からフィンガープリントを登録
…と思ったけど、
https://github.com/settings/ssh/audit でapproveボタンを押せばOKだった。
未承認のアクセスがあったというだけ?
■鍵を登録
https://github.com/settings/ssh
もしくは
https://github.com/ユーザ名/リポジトリ名/settings/keys
から「refirio.net」や「staging」などタイトルとともに公開鍵を登録
パスワードはGitHubへのログインパスワードを登録
■動作確認
※apacheユーザで作業
$ cd /var/www/html/test
… 作業用ディレクトリへ移動
$ git clone git@github.com:refirio/test.git /var/www/html/test
… クローン実行
Initialized empty Git repository in /var/www/html/test/.git/
remote: Counting objects: 146, done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 146 (delta 10), reused 0 (delta 0), pack-reused 121
Receiving objects: 100% (146/146), 18.03 KiB, done.
Resolving deltas: 100% (74/74), done.
$ ll
… 確認
合計 28
-rw-r--r-- 1 apache apache 23 10月 18 12:24 2015 README.md
drwxr-xr-x 2 apache apache 4096 10月 18 12:24 2015 css
-rw-r--r-- 1 apache apache 615 10月 18 12:24 2015 index.html
-rw-r--r-- 1 apache apache 370 10月 18 12:24 2015 page1.html
-rw-r--r-- 1 apache apache 343 10月 18 12:24 2015 page2.html
-rw-r--r-- 1 apache apache 343 10月 18 12:24 2015 page3.html
-rw-r--r-- 1 apache apache 384 10月 18 12:24 2015 test.php
$ git pull
… プルする場合
Already up-to-date.
$ git pull
… gitのmasterを更新してから再度プルした場合
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 5 (delta 3), reused 2 (delta 2), pack-reused 0
Unpacking objects: 100% (5/5), done.
From github.com:refirio/test
d3c714b..e12a45e develop -> origin/develop
f555d5f..5915266 master -> origin/master
* [new branch] text -> origin/text
Updating f555d5f..5915266
Fast-forward
index.html | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
$ ll
… 確認
合計 28
-rw-r--r-- 1 root root 23 10月 12 14:16 2015 README.md
drwxr-xr-x 2 root root 4096 10月 12 14:16 2015 css
-rw-r--r-- 1 root root 514 10月 12 14:29 2015 index.html
… ファイルが更新された
-rw-r--r-- 1 root root 343 10月 12 14:16 2015 page1.html
-rw-r--r-- 1 root root 343 10月 12 14:16 2015 page2.html
-rw-r--r-- 1 root root 343 10月 12 14:16 2015 page3.html
-rw-r--r-- 1 root root 343 10月 12 14:16 2015 page4.html
■デプロイ用スクリプト作成
※apacheユーザで作業
$ mkdir /var/www/html/test-deploy
… デプロイツール用ディレクトリを作成
$ chmod 775 /var/www/html/test-deploy/
… apacheグループのユーザに読み書き実行を許可
$ cd /var/www/html/test-deploy/
… 作業用ディレクトリへ移動
$ vi deploy.sh
… デプロイ用スクリプトを作成
#!/bin/bash
cd /var/www/html/test;
git pull;
$ chmod 744 deploy.sh
… デプロイ用スクリプトに実行権限を付加
$ /var/www/html/test-deploy/deploy.sh
… 実行テスト
Already up-to-date.
./deploy.sh を実行するPHPプログラムを作成する
/var/www/html/test-deploy/index.php
<?php
if ($fp = fopen('logs/' . date('YmdHis') . '.log', 'a')) {
fwrite($fp, print_r($_POST['payload'], true));
fwrite($fp, "\n");
fwrite($fp, $_SERVER['HTTP_USER_AGENT']);
fclose($fp);
} else {
exit('NG');
}
$payload = $_POST['payload'];
$payload = json_decode($payload, true);
if ($payload['ref'] == 'refs/heads/master') {
echo shell_exec('/var/www/html/test-deploy/deploy.sh');
}
ブラウザから index.php にアクセスして、デプロイできることを確認する
■更新を自動通知
https://github.com/refirio/test/settings/hooks
Payload URL:
http://refirio.net/test-deploy/
Content type: application/json
Which events would you like to trigger this webhook?: Send me everything.
everythingにしておかないと、マージのタイミングで知らせてくれない?
もしくは「Let me select individual events.」で、任意のタイミングで知らせてもらうのが良さそう
■GitHub Actions
※未検証
GitHubでCIのような仕組みを構築できる
自由度は高いようだが、規約で禁止されている使い方もあるようなので注意
プランによってジョブの数などに制限はある
GitHubの新機能「GitHub Actions」で試すCI/CD | さくらのナレッジ
https://knowledge.sakura.ad.jp/23478/
■続き
パーミッションをどうするか
開発環境がMacなら、パーミッションも含めてコミットされる?
シェルスクリプトに「特定箇所にあるディレクトリのパーミッションを自動設定する」コードを追加する?
…と思ったけど、Apache権限でデプロイするので、パーミッションは問題にならなさそう
■Bitbucket
Bitbucket
https://bitbucket.org/
Atlassian Bitbucket Status
https://bitbucket.status.atlassian.com/
※GitHubは非公開リポジトリを作りたい場合は有料
よってお金をかけずに非公開リポジトリを作りたい場合は、Bitbucketを使うといい
…だったが、2020年4月15日現在、GitHubは非公開リポジトリもチーム利用も無料になった
■ユーザ登録 〜 リポジトリの作成 〜 SourceTreeへのクローンメモ
https://bitbucket.org/
「Get started」から開始
リポジトリを作ると
refirio/test
のような名前になるので、会社で使う場合は「会社アカウントで」「リポジトリ名は英語で」作成したほうが良さそう
もしくは、案件ごとのまとまりごとにプロジェクトを作成した方が良さそう
すべて同じプロジェクトで管理するとすぐに上限の5人に達するし、管理も難しそう
ユーザ名・パスワード・Eメールを入力し
Planは「Personal Account」でサインアップ
会社で使うなら「5 user team」で良さそう
(会社アカウントで作って、その後チームアカウントも作る)
メールが送信されるので確認しておく
リポジトリの作成(以下の設定内容は一例)
名前は「test」英語のみにする?GitHubに合わせるためにも。日本語は「説明」欄に書く?
非公開リポジトリ
プライベートフォークのみ許可
リポジトリタイプGit
プロジェクト管理は課題管理とWiki
プログラミング言語はPHP
Hip Chat は有効にしない
Setting -> Services -> Issues を追加
…は、はじめから追加されていた
概要 -> SourceTreeにクローン
SourceTreeが起動するので、Bitbucketパスワードを入力
リポジトリの場所を選択してクローン
課題 -> 最初の課題を作成
「#1 メッセージ」
のようにコミットすると、課題の番号へリンクされる
Setting -> マイルストーン
からマイルストーンを設定できる
コマンドでクローンする場合、以下のようにする
HTTPSでクローン
git clone
https://refirio@bitbucket.org/refirio/test.git
SSHでクローン
git clone git@bitbucket.org:refirio/test.git
■インストール(古いバージョンでダメなら試す)
# yum list installed | grep git.x86_64
… gitのインストールを確認
# yum remove git
… 古いものがあれば削除
# yum install git
… gitをインストール
■gitの動作確認
# git --version
… インストールを確認
■Apacheへログイン(nginxの場合は、以降も含めてnginx用のユーザを使う)
# passwd apache
… apacheにパスワードを設定(rootを経由するなら不要)
# su -s /bin/bash - apache
… シェルを指定してログイン
■デプロイ環境を構築
※apacheユーザで作業
※/var/www 内全体をデプロイ対象にすると、
「/var/www/.ssh/ などが存在するのでデプロイできないが、リポジトリへアクセスするためには /var/www/.ssh/ が必要」
となって作業が難しいので注意。他の場所にすることを推奨
サイト全体をデプロイ対象にするなら、バーチャルホストを設定するのが無難
# mkdir /var/www/html/bitbucket-test
… デプロイ先を作成
# chmod 775 /var/www/html/bitbucket-test/
… apacheグループのユーザに読み書き実行を許可
# ll /var/www/html/
… デプロイ先の所有者を確認
$ cd /var/www/html/bitbucket-test
… デプロイ先に移動
$ git clone git@bitbucket.org:refirio/test.git /var/www/html/bitbucket-test
… クローン実行
Initialized empty Git repository in /var/www/html/bitbucket-test/.git/
The authenticity of host 'bitbucket.org (131.103.20.167)' can't be established.
RSA key fingerprint is 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'bitbucket.org,131.103.20.167' (RSA) to the list of known hosts.
Permission denied (publickey).
… Permissionで弾かれている
fatal: The remote end hung up unexpectedly
■鍵
※apacheユーザで作業
$ cd
… ホームディレクトリで作業
$ mkdir /var/www/.ssh
$ chown -R apache:apache /var/www/.ssh/
$ ssh-keygen -t rsa
… BitbucketへSSH接続するための鍵を作成
Generating public/private rsa key pair.
Enter file in which to save the key (/var/www/.ssh/id_rsa):
… 空Enter(デフォルトの場所に作成)
Enter passphrase (empty for no passphrase):
… 空Enter(パスワード無しの鍵を作成)
Enter same passphrase again:
… 空Enter
Your identification has been saved in /var/www/.ssh/id_rsa.
Your public key has been saved in /var/www/.ssh/id_rsa.pub.
The key fingerprint is:
42:b3:c9:c3:f9:85:e4:be:9a:3e:28:82:cf:48:83:a9 apache@refirio.net
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| o . |
| + B . |
| O S . |
|.. = . |
|+o . o |
|=oo . .. . |
|Eoo. .+o. |
+-----------------+
$ ll /var/www/.ssh/
… 鍵(id_rsa と id_rsa.pub)の作成を確認
合計 8
-rw------- 1 apache apache 1675 10月 18 12:13 2015 id_rsa
-rw-r--r-- 1 apache apache 400 10月 18 12:13 2015 id_rsa.pub
-rw-r--r-- 1 apache apache 407 10月 18 12:19 2015 known_hosts
$ vi /var/www/.ssh/id_rsa
… 秘密鍵の内容を確認
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA7QltpgTVx5XNpS3sA/qatl/NlFHxGHR55cnZw2zsGpkqadVN
〜略〜
ePtIQN8d07QbxJ/RLzzLfkgs6w0tezCv40tXtCSD7LdeJTaRwIg=
-----END RSA PRIVATE KEY-----
$ vi /var/www/.ssh/id_rsa.pub
… 公開鍵の内容を確認(アカウントとドメインが記入されているのを確認)
ssh-rsa AAAA〜略〜3PQ== apache@refirio.net
$ vi /var/www/.ssh/known_hosts
… Bitbucketへのログインを試みたので、known_hostsとして公開鍵が登録されている
bitbucket.org,192.30.252.128 ssh-rsa AAAA〜略〜AaQ==
■鍵を登録
https://bitbucket.org/refirio/test/admin/deploy-keys/
から「refirio.net」というタイトルで公開鍵を登録
■動作確認
※apacheユーザで作業
$ cd /var/www/html/bitbucket-test
… 作業用ディレクトリへ移動
$ git clone git@bitbucket.org:refirio/test.git /var/www/html/bitbucket-test
… クローン実行
Initialized empty Git repository in /var/www/html/bitbucket-test/.git/
remote: Counting objects: 22, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 22 (delta 10), reused 0 (delta 0)
Receiving objects: 100% (22/22), done.
Resolving deltas: 100% (10/10), done.
$ ll
… 確認
合計 24
drwxr-xr-x 2 apache apache 4096 12月 6 21:15 2015 css
-rw-r--r-- 1 apache apache 556 12月 6 21:15 2015 index.html
-rw-r--r-- 1 apache apache 290 12月 6 21:15 2015 test.php
-rw-r--r-- 1 apache apache 293 12月 6 21:15 2015 test1.html
-rw-r--r-- 1 apache apache 293 12月 6 21:15 2015 test2.html
-rw-r--r-- 1 apache apache 293 12月 6 21:15 2015 test3.html
$ git pull
… プルする場合
Already up-to-date.
■既存のディレクトリにCLONE
空ではないディレクトリにCLONEしようとするとエラーになる
以下の手順なら対応できた
既存のディレクトリに git clone するには - Corredor
http://neos21.hatenablog.com/entry/2016/02/07/000000
git pull を強制し、リモートでローカルを上書きする方法 | WWWクリエイターズ
http://www-creators.com/archives/1097
以下、実際に作業したときのメモ
# su -s /bin/bash - apache
$ cd /var/www/html/bitbucket-test
$ git clone git@bitbucket.org:refirio/test.git /var/www/html/bitbucket-test
本来は上記手順でCLONEできる
が、すでに /var/www/html/bitbucket-test が存在して作業をしている場合はCLONEできない
この場合、以下の方法で強制的に上書き対応できる(必ず既存ディレクトリをバックアップしてから作業を始める)
# cd /var/www/html
# chown -hR apache. /var/www/html/bitbucket-test
… デプロイで上書きできるように所有者を設定
# su -s /bin/bash - apache
$ cd /var/www/html/bitbucket-test
$ git init
… ローカルリポジトリを作成
$ git remote add origin git@bitbucket.org:refirio/test.git
… リモートリポジトリを追加
$ git fetch origin
… リモートリポジトリを取得
$ git branch -a
$ git merge origin/master
… ローカルリポジトリにマージ
$ git branch -a
「git merge origin/master」の際、以下のようなエラーになるようなら
$ git merge origin/master
error: Untracked working tree file 'app/config.php' would be overwritten by merge.
fatal: read-tree failed
以下を実行して強制的にリポジトリの内容に一致させることができる
$ git reset --hard origin/master
ブランチをdevelopに切り替えてPULLする場合、以下のようにする
$ git reset --hard origin/develop
$ git checkout develop
上記で切り替えられなければ、以下のようにする
git checkout -b develop origin/develop
git - fetchしたremoteブランチのトラッキングブランチがcheckout時に自動で生成されない - スタック・オーバーフロー
https://ja.stackoverflow.com/questions/18047/fetch%E3%81%97%E3%81%9Fremote%E3%83%96%E3%83%A9%E3%83%B...
最後にPULLして、エラーにならなければ完了
$ git pull
■複数サーバにCLONE
「ssh-keygen -t rsa」で鍵を作成したサーバを複製した場合、各サーバが同じ鍵を持つのでデプロイに問題はない
複数台で構築済みのサーバの場合、各サーバで鍵を作成すると鍵の内容が異なるのですべての鍵をGitHubなどに登録する必要がある
もしくは作成済みの id_rsa と id_rsa.pub を各サーバに複製すれば、同じ鍵を持つことになるのでデプロイに問題はない
ただし複製の際に権限に注意しないと、CLONEの際に以下の警告が表示される
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0664 for '/var/lib/nginx/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/var/lib/nginx/.ssh/id_rsa": bad permissions
Permission denied (publickey).
fatal: Could not read from remote repository.
権限 0664 は危険だと警告されている
この場合、鍵の複製元サーバに合わせて、以下のように調整するとCLONEできるようになる
$ cd /var/lib/nginx/.ssh
$ ll
合計 12
-rw-rw-r-- 1 nginx nginx 1675 4月 26 10:55 id_rsa
-rw-rw-r-- 1 nginx nginx 434 4月 26 10:55 id_rsa.pub
-rw-r--r-- 1 nginx nginx 409 4月 26 11:43 known_hosts
$ chmod 0600 id_rsa
$ chmod 0644 id_rsa.pub
$ ll
合計 12
-rw------- 1 nginx nginx 1675 4月 26 10:55 id_rsa
-rw-r--r-- 1 nginx nginx 434 4月 26 10:55 id_rsa.pub
-rw-r--r-- 1 nginx nginx 409 4月 26 11:43 known_hosts
■リポジトリを複製(引っ越し)する
Git.txt を参照
■リポジトリを譲渡する
Git.txt を参照
■サーバからコミット&プッシュ
一部の人のみFTPで更新し、その内容をgitに取り込めるかの試行錯誤
gitで定期的にファイルをバックアップする
http://qiita.com/irxground/items/80dc6432e7d9d2b8b2a9
Gitを使いこなすための20のコマンド
https://mag.osdn.jp/09/03/16/0831212/3
結論から書くと、Bitbucketのキーに書き込み権限はないので不可
GitHubならDeploy keysを登録時に「Allow write access」とすればできる
GitHubとBitbucketでのDeploy keyの違い
http://nemumu.hateblo.jp/entry/2014/03/12/184610
■git用にユーザを追加
# useradd git-user
# passwd git-user
# usermod -a -G apache git-user
# cp /home/ec2-user/.ssh/authorized_keys /home/git-user/.ssh/authorized_keys
■git用ユーザから更新できるように
以下はデプロイ時にApacheユーザから
find /var/www/html/student/ -type f -print | xargs chmod 664
find /var/www/html/student/ -type d -print | xargs chmod 775
find /var/www/html/html/student/ -type f -print | xargs chmod 664
find /var/www/html/html/student/ -type d -print | xargs chmod 775
find /var/www/html/html/student/test/ -type f -print | xargs chmod 664
find /var/www/html/html/student/test/ -type d -print | xargs chmod 775
■更新したファイルを表示
$ git status -bs
## develop...origin/develop
M html/student/test/test.txt
?? html/student/test/test_add.txt
$ git diff
diff --git a/html/student/test/test.txt b/html/student/test/test.txt
index 4871fd5..7827f81 100644
--- a/html/student/test/test.txt
+++ b/html/student/test/test.txt
@@ -1 +1,2 @@
test.txt
+更新テスト
■コミット&プッシュ
$ git add -A
$ git commit -m "Commit at $(date "+%Y-%m-%d %T")" || true
以下はBitbucketのキーでプッシュしようとした例
Bitbucketのキーには書き込み権限が無いためエラーとなる
$ git push -f origin develop:develop
conq: repository access denied. access via a deployment key is read-only.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
以下はGitHubのRead権限のみを持ったキーでプッシュしようとした例
「read only」のキーである旨が表示されている
$ git push origin develop
ERROR: The key you are authenticating with has been marked as read only.
fatal: Could not read from remote repository.
以下はGitHubのRead/write権限を持ったキーでプッシュしようとした例
問題なくプッシュできる。ローカル側でプルもできる
$ git push origin develop
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 364 bytes | 364.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:yamano-terraport/test.git
6049160..3899f8f develop -> develop
■PHPで現在のgitブランチを取得
PHPで現在のgitブランチを取得する
http://co.bsnws.net/article/78
■WordPressをGitで管理
■方針
WordPress自体が自身のプログラムを書き換えるため、最低限のファイル(テーマと.htaccess)のみgitで管理する
自作プラグインなど、他にも管理対象があれば追加する
■Gitへ登録
ローカルにWordPressを普通に設置&動作確認
SourceTreeでリポジトリを作成
「+ → Create」
保存先のパス: (WordPressを設置したフォルダのパス)
名前: (任意の名前)
種類: Git
フォルダが存在する旨の警告が表示されるが、そのまま進める
.gitignoreを作成(以下の場合、sampleテーマのみGit管理する)
Thumbs.db
.DS_Store
/wp-config.php
/.htaccess
/.htpasswd
/index.php
/license.txt
/readme.html
/wp-*.php
/xmlrpc.php
/wp-admin/*
/wp-content/*
!/wp-content/themes
/wp-content/themes/*
!/wp-content/themes/sample
/wp-includes/*
プラグインも管理対象にするなら、以下も追加する
!/wp-content/plugins
サンプルとして以下のテーマを導入(何でもいい)
https://wordpress.org/themes/sosimple/
Bitbucket上にリポジトリを作成(リポジトリは空のままにしておく)
SourceTreeでローカルリポジトリにリモートリポジトリを追加
「設定 → 追加」
リモート名: (任意の名前)
URL/パス: (Gitのパス)
SourceTreeでローカルリポジトリからリモートへプッシュする設定 | studio9 personal
http://personal-studio9.com/sourcetree_push/
SourceTreeから普通にコミット&プッシュ(コミット前に、意図したファイルのみが対象になっているか確認する)
これで、最低限のファイルのみGitで管理される
■Gitから取得
WordPressを普通に設置&動作確認
WordPressを設置したフォルダ自体の名前を一時的に変更
本来の場所にフォルダを作成し、その中にクローン(ファイルの所有者や権限に注意)
一時的に名前を変更したフォルダから、各ファイルを本来の場所に移動(.htaccess以外は丸ごと上書き、で大丈夫のはず)
コミット対象が発生していないことを確認
WordPressを動作確認
WordPressの管理画面からテーマを変更&動作確認
■複数台構成のサーバで稼働させる
マルチAZ環境でWordPressを使う方法は AWS.txt を参照