Laravel is a popular open source, free to customize and adopt PHP framework used in building of web applications. It has an easy syntax, elegant design, and its overall experienced biased on the developer experience. Some of the notable features in Laravel are:

  • It uses MVC Architecture: Laravel follows Model-View-Controller (MVC) pattern ensuring neatness in code structuring and perfect separation of concerns.
  • Laravel adopts Object-Oriented Approach: The core of Laravel is designed with the object-oriented programming principles hence easy to re-use and maintain.
  • Laravel uses Modular Packaging: The functionalities of Laravel are packaged in modules. This allows for development of each component independently.

If you’re interested in how Laravel can be installed on an Ubuntu Linux system, then this article is for you. Users interested in CakePHP can read the article available in our website. There are tons of resources online already written about Laravel. This includes the official Laravel documentation, various community tutorials, and YouTube videos that you can search and reference when doing your projects.

Before installation of Laravel, PHP has to be installed on your local system. Update OS packages list index.

sudo apt update

Install PHP and required dependencies.

sudo apt install php php-{cli,json,mysql,zip,gd,mbstring,curl,xml,pear,bcmath,sqlite3}

Proceed with the installation by keying y in your keyboard.

0 upgraded, 61 newly installed, 0 to remove and 29 not upgraded.
Need to get 14.0 MB of archives.
After this operation, 52.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Check the version of PHP installed.

$ php --version
PHP 8.3.6 (cli) (built: Apr 15 2024 19:21:47) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

Install PHP Composer.

sudo apt install composer

We can then create a Laravel test project.

mkdir ~/apps && cd ~/apps

We will create a Laravel project called mywebapp

composer create-project laravel/laravel mywebapp

Sample installation output.

laravel install

To serve the page use

cd mywebapp
php artisan serve --host 0.0.0.0 --port=8000

Sample execution output:

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

  Press Ctrl+C to stop the server

You will see the default Laravel page.

laravel install 02

Let’s create a sample Hello World application.

cd ~/apps/mywebapp
php artisan make:controller HelloWorldController

Add controller creation commands.

$ vim routes/web.php
Route::get('helloworld', 'App\Http\Controllers\HelloWorldController@index');

Create a function.

$ vim app/Http/Controllers/HelloWorldController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

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

$ vim resources/views/helloworld.blade.php
<!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 World from Laravel
</div>
</body>
</html>

Serve the application.

php artisan serve --host 0.0.0.0 --port=8000

Database credentials are set inside the .env file. See example below.

$ vim .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=DBUserPassword

You will then need to run your application’s database migrations:

php artisan migrate

LEAVE A REPLY

Please enter your comment!
Please enter your name here