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 fileinfo extension ubuntu

Enable PHP openssl extension

enable php openssl extension in ubuntu
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.


Our Trusted Hosting Services

contabo vps
MassiveGRID Banner

13 responses to “Install Laravel In Ubuntu 20.04 “LTS””

  1. Hi, thanks very informative.

    I got stuck at the very last point where we are to craft a new laravel application. I get the following error”bash: laravel: command not found”

  2. Because it should be
    “`
    echo ‘export PATH=”$PATH:$HOME/.config/composer/vendor/bin”‘ >> ~/.bashrc
    “`
    instead of

    “`
    echo ‘export PATH=”$PATH:$HOME/.composer/vendor/bin”‘ >> ~/.bashrc
    “`

  3. The command:

    sudo apt install php-ctype

    doesn’t work either. It tells me I need to select an option:

    Package php-ctype is a virtual package provided by:
    php8.0-common 8.0.0~rc1-3+ubuntu18.04.1+deb.sury.org+1
    php7.4-common 7.4.11-2+ubuntu18.04.1+deb.sury.org+1
    php7.3-common 7.3.23-2+ubuntu18.04.1+deb.sury.org+1
    php7.2-common 7.2.34-2+ubuntu18.04.1+deb.sury.org+1
    php7.1-common 7.1.33-19+ubuntu18.04.1+deb.sury.org+1
    php7.0-common 7.0.33-32+ubuntu18.04.1+deb.sury.org+1
    php5.6-common 5.6.40-33+ubuntu18.04.1+deb.sury.org+1
    You should explicitly select one to install.

  4. Running this:

    laravel new MyApplication –auth

    Shows this:

    The “–auth” option does not exist.

    I’m not sure seeing why yet…

    I’m using WSL2 with Ubuntu 20 and Laravel Installer 4.1.1

    Why am I getting this error when you’re not?

Leave a Reply

Your email address will not be published.