Laravel

Install Laravel In Ubuntu 20.04 “LTS”

install laravel in ubuntu 1

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 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 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. So 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 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 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

Compser 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 composer is installed, it’s now turn 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 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 setup Laravel 7.x in your Ubuntu installation. If you have any difficulty with any of the step mentioned above, please let me know in the comment section below.



LinuxAndUbuntu hosting is sponsored by massiveGRID

9 comments

karani August 2, 2020 at 2:25 pm

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”

Reply
Sohail August 14, 2020 at 12:09 pm

Hi Karani,

That probably happened due to setting incorrect $path. What distribution are you using?

Reply
Leaf Mabz August 23, 2020 at 10:55 am

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
“`

Reply
hero September 29, 2020 at 9:02 pm

stock in last using ubuntu lts 20

Reply
Luke Marvelly October 13, 2020 at 2:50 pm

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.

Reply
Luke Marvelly October 13, 2020 at 2:55 pm

Used this in the end:

sudo apt install php7.3-ctype

Reply
Luke Marvelly October 13, 2020 at 3:08 pm

This line didn’t work for me either:

source ~/.bashrc

Reply
Luke Marvelly October 13, 2020 at 3:40 pm

Btw I’m using Linux Mint 19.3

Reply
Sohail November 6, 2020 at 8:45 pm

No problem. It should work with Linux Mint too.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This website uses cookies to improve your experience. We'll assume you're ok with this. Thank you! Ok Read More