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 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
  • 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-ctype
sudo apt install php-json
sudo apt install php-mbstring
sudo apt install php-xml
sudo apt install php-tokenize
sudo apt install php-zip

Enable PHP fileinfo extension in Ubuntu

Enable PHP openssl extension

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 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');"

php -r "if (hash_file('sha384', 'composer-setup.php') === 'e5325b19b381bfd88ce90a5ddb7823406b2a38cff6bb704b0acc289a09c8128d4a8ce2bbafcd1fcbdc38666422fe2806') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

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

The post Install Laravel In Ubuntu 20.04 “LTS” appeared first on LinuxAndUbuntu.



from LinuxAndUbuntu https://ift.tt/2ZXYSBQ

Post a Comment

0 Comments