Laravel is an open-source and cross-platform PHP framework that is hailed by web developers everywhere. Laravel is built by Symfony framework and works on model-view-controller pattern. It is highly regarded because it cuts down the grunt work and lets the developers do the real work.
In this article, You will learn how you can install and set up the Laravel framework on your Ubuntu System.
Prerequisites
- Ubuntu Linux-based system
- Terminal access
- A user account with sudo privileges.
Note: The commands in this tutorial are executed on the Ubuntu 20.04 system. All the methods in the tutorial are valid for any Linux-based system.
Update & Upgrade the System
It is always the best practice to start any installation with the upgraded and updated system but it is necessary as Laravel does not work with PHP with a version lower than 7.2.
To update and upgrade your system, run the following command.
sudo apt update && apt upgrade -y
Install PHP
To install PHP on your system, run the following apt command.
sudo apt install php
Once you are done with the installation, check the installation version with the following command.
php -v
Now install the PHP extension with the same version with the following command.
sudo apt install php7.4-mbstring php7.4-xml php7.4-zip
Install curl
Run the following command to install curl if you do not have it installed.
sudo apt install curl
Install Composer
You need the Composer to manage dependencies in Laravel.
To install composer, run the following command.
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Run the following command with your composer file path to run composer without sudo permission.
sudo chown -R $USER /usr/local/bin/composer/
Install Symfony
Laravel often uses the Symfony framework so it is best to install it along with Laravel.
To install Symfony run the following command.
composer create-project symfony/skeleton testproj
Change into the testproj directory and run the following command
run php -S 127.0.0.1:8000 -t public
Open the following link in the browser to verify the installation.
Install Laravel
Now that everything is set and running, install Laravel using the following composer command.
composer global require laravel/installer
Add Laravel to Path in Bashrc File
Once the Laravel installation is done, open the .bashrc file.
nano .bashrc
Then add the following line of code at the end of the file.
export PATH="$PATH:$HOME/.config/composer/vendor/bin"
Press Ctrl+O and Ctrl+X to save and exit.
Next source the bashrc file.
source ~/.bashrc
Create New Laravel App
Simply run the following command to create an application in Laravel.
laravel new [name of app]
Navigate to the application directory and run the following composer command.
cd [name of app]
composer install
Now run the following commands to get the encryption key and access to localhost.
php artisan key:generate --ansi
php artisan serve
Note the development server link and open it in the browser.
You can see Laravel is up and running.
Conclusion
This article discusses the installation process of Laravel and all the necessary components to establish a bare-minimum configuration. You can keep using the installation as it is to learn the Laravel basics or add more components like databases or homestead to build elaborate web applications.