Wednesday, January 31, 2024

EC2 に Flask をインストール

 

EC2上にDockerをインストールする

まず、EC2 インスタンス作成(過去の投稿:EC2 インスタンス起動メモ

Amazon Linux 2023

sudo yum -y update

sudo yum -y install python3


sudo yum install python3-pip


pip3 install flask


cd /opt sudo mkdir flask sudo chown -R ec2-user:ec2-user flask cd flask mkdir project cd project


app.py
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
  return "世界のみなさん、こんにちは"




flask run



でも、なぜか動かない、、、下記で動いた。


理由はよくわからない。。。






Sunday, January 7, 2024

AWS S3

S3 Bucket を使って静的 Web サイトを表示:

S3 は 5GB まで無料枠で使えるようなので(そんなに使わないけど)、スタティックなサイトであれば S3 で十分と、HTML ファイルを置いて公開してみた。

S3 サービスを選択:

Create bucket:

上記の Bucket name を DNS のサブドメイン名と合しておかないと下記のような 404 Not Found になった、、、ので、今回、Bucket name を アサインする予定のと同じにしておいた。

Created:

Create access point:

Property:

Static website hosting:

Enable:

Permissions -> Bucket policy:

Upload some test files:

Uploaded:

S3 Bucket の Static website hosting address:

DNS レコードにエイリアス(CNAME)を設定:


Thursday, January 4, 2024

Visual Studio Code のインストール

もう 30 年前だろうか、、、学生の時、Visual Studio C++ とか Borland C++ とか、高価だったけど買わなくてはクラス取れないし、生活費を削って無理して買った記憶がありますが、今は Visual Studio Code という簡易版?の IDE が無償利用できるらしいのでインストールしてみた。


インストール後(手順は省略)、作業フォルダー指定:

新規ファイル作成:

Old School の自分だと NotePad や NotePad++ で十分のような気もしますが、ショートカットとか充実しているそうなので、これを HTML エディタとして使っていこうと思います。

ショートカット例(Shift + !):

追記:VSCode で EC2 インスタンスにアクセスする(ターミナル)

PuTTY でアクセスしていたが、VSCodeをターミナルとしてアクセスできる便利エクステンションがあるので利用。




























Wednesday, January 3, 2024

Friday, December 29, 2023

VirtualHost の設定(複数バーチャル・ホスト)

小ネタですが、サブドメインなど複数バーチャル・ホストを設定したときのメモ

/etc/httpd/conf.d/vhost.conf 内、下記の記述があるので、ServerName をサブドメイン(もしくは別ドメイン)に変更した <VirtualHost *:80> から </VirtualHost> までを丸ごとコピー&ペーストして、vhost.conf に追加(オリジナルのドメインの記述はそのまま):

<VirtualHost *:80>

  # REQUIRED. Set this to the host/domain/subdomain that
  # you want this VirtualHost record to handle.

  ServerName ほげほげ.com

  # Optional. You can specify additional host names that
  # serve up the same site. This can be top-level, domains,
  # sub-domains, and can even use wildcard subdomains such
  # as *.yourdomain.com - just separate each host name
  # with a single space.

  #ServerAlias ほげほげ.com

  # REQUIRED. Set this to the directory you want to use for
  # this vhost site's files.

  DocumentRoot /var/www/html/ほげほげ

  # Optional. Uncomment this and set it to your admin email
  # address, if you have one. If there is a server error,
  # this is the address that Apache will show to users.

  ServerAdmin admin@ほげほげ.com

  # Optional. Uncomment this if you want to specify
  # a different error log file than the default. You will
  # need to create the error file first.

  #ErrorLog /var/www/vhosts/logs/error_log

  # REQUIRED. Let's make sure that .htaccess files work on 
  # this site. Don't forget to change the file path to
  # match your DocumentRoot setting above.
  
  <Directory /var/www/html>
    AllowOverride All
  </Directory>

</VirtualHost>

Apache を再起動して設定を反映:

 sudo systemctl restart httpd 

DocumentRoot は別ディレクトリに作成して、アクセス権を設定(参照

SSL は追加したドメイン(またはサブドメイン)ごとに新規に証明書を生成しなくてはいけないが(参照今回はスキップ。

Thursday, December 28, 2023

WordPress の設定

インストールができましたので(参照)、実際にブログをポストしてみたいと思います。

WordPress の設定:

ターミナルで接続して、直接、wp-config-sample.php を開きデータベース情報を記入し wp-config.php として保存することもできますが、今回はブラウザーから設定してみます。

MySQL をインストール時に作成したアカウント(実際は WordPress 用アカウントを作成することが推奨ですが練習なのでマスターアカウントを使ってます)と DB 名を入力:

無事 DB に接続できましたのでインストール開始:


WordPress を使ってみる:

アカウントの設定:

アカウントが作成されました:

作成されたアカウントでログインしてみます:

無事ログインできました:

左ペインの [外観] からテーマを選択(もしくは追加):
*今回はテストなのでディフォルトのまま。

[新規投稿を追加] からポストしてみます。

テスト投稿を [公開]:

無事公開されました(SSL も有効です):