Install Laravel First Time In Ubuntu Linux

Posted on

Laravel 9 Ubuntu Step by Step

In this article I will share how to install Laravel for the first time step by step. This article is special for those of you who are just starting to learn Laravel framework.

Install Composer

Before installing Laravel, the first thing you must install is Composer.

Composer is a tool that contains dependencies and a collection of libraries of php.

Laravel will be installed to your linux through Composer.

To install Composer, please use command below:

sudo apt install composer

Or go to the official page here.

After the installation is complete, please check the version of Composer with the command “composer -v” like this:

neon@linux:~$ composer -v
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer 2.2.6 2022-02-04 17:00:38

From the terminal results, it can be seen that I am using composer version 2.2.6.

Install PHP

Usually, composer will install php automatically. You can check this with the command:

neon@linux:~$ php -v
PHP 8.1.2 (cli) (built: Aug 15 2022 12:24:10) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

If the result is like that, then PHP has been installed on your linux.

But if not, you have to install it manually with the command:

sudo apt install php php-common php-bcmath php-mbstring php-mysql php-tokenizer php-zip	

Install Laravel

After Composer is finished installing. Let’s create our project for the first time.

So, now I want to create a laravel project with the name is “firsts_laravel” and saving it to “Document” folder.

Open a terminal and navigate to Document. The command used is:

cd Documents

Now, still in the Document folder, use the following command to install laravel:

composer create-project laravel/laravel first-laravel

Please wait a moment…

If You Get Error Your requirements could not be resolved to an installable set of packages

Usually this happens because there is no PHP XML and CURL.

The fix is to install the both packages.

The way to install it is to open a terminal, use the following command:

sudo apt-get install php-xml php-curl

Now, please delete the “first-laravel” folder with the command:

sudo rm -r first-laravel

Then now repeat the steps to install laravel:

composer create-project laravel/laravel first-laravel

If the Installation is Successful

If you have installed it, you will get a message like this:

neon@linux:~/Documents/LARAVEL$ composer create-project laravel/laravel first-laravel
Creating a "laravel/laravel" project at "./first-laravel"
Info from https://repo.packagist.org: #StandWithUkraine
Installing laravel/laravel (v9.3.5)
  - Installing laravel/laravel (v9.3.5): Extracting archive
Created project in /home/neon/Documents/LARAVEL/first-laravel
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 105 installs, 0 updates, 0 removals
  - Locking brick/math (0.10.2)
  - Locking dflydev/dot-access-data (v3.0.1)
  - Locking doctrine/inflector (2.0.4)
  - Locking doctrine/instantiator (1.4.1)
  - Locking doctrine/lexer (1.2.3)
  - Locking dragonmantank/cron-expression (v3.3.1)
  - Locking egulias/email-validator (3.2.1)
  - Locking fakerphp/faker (v1.20.0)
  - Locking filp/whoops (2.14.5)
  - Locking fruitcake/php-cors (v1.2.0)
  - Locking graham-campbell/result-type (v1.1.0)
  - Locking guzzlehttp/guzzle (7.5.0)
  - Locking guzzlehttp/promises (1.5.2)
  - Locking guzzlehttp/psr7 (2.4.1)
  - Locking hamcrest/hamcrest-php (v2.0.1)
  - Locking laravel/framework (v9.26.1)
  - Locking laravel/pint (v1.1.1)
  - Locking laravel/sail (v1.15.4)
  - Locking laravel/sanctum (v3.0.1)
  - Locking laravel/serializable-closure (v1.2.0)
  - Locking laravel/tinker (v2.7.2)
  - Locking league/commonmark (2.3.5)
  - Locking league/config (v1.1.1)
  - Locking league/flysystem (3.2.1)
  - Locking league/mime-type-detection (1.11.0)
  - Locking mockery/mockery (1.5.0)
  - Locking monolog/monolog (2.8.0)
  - Locking myclabs/deep-copy (1.11.0)
  - Locking nesbot/carbon (2.62.0)
  - Locking nette/schema (v1.2.2)
  - Locking nette/utils (v3.2.7)
  - Locking nikic/php-parser (v4.14.0)
  - Locking nunomaduro/collision (v6.3.0)
  - Locking nunomaduro/termwind (v1.14.0)
  - Locking phar-io/manifest (2.0.3)
  - Locking phar-io/version (3.2.1)
  - Locking phpoption/phpoption (1.9.0)
  - Locking phpunit/php-code-coverage (9.2.16)
  - Locking phpunit/php-file-iterator (3.0.6)
  - Locking phpunit/php-invoker (3.1.1)
  - Locking phpunit/php-text-template (2.0.4)
  - Locking phpunit/php-timer (5.0.3)
  - Locking phpunit/phpunit (9.5.23)
  - Locking psr/container (2.0.2)
  - Locking psr/event-dispatcher (1.0.0)
  - Locking psr/http-client (1.0.1)
  - Locking psr/http-factory (1.0.1)
  - Locking psr/http-message (1.0.1)
  - Locking psr/log (3.0.0)
  - Locking psr/simple-cache (3.0.0)
  - Locking psy/psysh (v0.11.8)
  - Locking ralouphie/getallheaders (3.0.3)
  - Locking ramsey/collection (1.2.2)
  - Locking ramsey/uuid (4.4.0)
  - Locking sebastian/cli-parser (1.0.1)
  - Locking sebastian/code-unit (1.0.8)
  - Locking sebastian/code-unit-reverse-lookup (2.0.3)
  - Locking sebastian/comparator (4.0.6)
  - Locking sebastian/complexity (2.0.2)
  - Locking sebastian/diff (4.0.4)
  - Locking sebastian/environment (5.1.4)
  - Locking sebastian/exporter (4.0.4)
  - Locking sebastian/global-state (5.0.5)
  - Locking sebastian/lines-of-code (1.0.3)
  - Locking sebastian/object-enumerator (4.0.4)
  - Locking sebastian/object-reflector (2.0.4)
  - Locking sebastian/recursion-context (4.0.4)
  - Locking sebastian/resource-operations (3.0.3)
  - Locking sebastian/type (3.1.0)
  - Locking sebastian/version (3.0.2)
  - Locking spatie/backtrace (1.2.1)
  - Locking spatie/flare-client-php (1.3.0)
  - Locking spatie/ignition (1.4.1)
  - Locking spatie/laravel-ignition (1.4.0)
  - Locking symfony/console (v6.1.4)
  - Locking symfony/css-selector (v6.1.3)
  - Locking symfony/deprecation-contracts (v3.1.1)
  - Locking symfony/error-handler (v6.1.3)
  - Locking symfony/event-dispatcher (v6.1.0)
  - Locking symfony/event-dispatcher-contracts (v3.1.1)
  - Locking symfony/finder (v6.1.3)
  - Locking symfony/http-foundation (v6.1.4)
  - Locking symfony/http-kernel (v6.1.4)
  - Locking symfony/mailer (v6.1.4)
  - Locking symfony/mime (v6.1.4)
  - Locking symfony/polyfill-ctype (v1.26.0)
  - Locking symfony/polyfill-intl-grapheme (v1.26.0)
  - Locking symfony/polyfill-intl-idn (v1.26.0)
  - Locking symfony/polyfill-intl-normalizer (v1.26.0)
  - Locking symfony/polyfill-mbstring (v1.26.0)
  - Locking symfony/polyfill-php72 (v1.26.0)
  - Locking symfony/polyfill-php80 (v1.26.0)
  - Locking symfony/polyfill-php81 (v1.26.0)
  - Locking symfony/process (v6.1.3)
  - Locking symfony/routing (v6.1.3)
  - Locking symfony/service-contracts (v3.1.1)
  - Locking symfony/string (v6.1.4)
  - Locking symfony/translation (v6.1.4)
  - Locking symfony/translation-contracts (v3.1.1)
  - Locking symfony/var-dumper (v6.1.3)
  - Locking theseer/tokenizer (1.2.1)
  - Locking tijsverkoyen/css-to-inline-styles (2.2.4)
  - Locking vlucas/phpdotenv (v5.4.1)
  - Locking voku/portable-ascii (2.0.1)
  - Locking webmozart/assert (1.11.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 105 installs, 0 updates, 0 removals
  - Downloading doctrine/inflector (2.0.4)
  - Downloading doctrine/lexer (1.2.3)
  - Downloading symfony/polyfill-ctype (v1.26.0)
  - Downloading webmozart/assert (1.11.0)
  - Downloading dragonmantank/cron-expression (v3.3.1)
  - Downloading symfony/deprecation-contracts (v3.1.1)
  - Downloading psr/container (2.0.2)
  - Downloading fakerphp/faker (v1.20.0)
  - Downloading symfony/polyfill-mbstring (v1.26.0)
  - Downloading symfony/http-foundation (v6.1.4)
  - Downloading fruitcake/php-cors (v1.2.0)
  - Downloading psr/http-message (1.0.1)
  - Downloading psr/http-client (1.0.1)
  - Downloading ralouphie/getallheaders (3.0.3)
  - Downloading psr/http-factory (1.0.1)
  - Downloading guzzlehttp/psr7 (2.4.1)
  - Downloading guzzlehttp/promises (1.5.2)
  - Downloading guzzlehttp/guzzle (7.5.0)
  - Downloading laravel/pint (v1.1.1)
  - Downloading voku/portable-ascii (2.0.1)
  - Downloading symfony/polyfill-php80 (v1.26.0)
  - Downloading phpoption/phpoption (1.9.0)
  - Downloading graham-campbell/result-type (v1.1.0)
  - Downloading vlucas/phpdotenv (v5.4.1)
  - Downloading symfony/css-selector (v6.1.3)
  - Downloading tijsverkoyen/css-to-inline-styles (2.2.4)
  - Downloading symfony/var-dumper (v6.1.3)
  - Downloading symfony/routing (v6.1.3)
  - Downloading symfony/process (v6.1.3)
  - Downloading symfony/polyfill-php72 (v1.26.0)
  - Downloading symfony/polyfill-intl-normalizer (v1.26.0)
  - Downloading symfony/polyfill-intl-idn (v1.26.0)
  - Downloading symfony/mime (v6.1.4)
  - Downloading symfony/service-contracts (v3.1.1)
  - Downloading psr/event-dispatcher (1.0.0)
  - Downloading symfony/event-dispatcher-contracts (v3.1.1)
  - Downloading symfony/event-dispatcher (v6.1.0)
  - Downloading psr/log (3.0.0)
  - Downloading egulias/email-validator (3.2.1)
  - Downloading symfony/mailer (v6.1.4)
  - Downloading symfony/error-handler (v6.1.3)
  - Downloading symfony/http-kernel (v6.1.4)
  - Downloading symfony/finder (v6.1.3)
  - Downloading symfony/polyfill-intl-grapheme (v1.26.0)
  - Downloading symfony/string (v6.1.4)
  - Downloading symfony/console (v6.1.4)
  - Downloading symfony/polyfill-php81 (v1.26.0)
  - Downloading ramsey/collection (1.2.2)
  - Downloading brick/math (0.10.2)
  - Downloading ramsey/uuid (4.4.0)
  - Downloading psr/simple-cache (3.0.0)
  - Downloading nunomaduro/termwind (v1.14.0)
  - Downloading symfony/translation-contracts (v3.1.1)
  - Downloading symfony/translation (v6.1.4)
  - Downloading nesbot/carbon (2.62.0)
  - Downloading monolog/monolog (2.8.0)
  - Downloading league/mime-type-detection (1.11.0)
  - Downloading league/flysystem (3.2.1)
  - Downloading nette/utils (v3.2.7)
  - Downloading nette/schema (v1.2.2)
  - Downloading dflydev/dot-access-data (v3.0.1)
  - Downloading league/config (v1.1.1)
  - Downloading league/commonmark (2.3.5)
  - Downloading laravel/serializable-closure (v1.2.0)
  - Downloading laravel/framework (v9.26.1)
  - Downloading laravel/sail (v1.15.4)
  - Downloading laravel/sanctum (v3.0.1)
  - Downloading nikic/php-parser (v4.14.0)
  - Downloading psy/psysh (v0.11.8)
  - Downloading laravel/tinker (v2.7.2)
  - Downloading hamcrest/hamcrest-php (v2.0.1)
  - Downloading mockery/mockery (1.5.0)
  - Downloading filp/whoops (2.14.5)
  - Downloading nunomaduro/collision (v6.3.0)
  - Downloading sebastian/version (3.0.2)
  - Downloading sebastian/type (3.1.0)
  - Downloading sebastian/resource-operations (3.0.3)
  - Downloading sebastian/recursion-context (4.0.4)
  - Downloading sebastian/object-reflector (2.0.4)
  - Downloading sebastian/object-enumerator (4.0.4)
  - Downloading sebastian/global-state (5.0.5)
  - Downloading sebastian/exporter (4.0.4)
  - Downloading sebastian/environment (5.1.4)
  - Downloading sebastian/diff (4.0.4)
  - Downloading sebastian/comparator (4.0.6)
  - Downloading sebastian/code-unit (1.0.8)
  - Downloading sebastian/cli-parser (1.0.1)
  - Downloading phpunit/php-timer (5.0.3)
  - Downloading phpunit/php-text-template (2.0.4)
  - Downloading phpunit/php-invoker (3.1.1)
  - Downloading phpunit/php-file-iterator (3.0.6)
  - Downloading theseer/tokenizer (1.2.1)
  - Downloading sebastian/lines-of-code (1.0.3)
  - Downloading sebastian/complexity (2.0.2)
  - Downloading sebastian/code-unit-reverse-lookup (2.0.3)
  - Downloading phpunit/php-code-coverage (9.2.16)
  - Downloading phar-io/version (3.2.1)
  - Downloading phar-io/manifest (2.0.3)
  - Downloading myclabs/deep-copy (1.11.0)
  - Downloading doctrine/instantiator (1.4.1)
  - Downloading phpunit/phpunit (9.5.23)
  - Downloading spatie/backtrace (1.2.1)
  - Downloading spatie/flare-client-php (1.3.0)
  - Downloading spatie/ignition (1.4.1)
  - Downloading spatie/laravel-ignition (1.4.0)
  - Installing doctrine/inflector (2.0.4): Extracting archive
  - Installing doctrine/lexer (1.2.3): Extracting archive
  - Installing symfony/polyfill-ctype (v1.26.0): Extracting archive
  - Installing webmozart/assert (1.11.0): Extracting archive
  - Installing dragonmantank/cron-expression (v3.3.1): Extracting archive
  - Installing symfony/deprecation-contracts (v3.1.1): Extracting archive
  - Installing psr/container (2.0.2): Extracting archive
  - Installing fakerphp/faker (v1.20.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.26.0): Extracting archive
  - Installing symfony/http-foundation (v6.1.4): Extracting archive
  - Installing fruitcake/php-cors (v1.2.0): Extracting archive
  - Installing psr/http-message (1.0.1): Extracting archive
  - Installing psr/http-client (1.0.1): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
  - Installing psr/http-factory (1.0.1): Extracting archive
  - Installing guzzlehttp/psr7 (2.4.1): Extracting archive
  - Installing guzzlehttp/promises (1.5.2): Extracting archive
  - Installing guzzlehttp/guzzle (7.5.0): Extracting archive
  - Installing laravel/pint (v1.1.1): Extracting archive
  - Installing voku/portable-ascii (2.0.1): Extracting archive
  - Installing symfony/polyfill-php80 (v1.26.0): Extracting archive
  - Installing phpoption/phpoption (1.9.0): Extracting archive
  - Installing graham-campbell/result-type (v1.1.0): Extracting archive
  - Installing vlucas/phpdotenv (v5.4.1): Extracting archive
  - Installing symfony/css-selector (v6.1.3): Extracting archive
  - Installing tijsverkoyen/css-to-inline-styles (2.2.4): Extracting archive
  - Installing symfony/var-dumper (v6.1.3): Extracting archive
  - Installing symfony/routing (v6.1.3): Extracting archive
  - Installing symfony/process (v6.1.3): Extracting archive
  - Installing symfony/polyfill-php72 (v1.26.0): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.26.0): Extracting archive
  - Installing symfony/polyfill-intl-idn (v1.26.0): Extracting archive
  - Installing symfony/mime (v6.1.4): Extracting archive
  - Installing symfony/service-contracts (v3.1.1): Extracting archive
  - Installing psr/event-dispatcher (1.0.0): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v3.1.1): Extracting archive
  - Installing symfony/event-dispatcher (v6.1.0): Extracting archive
  - Installing psr/log (3.0.0): Extracting archive
  - Installing egulias/email-validator (3.2.1): Extracting archive
  - Installing symfony/mailer (v6.1.4): Extracting archive
  - Installing symfony/error-handler (v6.1.3): Extracting archive
  - Installing symfony/http-kernel (v6.1.4): Extracting archive
  - Installing symfony/finder (v6.1.3): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.26.0): Extracting archive
  - Installing symfony/string (v6.1.4): Extracting archive
  - Installing symfony/console (v6.1.4): Extracting archive
  - Installing symfony/polyfill-php81 (v1.26.0): Extracting archive
  - Installing ramsey/collection (1.2.2): Extracting archive
  - Installing brick/math (0.10.2): Extracting archive
  - Installing ramsey/uuid (4.4.0): Extracting archive
  - Installing psr/simple-cache (3.0.0): Extracting archive
  - Installing nunomaduro/termwind (v1.14.0): Extracting archive
  - Installing symfony/translation-contracts (v3.1.1): Extracting archive
  - Installing symfony/translation (v6.1.4): Extracting archive
  - Installing nesbot/carbon (2.62.0): Extracting archive
  - Installing monolog/monolog (2.8.0): Extracting archive
  - Installing league/mime-type-detection (1.11.0): Extracting archive
  - Installing league/flysystem (3.2.1): Extracting archive
  - Installing nette/utils (v3.2.7): Extracting archive
  - Installing nette/schema (v1.2.2): Extracting archive
  - Installing dflydev/dot-access-data (v3.0.1): Extracting archive
  - Installing league/config (v1.1.1): Extracting archive
  - Installing league/commonmark (2.3.5): Extracting archive
  - Installing laravel/serializable-closure (v1.2.0): Extracting archive
  - Installing laravel/framework (v9.26.1): Extracting archive
  - Installing laravel/sail (v1.15.4): Extracting archive
  - Installing laravel/sanctum (v3.0.1): Extracting archive
  - Installing nikic/php-parser (v4.14.0): Extracting archive
  - Installing psy/psysh (v0.11.8): Extracting archive
  - Installing laravel/tinker (v2.7.2): Extracting archive
  - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
  - Installing mockery/mockery (1.5.0): Extracting archive
  - Installing filp/whoops (2.14.5): Extracting archive
  - Installing nunomaduro/collision (v6.3.0): Extracting archive
  - Installing sebastian/version (3.0.2): Extracting archive
  - Installing sebastian/type (3.1.0): Extracting archive
  - Installing sebastian/resource-operations (3.0.3): Extracting archive
  - Installing sebastian/recursion-context (4.0.4): Extracting archive
  - Installing sebastian/object-reflector (2.0.4): Extracting archive
  - Installing sebastian/object-enumerator (4.0.4): Extracting archive
  - Installing sebastian/global-state (5.0.5): Extracting archive
  - Installing sebastian/exporter (4.0.4): Extracting archive
  - Installing sebastian/environment (5.1.4): Extracting archive
  - Installing sebastian/diff (4.0.4): Extracting archive
  - Installing sebastian/comparator (4.0.6): Extracting archive
  - Installing sebastian/code-unit (1.0.8): Extracting archive
  - Installing sebastian/cli-parser (1.0.1): Extracting archive
  - Installing phpunit/php-timer (5.0.3): Extracting archive
  - Installing phpunit/php-text-template (2.0.4): Extracting archive
  - Installing phpunit/php-invoker (3.1.1): Extracting archive
  - Installing phpunit/php-file-iterator (3.0.6): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing sebastian/lines-of-code (1.0.3): Extracting archive
  - Installing sebastian/complexity (2.0.2): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
  - Installing phpunit/php-code-coverage (9.2.16): Extracting archive
  - Installing phar-io/version (3.2.1): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.11.0): Extracting archive
  - Installing doctrine/instantiator (1.4.1): Extracting archive
  - Installing phpunit/phpunit (9.5.23): Extracting archive
  - Installing spatie/backtrace (1.2.1): Extracting archive
  - Installing spatie/flare-client-php (1.3.0): Extracting archive
  - Installing spatie/ignition (1.4.1): Extracting archive
  - Installing spatie/laravel-ignition (1.4.0): Extracting archive
58 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   INFO  Discovering packages.  

  laravel/sail ...................................................................................................... DONE
  laravel/sanctum ................................................................................................... DONE
  laravel/tinker .................................................................................................... DONE
  nesbot/carbon ..................................................................................................... DONE
  nunomaduro/collision .............................................................................................. DONE
  nunomaduro/termwind ............................................................................................... DONE
  spatie/laravel-ignition ........................................................................................... DONE

79 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].  

> @php artisan key:generate --ansi

   INFO  Application key set successfully. 

Application key set successfully means that laravel has been installed.

Check Laravel Version

Now go to the “first-laravel” folder using the following command:

cd first-laravel

To check the laravel version installed in the “first-laravel” project, use the following command:

php artisan -V

Then it will come out like in the following terminal:

neon@linux:~/Documents/first-laravel$ php artisan -V
Laravel Framework 9.27.0

If you want to check the files, please go to Documents > first-laravel as shown below:

Install Laravel First Time In Ubuntu Linux

First Testing

In the first-laravel folder, let’s test our laravel project can run in a web browser.

We use Laravel’s artisan command to create the serve address. The command used is:

php artisan serve

The artisan command will automatically create an address, as shown below.

neon@linux:~/Documents/first-laravel$ php artisan serve

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

  Press Ctrl+C to stop the server

The address is http://127.0.0.1:8000.

Move the cursor to the address in the terminal, press CTRL + Click.

Or Copy the address, then open a browser and paste and “Enter”.

If it looks like the following image, Laravel has been successfully installed on our laptop.

Install Laravel First Time In Ubuntu Linux

What’s Next?

It would be nice to learn about CRUD (Create Read Update and Delete) because it will be very widely used in applications.

Hopefully this Install Laravel First Time In Ubuntu Linux article is useful.

Read more:

> Guide to install android studio Linux Pop OS
> Check PHP Version Ubuntu Linux Distro Command