Install Laravel In Ubuntu 20.04 "LTS"

Laravel is one of the best PHP frameworks for developing web applications. It has a ton of features that otherwise are time-consuming to build a PHP app from scratch.

Some of the best features of Laravel are, it is easily customizable, the great authentication system, and a huge collection of packages created by the community. In this article, I will walk you through how to install the Laravel framework in Ubuntu 20.04 LTS or Linux Mint 20. This should also work for any other Ubuntu version or Ubuntu derivatives.

If you are thinking about deploying your Laravel application, then you can use massiveGRID or digitalocean. Both of these companies will let you set up your web server in no time.

Recently I have seen people having trouble with installing Laravel with the latest versions of PHP. To get the most from PHP or Laravel, it is recommended to use the latest version of PHP.

Install or upgrade to the latest PHP version

Install the latest PHP version from ondrej PPA for Ubuntu.

sudo add-apt-repository ppa:ondrej/php
sudo apt upgrade
sudo apt install php
sudo apt install apache2
  • PHP (7.0, 7.1, 7.2, 7.3, 7.4) (Latest version is recommended)

Laravel requires the following PHP packages to function properly. To install each of them before heading forward to the next step.

Required PHP Extensions

sudo apt install php-bcmath
sudo apt install php-json
sudo apt install php-mbstring
sudo apt install php-xml
sudo apt install php-tokenizer
sudo apt install php-zip

Enable PHP fileinfo extension in Ubuntu

To enable PHP fileinfo and PHP OpenSSL in Ubuntu or derivatives, uncomment the extension in the php.ini file. Open php.ini file located in /etc/php/7.4/apache2/php.ini. Change the PHP version in the path. For instance, my currently activated PHP version is 7.4, so I need to edit the php.ini file inside 7.4 directory.

sudo nano /etc/php/7.4/apache2/php.ini
  • Press ctrl + w and search for fileinfo. Remove the semi-colon to enable the extension.
  • Press ctrl + w and search for openssl. Remove the semi-colon to enable the extension.
enable PHP fileinfo extension ubuntu

Enable PHP openssl extension

enable PHP openssl extension in ubuntu

Install Composer in Ubuntu

Composer is a dependency manager for PHP. It makes the installation of PHP packages very easy. To install it on Ubuntu or Linux Mint or any other Ubuntu derivatives, run the following commands in the terminal –

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

sudo php composer-setup.php --install-dir=/bin --filename=composer

Install Laravel

Once the composer is installed, it now turns to install laravel.

composer global require laravel/installer
echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
source ~/.bashrc

And that’s it. You can now run the laravel command to craft your new laravel application.

laravel new MyApplication

Set up laravel app with authentication.

laravel new MyApplication --auth

The above will install and set up Laravel 7.x in your Ubuntu installation. If you have any difficulty with any of the steps mentioned above, please let me know in the comment section below.