1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

検証:Azure AppserviceとGithub連携でphp/htmlをデプロイ

Posted at

背景

最近、環境構築する際、Azure Appservice上で本物のweb application をデプロイする必要の場面がしばしばでます。やはりまじめにdeployしないといけないと痛感して、AppserviceとGithubを利用して、phpのfileuploadのweb appをデプロイしてみました。

作業手順

1.まずAIを利用して以下のphp codeを作成してもらいました。

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>テキストファイルアップロード</title>
</head>
<body>
    <h2>テキストファイルアップロード</h2>
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" name="textfile" accept=".txt">
        <input type="submit" value="アップロード">
    </form>

    <?php
    if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["textfile"])) {
        $uploadDir = "uploads/";
        $uploadFile = $uploadDir . basename($_FILES["textfile"]["name"]);
        
        // アップロードディレクトリが存在しない場合は作成
        if (!file_exists($uploadDir)) {
            mkdir($uploadDir, 0777, true);
        }

        // ファイルがテキストファイルかチェック
        $fileType = pathinfo($uploadFile, PATHINFO_EXTENSION);
        if ($fileType != "txt") {
            echo "<p>エラー: テキストファイル(.txt)のみアップロード可能です。</p>";
        } else {
            // ファイルを指定ディレクトリに移動
            if (move_uploaded_file($_FILES["textfile"]["tmp_name"], $uploadFile)) {
                echo "<p>ファイルが正常にアップロードされました: " . htmlspecialchars(basename($uploadFile)) . "</p>";
            } else {
                echo "<p>エラー: ファイルのアップロードに失敗しました。</p>";
            }
        }
    }
    ?>
</body>
</html>

2.GithubにRepository[php-docs-hello-world2]を作って、中のindex.phpファイルを修正して、1のphp codeをいれて、Masterに直接commitします。
image.png

3.Azure Appserviceの[Deployment]にてソースを[Github]を選択します。
image.png

4.適切に選択します。最後はSaveします。デプロイ開始。
image.png

5.LogではsucceededになったらOKです。
image.png

6.Accessしてみると、oh,予想通りの画面が出てきましたね。
image.png

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?