How To Install Laravel on Linux

Viraj Madhushan
Tech Dude LK
Published in
4 min readMar 8, 2022
Laravel logo

In this article, I will tell you how to install Laravel in your Linux operating system using Composer. You can use this on Debian or any Debian based Linux distro. If you are not sure that you are using a Debian based distro, check →🐧 this.
Also, if you are an Arch or fedora user, you can continue from step 03. But step 01 and 02 have different commands.

So, get ready with your all-mighty terminals and let’s go for the action.😉

Step 01 — Update your system

First, we need to update the apt list. This is required to check whether your system runs the latest updates.

sudo apt-get update

ss1

When you run this command, you need to give your root password for your pc.

Step 02 — Install the latest PHP in your system

Install PHP and CURL in your system. Laravel is a PHP framework. To work with Laravel, we need to install PHP in our PC. Also, CURL is a command-line tool to transfer data to or from a server, using any of the supported protocols in the web.

To Install PHP

sudo apt install php

ss2

sudo apt install php7.4-mbstring php7.4-xml php7.4-zip

ss3

To Install CURL

sudo apt install curl

ss4

Step 03 — Install Composer

Above steps are required basic dependencies which helps to install and run Laravel in your computer. In this step, we install composer. Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries.

composer logo

This command will download composer from its official site. Don’t worry! It is actually official website 😄. You can check it before type that command.

curl -s https://getcomposer.org/installer | php

Then move the “composer.phar” file into “ /usr/local/bin/composer” location

sudo mv composer.phar /usr/local/bin/composer

Now you are done with composer. You can check it success or not, using below command. In my case, it shows Composer version of installed. That version can be change in the future.

composer -V

Step 04 — Install Laravel using Laravel installer

In this step, we install Laravel in globally. To do this, we use…

composer global require laravel/installer

Step 05

We must set up path variables correctly. We can do it using nano editor. Nano is an easy-to-use command line text editor for Unix and Linux operating systems.

To do this, enter the below command.

nano .bashrc

Then you will get a window like this. 👇

Then write down this text line, like the image. You can just copy and paste it.

export PATH="$PATH:$HOME/.config/composer/vendor/bin"

Then press CTRL+X, and then it asks to save the file. Enter “y” to yes and press enter. Then it will ask for filename. Don’t do any changes of it, and press enter again. Then you will be exited to terminal again.

Step 06

Update your current shell environment after changes.

source ~/.bashrc

Step 07

Now you successfully installed PHP, composer and Laravel in your pc. You can check whether Laravel installer working or not by simply typing laravel and hit enter. If you get an output like the below image, you are good to go.

Let’s create our first Laravel project.

laravel new FirstLaravelProject

This above command will create a new Laravel project called FristLaravelProject. You can give any name you desired instead of it.

After everything done, you can see a folder called FristLaravelProject. Then go inside that folder using cd command.

cd FristLaravelProject

Generate unique key inside the project. It helps to run git related projects without any conflicts.

php artisan key:generate --ansi

Finally, run your Laravel project on a local server using artisan serve.

php artisan serve

Congratulations! 🎉 You just launched your first Laravel project on local server.

--

--

Viraj Madhushan
Tech Dude LK

Passionate learner of AI and Robotics. Always exploring new technologies to stay ahead of emerging trends. Hiking and reading enthusiast.