Ubuntu 24.04
Sponsored Link

Laravel : Install2024/05/17

 
Install Laravel which is a PHP Web application framework.
[1] Install PHP Composer first.
root@dlp:~#
apt -y install composer php8.3-curl php8.3-sqlite3

[2] Create a Laravel test project with a common user.
ubuntu@dlp:~$
mkdir test-project

ubuntu@dlp:~$
cd test-project
# create [my-app] Laravel project

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

Creating a "laravel/laravel" project at "./my-app"
Installing laravel/laravel (v11.0.8)
  - Installing laravel/laravel (v11.0.8): Extracting archive
Created project in /home/ubuntu/test-project/my-app

.....
.....

85 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.

> @php -r "file_exists('database/database.sqlite') || touch('database/database.sqlite');"
> @php artisan migrate --graceful --ansi

   INFO  Preparing database.

  Creating migration table ...................................... 84.31ms DONE

   INFO  Running migrations.

  0001_01_01_000000_create_users_table .......................... 25.24ms DONE
  0001_01_01_000001_create_cache_table .......................... 10.23ms DONE
  0001_01_01_000002_create_jobs_table ........................... 20.89ms DONE

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

ubuntu@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
  Access to the URL you set from any client computer, and then that's OK if following site is shown.
[3] Create a sample Hello World app.
ubuntu@dlp:~$
cd ~/test-project/my-app
# create [HelloWorldController] controller

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


   INFO  Controller [app/Http/Controllers/HelloWorldController.php] created successfully.

ubuntu@dlp:~/test-project/my-app$
vi routes/web.php
; add to last line

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

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

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

ubuntu@dlp:~/test-project/my-app$
vi resources/views/helloworld.blade.php
; create index

<!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>

ubuntu@dlp:~/test-project/my-app$
php artisan serve --host 0.0.0.0 --port=8000
Matched Content