CentOS Stream 9
Sponsored Link

CakePHP : インストール2022/06/28

 
PHP の Web アプリケーションフレームワーク CakePHP のインストールです。
[1] 事前に必要な PHP モジュールをインストールしておきます。
# EPEL からインストール

[root@dlp ~]#
dnf --enablerepo=epel -y install composer

[2] 任意の一般ユーザーで CakePHP テストプロジェクトを作成して動作確認します。
[cent@dlp ~]$
mkdir test-project

[cent@dlp ~]$
cd test-project
# CakePHP プロジェクト [my-app] 作成

[cent@dlp test-project]$
composer create-project cakephp/app my-app

Creating a "cakephp/app" project at "./my-app"
Info from https://repo.packagist.org: #StandWithUkraine
Installing cakephp/app (4.4.1)
  - Downloading cakephp/app (4.4.1)
  - Installing cakephp/app (4.4.1): Extracting archive
Created project in /home/cent/test-project/my-app
Loading composer repositories with package information
Updating dependencies
Lock file operations: 92 installs, 0 updates, 0 removals

.....
.....

Created `config/app_local.php` file
Created `/home/cent/test-project/my-app/logs` directory
Created `/home/cent/test-project/my-app/tmp/cache/views` directory
Set Folder Permissions ? (Default to Y) [Y,n]? y
Permissions set on /home/cent/test-project/my-app/tmp/cache
Permissions set on /home/cent/test-project/my-app/tmp/cache/models
Permissions set on /home/cent/test-project/my-app/tmp/cache/persistent
Permissions set on /home/cent/test-project/my-app/tmp/cache/views
Permissions set on /home/cent/test-project/my-app/tmp/sessions
Permissions set on /home/cent/test-project/my-app/tmp/tests
Permissions set on /home/cent/test-project/my-app/tmp
Permissions set on /home/cent/test-project/my-app/logs
Updated Security.salt value in config/app_local.php

[cent@dlp test-project]$
cd my-app

[cent@dlp my-app]$
./bin/cake server -H 0.0.0.0 -p 8765


Welcome to CakePHP v4.4.1 Console
-------------------------------------------------------------------------------
App : src
Path: /home/cent/test-project/my-app/src/
DocumentRoot: /home/cent/test-project/my-app/webroot
Ini Path:
-------------------------------------------------------------------------------
built-in server is running in http://0.0.0.0:8765/
You can exit with `CTRL-C`
[Tue Jun 28 13:50:38 2022] PHP 8.0.13 Development Server (http://0.0.0.0:8765) started
  任意のクライアントコンピューターで Web アクセスして、以下のようなページが表示されれば OK です。
[3] 先に作成したプロジェクトで Hello World を作成して動作確認します。
[cent@dlp ~]$
cd ~/test-project/my-app
[cent@dlp my-app]$
vi src/Controller/HelloWorldController.php
# 新規作成

<?php

namespace App\Controller;

class HelloWorldController extends AppController
{
    public function index()
    {
    }
}

[cent@dlp my-app]$
mkdir templates/HelloWorld

[cent@dlp my-app]$
vi templates/HelloWorld/index.php
# 表示する HTML 作成

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Hello World</title>
</head>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Hello CakePHP World!
</div>
</body>
</html>

[cent@dlp my-app]$
./bin/cake server -H 0.0.0.0 -p 8765

関連コンテンツ