<!DOCTYPE html> <html> <head> <script src="tinymce/js/tinymce/tinymce.min.js"></script> <script>tinymce.init({ selector: 'textarea' }); </script> </head> <body> <h1>テキストを入力してください</h1> <textarea>TinyMCE Editor</textarea> </body> </html>
普通に実装します。
随机应变 ABCD: Always Be Coding and … : хороший
<!DOCTYPE html> <html> <head> <script src="tinymce/js/tinymce/tinymce.min.js"></script> <script>tinymce.init({ selector: 'textarea' }); </script> </head> <body> <h1>テキストを入力してください</h1> <textarea>TinyMCE Editor</textarea> </body> </html>
普通に実装します。
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the ‘Note about
fast-forwards’ section of ‘git push –help’ for details.
対応方法 fetchしてmergeする
[vagrant@localhost laravel]$ git fetch
Password:
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 8 (delta 2), reused 5 (delta 1), pack-reused 0
Unpacking objects: 100% (8/8), done.
From https://github.com/hoge/hogehoge
e66ad76..bd912e1 master -> origin/master
[vagrant@localhost laravel]$ git merge origin/master
Merge made by recursive.
README.md | 2 +-
appspec.yml | 5 ++++
readme.md | 67 +———————————————————
3 files changed, 8 insertions(+), 66 deletions(-)
create mode 100644 appspec.yml
これで、git pushできるようになる。
なるほど!!
簡易的にcdnで実装したい。jqueryはbody内。
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
resources/views/layouts のdefault.blade.phpを編集する。
<!DOCTYPE> <html> <head> <meta charset="utf-8"> <title>@yield('title')</title> <link rel="stylesheet" href="/css/styles.css"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> </head> <body> <div class="container"> @yield('content') </div> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> </body> </html>
[vagrant@localhost laravel]$ php artisan serve –host 192.168.35.10
おいおい、おかしなことになってる。
まあbootstrapが動くことは分かったのでOK
passwordが違うと表示
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
さっぱり覚えていない
ec2の初期パスワードか?
[ec2-user@ ~]$ cat /var/log/mysqld.log
[ec2-user@ ~]$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
違うらしい。。
mysqlを止めて、/etc/my.cnfを編集
[ec2-user@ ~]$ sudo service mysqld stop
Stopping mysqld: [ OK ]
[ec2-user@]$ sudo vi /etc/my.cnf
skip-grant-tables を追加
再起動して、-pなしでログイン
[ec2-user@~]$ sudo service mysqld start
Starting mysqld: [ OK ]
[ec2-user@ ~]$ mysql -u root
> UPDATE mysql.user SET authentication_string = PASSWORD(‘new password’) WHERE User = ‘root’ AND Host = ‘localhost’;
> FLUSH PRIVILEGES;
[ec2-user@]$ sudo vi /etc/my.cnf
# skip-grant-tables //コメントアウト
$ sudo service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
[ec2-user@ ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
OK!ふう、焦った~
$ rpm -qa |grep -i codedeploy-agent
codedeploy-agent-1.0-1.1518.noarch
/var/log/aws/codedeploy-agent/*
2018-09-24 10:54:17 INFO [codedeploy-agent(13919)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.0-1.1518_rpm.
2018-09-24 10:54:17 ERROR [codedeploy-agent(13919)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Missing credentials – please check if this instance was started with an IAM instance profile
これか?
Missing credentials
sudo service codedeploy-agent restart
デプロイとは、ソフトウェアの分野で、開発したソフトウェアを利用できるように実際の運用環境に展開すること。
IAMからロールへ行く
CodeDeployを選択する
ec2 インスタンス
# CodeDeployエージェント
wget https://aws-codedeploy-ap-northeast-1.s3.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
# 実行
sudo service codedeploy-agent start
appspec.ymlを編集して、githubにpush
version: 0.0 os: linux files: - source: / destination: /home/ec2-user/dev/
code deployからアプリケーションの作成
deployする
deploy長いな。。
ELBでhttpsの無料証明は既に確認した。
ELBで接続をhttpsに設定するだけ。
AWS Certificate Manager でプロビジョニングされたパブリック SSL/TLS 証明書は無料
https://aws.amazon.com/jp/certificate-manager/pricing/
無料とは別にプライベート証明書がある。
ACMはSSL/TLS証明書のプロビジョニング、管理、およびデプロイを行うサービス
ただし、AWSでは実在認証(EV)、組織認証(OV)の証明書は提供していない。
ACMはこれか!
証明書情報↓
証明書本文
証明書のプライベートキー
証明書チェーン
なるほど。クラスメソッド凄いな。
alpha ssl トリトン 6,000円~/年
https://www.toritonssl.com/
KWC 15,700円/年
https://www.sslcoupon.jp/
なるほどね~
Next: githubからec2にデプロイ
1. まずdatabaseをつくります。
mysql> CREATE DATABASE click;
Query OK, 1 row affected (0.00 sec)
mysql> use click;
2. 続いて、tableを作ります。
mysql> create table articles(
-> id int primary key auto_increment,
-> login_id varchar(30),
-> role varchar(50),
-> name varchar(20),
-> password varchar(30),
-> mail varchar(255),
-> test_mail varchar(255),
-> updated_person varchar(50),
-> created_at datetime,
-> updated_at datetime
-> );
mysql> select * from articles;
Empty set (0.00 sec)
s3から取得したcsvをopenして1行目のカラムを飛ばしてmysqlにinsertしていきます。
try { $dbh = new PDO('mysql:host=localhost;dbname=click;charset=utf8','hoge','hogehoge', array(PDO::ATTR_EMULATE_PREPARES => false)); } catch(PDOException $e){ exit('データベース接続失敗。'.$e->getMessage()); } $stmt = $dbh->prepare('INSERT INTO articles VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?)'); $dbh->beginTransaction(); $fp = fopen('article.csv', 'rb'); $i = 0; while ($row = fgetcsv($fp)){ if($i == 0){ $i++; continue; } if ($row === array(null)){ continue; } $executed = $stmt->execute($row); $i++; } fclose($fp); $dbh->commit();
確認してみましょう。
mysql> select * from articles;
+—-+———-+——–+————–+———–+———————+————————–+—————-+———————+———————+
| id | login_id | role | name | password | mail | test_mail | updated_person | created_at | updated_at |
+—-+———-+——–+————–+———–+———————+————————–+—————-+———————+———————+
| 1 | user1 | master | taniguchi | passowrd | laravel@gmail.com | laravel_test@gmail.com | sasaki | 2018-09-21 21:39:07 | 2018-09-21 21:39:07 |
| 2 | user2 | master | goto | himitsu | laravel@hotmail.com | laravel_test@hotmail.com | sasaki | 2018-09-22 08:31:54 | 2018-09-22 08:51:32 |
| 3 | user3 | master | 橋本太郎 | password3 | laravel@gmail.com | laravel_test@gmail.com | こばやし | 2018-09-22 15:03:11 | 2018-09-22 15:03:11 |
| 4 | user4 | master | 後藤大輔 | password4 | laravel@gmail.com | laravel_test@gmail.com | こばやし | 2018-09-22 15:48:56 | 2018-09-22 15:48:56 |
| 9 | user2 | master | goto | himitsu | laravel@hotmail.com | laravel_test@hotmail.com | sasaki | 2018-09-22 17:41:59 | 2018-09-22 17:41:59 |
+—-+———-+——–+————–+———–+———————+————————–+—————-+———————+———————+
5 rows in set (0.00 sec)
おいおいおい、やべーことになってる。
とりあえず、laravel -> mysql(1) -> csv -> s3 upload -> s3 import -> csv -> mysql(2)の流れは出来た。やはり、laravelが時間かかったな。frameworkの習得は時間がかかる。s3はセキュリティ周りをもっと学習する必要がある。
next
-> SSL
-> githubからdeploy
引き続き、aws sdkを読み込みます。
require_once('vendor/autoload.php'); $s3client = new Aws\S3\S3Client([ 'credentials' => [ 'key' => '', 'secret' => '' ], 'region' => 'ap-northeast-1', 'version' => 'latest', ]); $result = $s3client->getObject([ 'Bucket' => 'hoge', 'Key' => 'article.csv', 'SaveAs' => 'article.csv', ]);
なに、こんなに簡単なのか。。。。。。
続いて、csvからmysql! gogogo!
composerを入れます。
[vagrant@localhost s3]$ curl -sS https://getcomposer.org/installer | php
aws sdkをインストール
[vagrant@localhost s3]$ php composer.phar require aws/aws-sdk-php
consoleでs3のバケットを作成する。
upload
require_once('vendor/autoload.php'); $s3client = new Aws\S3\S3Client([ 'credentials' => [ 'key' => 'A', 'secret' => '' ], 'region' => 'ap-northeast-1', 'version' => 'latest', ]); $result = $s3client->putObject([ 'Bucket' => '', 'Key' => 'article.csv', 'SourceFile' => 'article.csv', 'ContentType' => mime_content_type('article.csv'), ]);
おいおいおい、まじかー
まじかー。2回言ってしまった。
次はuploadしたS3のバケットからCSVをダウンロードして、mysqlの異なるdb・tableにinsertする。