ec2でgit

$ git version
git version 2.14.4

共有リポジトリをつくる。
bareリポジトリは、ワーキングコピーを持たないリポジトリ
sharedオプションをつけないと,ファイルパーミッションが無くてpushできなくなってしまう

mkdir test.git
cd test.git
git --bare init --shared
git clone ../git/test.git

git remote add origin
git push -u origin master

$ git push origin master
The authenticity of host ‘()’ can’t be established.
何!?

s3から画像をダウンロードする

require_once('vendor/autoload.php');

$s3client = new Aws\S3\S3Client([
		'credentials' => [
				'key' => '',
				'secret' => ''
		],
		'region' => 'ap-northeast-1',
		'version' => 'latest',
]);

$result = $s3client->getObject([
		'Bucket' => 'capital-technology',
		'Key' => 'img.jpeg',
]);

echo $result['ContentLength'];

OK!

次は、vagrantからec2にgitでpush, commitをしたい。

phpでlocalからS3に画像をアップロードする

aws sdk for php v3を使う。autoload.phpで良い。

<?php

require_once('vendor/autoload.php');

$s3client = new Aws\S3\S3Client(&#91;
		'credentials' => [
				'key' => '',
				'secret' => ''
		],
		'region' => 'ap-northeast-1',
		'version' => 'latest',
]);

$result = $s3client->putObject([
		'Bucket' => 'capital-technology',
		'Key' => 'img.jpeg',
		'SourceFile' => 'aaa.jpeg',
		'ContentType' => mime_content_type('aaa.jpeg'),
]);

アップロードはできたが、公開するとしないと、アクセスできない。
更に、ストレージクラスもスタンダード。ここらへんをphp側で操作できるようにしたい。

ACLで’public-read’と指定すると公開指定ができる。

$result = $s3client->putObject([
		'Bucket' => 'capital-technology',
		'Key' => 'img2.jpeg',
		'ACL' => 'public-read',
		'SourceFile' => 'aaa.jpeg',
		'ContentType' => mime_content_type('aaa.jpeg'),
]);

echo $result['ObjectURL'];

aws sdk for php v3

まずcomposerをいれます。

$ curl -sS https://getcomposer.org/installer | php

続いて、aws sdkをinstallします。

$ composer require aws/aws-sdk-php
Using version ^3.62 for aws/aws-sdk-php
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 6 installs, 0 updates, 0 removals
  - Installing mtdowling/jmespath.php (2.4.0): Downloading (100%)
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing guzzlehttp/psr7 (1.4.2): Loading from cache
  - Installing guzzlehttp/promises (v1.3.1): Loading from cache
  - Installing guzzlehttp/guzzle (6.3.3): Downloading (100%)
  - Installing aws/aws-sdk-php (3.62.2): Downloading (100%)
guzzlehttp/guzzle suggests installing psr/log (Required for using the Log middleware)
aws/aws-sdk-php suggests installing doctrine/cache (To use the DoctrineCacheAdapter)
aws/aws-sdk-php suggests installing aws/aws-php-sns-message-validator (To validate incoming SNS notifications)
Writing lock file
Generating autoload files

swift4でARアプリを作ろう

まず、Augmented Reality Appを選択する必要がある。

AppDelegate.swift, ViewController.swift, Main.storyboard, LaunchScreen.storyboard, Info.plist は同じだが、art.scnassetsが追加されている。

viewController.swift
デフォルトでvr体験できるようになってますね。

import UIKit
import SceneKit
import ARKit

class ViewController: UIViewController, ARSCNViewDelegate {

    @IBOutlet var sceneView: ARSCNView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Set the view's delegate
        sceneView.delegate = self
        
        // Show statistics such as fps and timing information
        sceneView.showsStatistics = true
        
        // Create a new scene
        let scene = SCNScene(named: "art.scnassets/ship.scn")!
        
        // Set the scene to the view
        sceneView.scene = scene
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        // Create a session configuration
        let configuration = ARWorldTrackingConfiguration()

        // Run the view's session
        sceneView.session.run(configuration)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        // Pause the view's session
        sceneView.session.pause()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Release any cached data, images, etc that aren't in use.
    }

    // MARK: - ARSCNViewDelegate
    
/*
    // Override to create and configure nodes for anchors added to the view's session.
    func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
        let node = SCNNode()
     
        return node
    }
*/
    
    func session(_ session: ARSession, didFailWithError error: Error) {
        // Present an error message to the user
        
    }
    
    func sessionWasInterrupted(_ session: ARSession) {
        // Inform the user that the session has been interrupted, for example, by presenting an overlay
        
    }
    
    func sessionInterruptionEnded(_ session: ARSession) {
        // Reset tracking and/or remove existing anchors if consistent tracking is required
        
    }
}

複数ファイルに.htaccessを設定する

<Files app_a.php>
AuthUserFile .htpasswd
AuthType Basic
AuthName "Web access"
Require valid-user
</Files>

<Files app_b.php>
AuthUserFile .htpasswd
AuthType Basic
AuthName "Web access"
Require valid-user
</Files>

htpasswd用パス作成ツール
http://phpspot.net/php/pghtpasswd%E7%94%A8%E3%83%91%E3%82%B9%E4%BD%9C%E6%88%90%E3%83%84%E3%83%BC%E3%83%AB.html

AWS S3を使おう

新しいバケットを作成します。

capital-technologyというバケットを作成します。

s3にファイルをアップロードします。

なるほど!バケットの下に保存されました。ディレクトリみたいなもん?

ストレージクラスは
1. スタンダード
2. 標準 IA
3. 1ゾーン IA
4. 低冗長化
から選択できる。

basic認証を実装する

switch(true){
	case !isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']):
	case $_SERVER['PHP_AUTH_USER'] !== 'admin':
	case $_SERVER['PHP_AUTH_PW'] !== 'test':
		header('WWW-Authenticate: Basic realm="Enter username and password."');
		header('Content-Type: text/plain; charset=utf-8');
		die('このページを見るにはログインが必要です');
}

header('Content-Type: text/html; charset=utf-8');

WWW-Authenticateヘッダ:Webブラウザに対して認証用ダイアログの表示をさせるための指示

ec2のtimezoneをJST-9に変更

バックアップを取りながら進めます。拡張子は皆さんに習って.org
sysconfig/clockは、ZONE=”Asia/Tokyo” UTC=falseにします。

$ date
Sat Jun 23 23:02:34 UTC 2018
$ strings /etc/localtime
TZif2
TZif2
UTC0

$ sudo cp /etc/localtime /etc/localtime.org
$ sudo ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
$ date
Sun Jun 24 08:04:10 JST 2018

$ sudo cp /etc/sysconfig/clock /etc/sysconfig/clock.org
$ sudo vi /etc/sysconfig/clock

OK♪

$ strings /etc/localtime
TZif2
TZif2
JST-9

ここから、crontabを編集
binはcyberduckで一応かくにんしておく。/usr/bin/php

00 02 * * 5 cd /var/local/device/ ; /usr/bin/php -q index.php

:wqで保存して、crondを再起動

$ sudo service crond restart
Stopping crond:                                            [  OK  ]
Starting crond:                                            [  OK  ]

OK! ec2からhotmailへ毎週、週間スマホ売上ランキングが飛んでくるようになりました。
hotmailでは、spamは扱いですが、まあいいとしましょう!
シャーディー♪