How to Install a Laravel Project

In web development, a robust framework is where most developers go. As a result, Laravel is quite popular and loved by many developers. This post will teach you how to install Laravel and set up a basic project.

You may also want to read: Getting Started with Laravel Artisan CLI.

Install Laravel using Composer

You can download and install Laravel using the files. However, it is much more convenient to install a Laravel project using Composer. You can install Composer via this link: https://getcomposer.org/download/. Once installed, open your command-line interface.

You can then navigate to the directory where you want to install your Laravel project.

Next, run the following command:

composer create-project laravel/laravel <project-name>

Of course, remember to replace <project-name> with the name of your project. This command is the easiest and most convenient way of installing Laravel.

You can also install Laravel globally on your machine to save you the trouble of using Composer to set up Laravel projects. For example, use the following command to install Laravel globally:

composer global require laravel/installer

Next, you can install a new Laravel app using the following command:

laravel new <app-name>

First, of course, remember to replace <app-name> with the name of your app.

Run and test your Laravel project

Once you have executed the above commands to install Laravel, you can assess your Laravel app. Navigate to your Laravel app directory and run the following command:

php artisan serve

This command will start a Laravel local development server. Now you can open your browser and visit localhost:8000. You should be able to see a Laravel welcome screen:

The Laravel documentation provides a detailed explanation and tutorials of all Laravel features.

Advanced installation

Installation with Git

One of the most valuable features of Laravel is its scalability. More than one developer can develop Laravel apps without experiencing major conflicts. Hence, it might be suitable for a developer to install the Laravel app as a git repository. To initialize the project as a repository, use the --git flag:

laravel new app-name --git

You can only use this command if you have Git installed. Along with the --git flag, you can also use a --branch=" <branch-name>" flag to initialize the git on a specific branch. Replace <branch-name> with the name of your branch.

laravel new app-name --git --branch="main"

Installation with GitHub

If you would like to make a local git repository and set it up on GitHub, use the flag --github.

laravel new appname --github

This command assumes you have GitHub setup and configured on your machine. You can pass extra command-line arguments. If needed, use the flag --github=" <args>", replace <args> with your arguments.

laravel new appname --github="--public"

You can also use a specific organization for your repository. You can use the --organization flag if needed.

laravel new appname --github --organisation="myOrg"

The ENV file

In the root directory of your Laravel application, you will find a .env file that holds information like database connectivity. It also has the site info, email config, and other global variables. You can also define your custom global variables in this file.

To configure the database of your application, look for the following lines in your .env file:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=root
DB_PASSWORD=root

Common issues

When installing Laravel, ensure your terminal is running with administrator rights. In Windows, do this by right-clicking the cmd icon and then selecting "run as administrator". In Linux systems, use the command sudo before the command to run as a superuser. This action is necessary as installing Laravel globally requires administrator privileges.

Want to know more?

There is to much more that you need to know about Laravel.

You may also be interested in



About the Authors

Anto's editorial team loves the cloud as much as you! Each member of Anto's editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic! Contact Anto Online if you want to contribute.

Support the Cause

Support Anto Online and buy us a coffee. Anything is possible with coffee and code.

Buy me a coffee



Leave a Reply

Your email address will not be published. Required fields are marked *