Debian 13 trixie

Laravel : インストール2025/09/05

 

PHP の Web アプリケーションフレームワーク Laravel のインストールです。

[1] 事前に PHP Composer をインストールしておきます。
root@dlp:~#
apt -y install composer php8.4-curl php8.4-sqlite3

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

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

debian@dlp:~/test-project$
composer create-project laravel/laravel my-app

Creating a "laravel/laravel" project at "./my-app"
Installing laravel/laravel (v12.4.0)
  - Downloading laravel/laravel (v12.4.0)
  - Installing laravel/laravel (v12.4.0): Extracting archive
Created project in /home/debian/test-project/my-app
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 112 installs, 0 updates, 0 removals

.....
.....

81 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force

   INFO  No publishable resources for tag [laravel-assets].

No security vulnerability advisories found.
> @php artisan key:generate --ansi

   INFO  Application key set successfully.

debian@dlp:~/test-project$
cd my-app

debian@dlp:~/test-project$
vi .env
# 30行目 : 変更

#SESSION_DRIVER=
file
debian@dlp:~/test-project/my-app$
php artisan serve --host 0.0.0.0 --port=8000


   INFO  Server running on [http://0.0.0.0:8000].

  Press Ctrl+C to stop the server
  任意のクライアントコンピューターで Web アクセスして、以下のようなページが表示されれば OK です。
[3] 先に作成したプロジェクトで Hello World を作成して動作確認します。
debian@dlp:~$
cd ~/test-project/my-app
# [HelloWorldController] コントローラー作成

debian@dlp:~/test-project/my-app$
php artisan make:controller HelloWorldController

INFO Controller [app/Http/Controllers/HelloWorldController.php] created successfully.
debian@dlp:~/test-project/my-app$
vi routes/web.php
// 最終行に追記

Route::get('helloworld', 'App\Http\Controllers\HelloWorldController@index');
debian@dlp:~/test-project/my-app$
vi app/Http/Controllers/HelloWorldController.php
// function 追記

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HelloWorldController extends Controller
{
    public function index()
    {
        return view('helloworld');
    }
}

debian@dlp:~/test-project/my-app$
vi resources/views/helloworld.blade.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 Laravel World!
</div>
</body>
</html>

debian@dlp:~/test-project/my-app$
php artisan serve --host 0.0.0.0 --port=8000
関連コンテンツ