How to install Laravel on Ubuntu 16.04 or 18.04

This post will guide you how to install Laravel Application on your Ubuntu Linux 18.04 or 16.04. How do I install Laravel PHP framework via Composer Tool on Ubuntu system.

What is Laravel?


Laravel is a web application framework with expressive, elegant syntax. Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller architectural pattern and based on Symfony. Some of the features of Laravel are a modular packaging system with a dedicated dependency manager, different ways for accessing relational databases, utilities that aid in application deployment and maintenance, and its orientation toward syntactic sugar.

install laravel on ubuntu2

Server Requirements


You need to make sure that your system meets the following requirements:

  • PHP >= 7.2.0
  • BCMath PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

Step1: Installing PHP


You need to install PHP 7.2+ in your Ubuntu system. And PHP 7.2 is already available in Ubuntu 18.04 default APT repository. So you just need to run the following command to install PHP 7.2 and all required PHP extensions, type:

$ sudo apt install php libapache2-mod-php
$ sudo apt install php7.2-common php7.2-cli php7.2-fpm php7.2-opcache php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-xsl php7.2-mbstring php7.2-zip php7.2-bcmath php7.2-soap

Outpus:

devops@devops:~$ sudo apt install php libapache2-mod-php
[sudo] password for devops:
Reading package lists... Done
Building dependency tree
Reading state information... Done
libapache2-mod-php is already the newest version (1:7.2+60ubuntu1).
The following packages were automatically installed and are no longer required:
linux-headers-4.18.0-22 linux-headers-4.18.0-22-generic linux-image-4.18.0-22-generic linux-modules-4.18.0-22-generic linux-modules-extra-4.18.0-22-generic
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
php
0 upgraded, 1 newly installed, 0 to remove and 56 not upgraded.
Need to get 3,084 B of archives.
After this operation, 12.3 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.aliyun.com/ubuntu bionic/main amd64 php all 1:7.2+60ubuntu1 [3,084 B]
Fetched 3,084 B in 0s (14.6 kB/s)
Selecting previously unselected package php.
(Reading database ... 210189 files and directories currently installed.)
Preparing to unpack .../php_1%3a7.2+60ubuntu1_all.deb ...
Unpacking php (1:7.2+60ubuntu1) ...
Setting up php (1:7.2+60ubuntu1) ...

devops@devops:~$ sudo apt install php7.2-common php7.2-cli php7.2-fpm php7.2-opcache php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-xsl php7.2-mbstring php7.2-zip php7.2-bcmath php7.2-soap
Reading package lists... Done
Building dependency tree
Reading state information... Done
php7.2-cli is already the newest version (7.2.19-0ubuntu0.18.04.1).
php7.2-common is already the newest version (7.2.19-0ubuntu0.18.04.1).
php7.2-common set to manually installed.
php7.2-curl is already the newest version (7.2.19-0ubuntu0.18.04.1).
php7.2-gd is already the newest version (7.2.19-0ubuntu0.18.04.1).
php7.2-mysql is already the newest version (7.2.19-0ubuntu0.18.04.1).
php7.2-opcache is already the newest version (7.2.19-0ubuntu0.18.04.1).
php7.2-intl is already the newest version (7.2.19-0ubuntu0.18.04.1).
php7.2-mbstring is already the newest version (7.2.19-0ubuntu0.18.04.1).
php7.2-zip is already the newest version (7.2.19-0ubuntu0.18.04.1).
The following packages were automatically installed and are no longer required:
linux-headers-4.18.0-22 linux-headers-4.18.0-22-generic linux-image-4.18.0-22-generic linux-modules-4.18.0-22-generic linux-modules-extra-4.18.0-22-generic
Use 'sudo apt autoremove' to remove them.
Suggested packages:
php-pear
The following NEW packages will be installed:
php7.2-bcmath php7.2-fpm php7.2-soap php7.2-xsl
0 upgraded, 4 newly installed, 0 to remove and 56 not upgraded.
Need to get 1,550 kB of archives.
After this operation, 5,456 kB of additional disk space will be used.
Do you want to continue? [Y/n]Y

Step2: Installing Composer


Laravel use Composer to manage its dependencies, so you can use Composer to install Laravel. Before installing Laravel, you should make sure that you have Composer installed on your system. You can use the below curl command to download the Composer installer. And then move it to /usr/local/bin directory. Type:

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo chmod +x /usr/local/bin/composer

Outputs:

devops@devops:~$ curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
Composer (version 1.9.0) successfully installed to: /home/devops/composer.phar
Use it: php composer.phar

You can verify the installation of Composer by running the following command:

$ composer –version

Outputs:

devops@devops:~$ composer --version
Composer version 1.9.0 2019-08-02 20:55:32

Step3: Installing Laravel


You can install Laravel by issuing the Composer create-project command in your Ubuntu terminal. For Example, if you want to Laravel in the myphp directory. Just type:

$ composer create-project --prefer-dist laravel/laravel myphp

Outputs:

devops@devops:~$ composer create-project --prefer-dist laravel/laravel myphp
Installing laravel/laravel (v6.0.0)
- Installing laravel/laravel (v6.0.0): Downloading (100%)
Created project in myphp
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 80 installs, 0 updates, 0 removals
- Installing symfony/polyfill-ctype (v1.12.0): Downloading (100%)
- Installing phpoption/phpoption (1.5.0): Downloading (100%)
- Installing vlucas/phpdotenv (v3.5.0): Downloading (100%)
- Installing symfony/css-selector (v4.3.4): Downloading (100%)
- Installing tijsverkoyen/css-to-inline-styles (2.2.1): Downloading (100%)
- Installing symfony/polyfill-php72 (v1.12.0): Downloading (100%)
- Installing symfony/polyfill-mbstring (v1.12.0): Downloading (100%)
- Installing symfony/var-dumper (v4.3.4): Downloading (100%)
- Installing symfony/routing (v4.3.4): Downloading (100%)
- Installing symfony/process (v4.3.4): Downloading (100%)
- Installing psr/log (1.1.0): Downloading (100%)
- Installing symfony/polyfill-php73 (v1.12.0): Downloading (100%)
- Installing symfony/debug (v4.3.4): Downloading (100%)
- Installing symfony/polyfill-intl-idn (v1.12.0): Downloading (100%)
- Installing symfony/mime (v4.3.4): Downloading (100%)
- Installing symfony/http-foundation (v4.3.4): Downloading (100%)
- Installing symfony/event-dispatcher-contracts (v1.1.5): Downloading (100%)
- Installing psr/container (1.0.0): Downloading (100%)
- Installing symfony/event-dispatcher (v4.3.4): Downloading (100%)
- Installing symfony/http-kernel (v4.3.4): Downloading (100%)
- Installing symfony/finder (v4.3.4): Downloading (100%)
- Installing symfony/service-contracts (v1.1.6): Downloading (100%)
- Installing symfony/console (v4.3.4): Downloading (100%)
- Installing symfony/polyfill-iconv (v1.12.0): Downloading (100%)
- Installing doctrine/lexer (1.1.0): Downloading (100%)
- Installing egulias/email-validator (2.1.11): Downloading (100%)
- Installing swiftmailer/swiftmailer (v6.2.1): Downloading (100%)
- Installing paragonie/random_compat (v9.99.99): Downloading (100%)
- Installing ramsey/uuid (3.8.0): Downloading (100%)
- Installing psr/simple-cache (1.0.1): Downloading (100%)
- Installing opis/closure (3.4.0): Downloading (100%)
- Installing symfony/translation-contracts (v1.1.6): Downloading (100%)
- Installing symfony/translation (v4.3.4): Downloading (100%)
- Installing nesbot/carbon (2.24.0): Downloading (100%)
- Installing monolog/monolog (2.0.0): Downloading (100%)
- Installing league/flysystem (1.0.55): Downloading (100%)
- Installing erusev/parsedown (1.7.3): Downloading (100%)
- Installing dragonmantank/cron-expression (v2.3.0): Downloading (100%)
- Installing doctrine/inflector (v1.3.0): Downloading (100%)
- Installing laravel/framework (v6.0.0): Downloading (100%)
- Installing fideloper/proxy (4.2.1): Downloading (100%)
- Installing jakub-onderka/php-console-color (v0.2): Downloading (100%)
- Installing jakub-onderka/php-console-highlighter (v0.4): Downloading (100%)
- Installing dnoegel/php-xdg-base-dir (0.1): Downloading (100%)
- Installing nikic/php-parser (v4.2.4): Downloading (100%)
- Installing psy/psysh (v0.9.9): Downloading (100%)
- Installing laravel/tinker (v1.0.10): Downloading (100%)
- Installing fzaninotto/faker (v1.8.0): Downloading (100%)
- Installing hamcrest/hamcrest-php (v2.0.0): Downloading (100%)
- Installing mockery/mockery (1.2.3): Downloading (100%)
- Installing filp/whoops (2.5.0): Downloading (100%)
- Installing nunomaduro/collision (v3.0.1): Downloading (100%)
- Installing sebastian/version (2.0.1): Downloading (100%)
- Installing sebastian/type (1.1.3): Downloading (100%)
- Installing sebastian/resource-operations (2.0.1): Downloading (100%)
- Installing sebastian/object-reflector (1.1.1): Downloading (100%)
- Installing sebastian/recursion-context (3.0.0): Downloading (connecting...)
……
psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
psy/psysh suggests installing hoa/console (A pure PHP readline implementation. You'll want this if your PHP install doesn't already support readline or libedit.)
filp/whoops suggests installing whoops/soap (Formats errors as SOAP responses)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.7.2)
phpunit/phpunit suggests installing phpunit/php-invoker (^2.0.0)
phpunit/phpunit suggests installing ext-xdebug (*)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
> @php artisan key:generate --ansi
Application key set successfully.

Once installed, it will create a directory named myphp that containing a fresh Laravel installation with all of Laravel’s dependencies already installed.

devops@devops:~$ cd myphp/
devops@devops:~/myphp$ ls
app artisan bootstrap composer.json composer.lock config database package.json phpunit.xml public readme.md resources routes server.php storage tests vendor webpack.mix.js

Step4: Starting a Laravel Development Server


Once a Laravel project is installed, and you can run the following command to start the Laravel Development server. Type:

$ cd myphp
$ php artisan serve

Outputs:

devops@devops:~/myphp$ php artisan serve
Laravel development server started: http://127.0.0.1:8000

Then you can open your web browser to access Laravel application via http://127.0.0.1:8000.

install laravel on ubuntu1

Conclusion


You should know that how to install Laravel Application on your Ubuntu or Debian Linux. If you want to see more detailed information about Laravel, you can directly go to its official web site.

 

You might also like:

Sidebar



back to top