How to create your first Laravel project

  • avatar
  • 3.8K Views
  • 3 mins read

Laravel is an open-source PHP web framework intended for the development of web applications following the model–view–controller (MVC) architectural pattern and based on Symfony. The source code of Laravel is hosted on GitHub and licensed under the terms of MIT License.

Prerequisites

Laravel utilizes Composer to manage its dependencies. Take a look on how to install Composer on your computer.

Installation

If your computer already has Composer installed, you may create a new Laravel project by using Composer directly. The command will create a new project in new_app folder (in the current location) and install dependencies:

composer create-project laravel/laravel new_app

Configuring Laravel

Initial configuration must be performed in order to run Laravel.

Directory Permissions

You may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run.

Environment variables

Environment variables are used to store sensitive data such as passwords, credentials and other information that should not be written directly in code. Environment variables must be used to configure variables or configuration details that may differ between environments.

Laravel provides an example of how should initial environment file look like in .env.example document. The easiest way to complete the setup is renaming that file to .env and use it for our variables. Remember that it must be placed in the project directory.

Encryption key

The next thing you should do after installing Laravel is set your application key. Application key is a random string used to secure your user sessions and encrypt data. To automatically generate the key, run the following command:

php artisan key:generate

The command sets the APP_KEY value in your .env file. It is important to note that if the encryption key needs to be regenerated after an application has been in use, any data that was previously encrypted using the old key cannot be decrypted using the new encryption key.

Using Laravel

After the application has been created, you may start Laravel's local development server using artisan command:

cd new_app && php artisan serve

We will see that our terminal will be blocked by the process and will show us the URL to access the APP from any browser installed on our computer. Usually it will be something similar to http://127.0.0.1:8000

artisan_serve.png

To unlock the terminal and stop the execution we can use the Ctrl+C combination on our keyboard.

 Join Our Monthly Newsletter

Get the latest news and popular articles to your inbox every month

We never send SPAM nor unsolicited emails

0 Comments

Leave a Reply

Your email address will not be published.

Replying to the message: View original

Hey visitor! Unlock access to featured articles, remove ads and much more - it's free.