Laravel Lessons: Installation & Setup

Published April 22, 2020 • 4 mins read

In this lesson, we are going to be setting up a fresh Laravel project. I believe you read the getting started article. If you haven't, go check it out.

Lite Mailer

All through this series we are going to be building an email sending application where user can add emails and send out mass emails. Its going to be very simple and we are going to call it Lite Mailer.

Composer

Laravel setup is done through composer - a dependency management tool. Using composer is very simple so you don't need to go for any special class for that. I will be explaining the composer commands that we use in this lessons.

Follow any of this link to install composer on our machine. You can check if composer is installed on your system by running the composer command on your terminal.

Installing Laravel

You can install Laravel via the Laravel installer or via the composer create-project command. We are going to use the composer create-project command.

Open your terminal, move into your project directory by running cd project_dir . You can keep your Laravel project anywhere you like.

Run the create-project command.

composer create-project --prefer-dist laravel/laravel litemailer

The composer create-project command will create a fresh Laravel project, create a .env file, install all the required PHP/Laravel packages and generate our application key.

Manual Installation

The source code for this project will be available on GitHub, so let me walk you through how to set it up on your local machine.

Open your terminal, move into your project directory and clone the repository.

git clone https://github.com/stephenjude/litemailer.git

Move into the litemailer directory and install the required PHP/Laravel packages by running composer install command.

composer install

Create your .env file from the .env.example file. If you are using Linux/macOS or git bash terminal, this should work.

cp .env.example .env

Run the key:generate artisan command to add an application key to your project.

php artisan key:generate

Now you are ready. This is applicable to any laravel project you clone from a remote repository. Lets talk about this artisan command.

Artisan Command

The artisan command provides lots of handy commands that can speeds up your development pace. The key:generate is an example of artisan command, usually the first artisan command that runs on every Laravel application.

You can see all the available artisan commands by running php artisan list. I will be explaining some of these commands as we go on.

Basic Configuration

All the Laravel configuration files for this project can be found inside the litemailer/config directory but we are not going to be focusing there for now. The basic configuration of a Laravel application revolves around the .env file we created earlier.

The .env file contains variables that are can change when we move our application to another environment. For example, when we move our application from a development machine to the production server, our database credentials must surely change. That's why it's highly encouraged to not commit your .env file to a git repository.

Lets go through some of the vital .env variables, the when and how to use them.

APP_NAME: This is the name of your application. Laravel uses this name by default especially when sending email.

APP_ENV: This is used by Laravel to detect where your application is currently running. When you set it to production, Laravel will warn you anytime you want to perform a sensitive action like running the artisan migrate command.

APP_KEY: The app key is used for securing the session and encrypted data. By default your laravel application will return error 500 if the key is not set.

APP_DEBUG: This variable is set to true by default and this allows you to see error stack trace and its is highly recommended for local or development environment. Setting this variable to false will activate the default laravel error page and hide all stack trace. This very important when you are in a production environment.

APP_URL: Always set this to the domain name of your application. Laravel and some external packages makes use variable.

LOG_CHANNEL: This is used to define how your application should store log data. The default variable is stack which allows your application to log data on daily basis. This is good for production. During development I usually set it to single so that it all log data are stored on the same file.

Thats all for now. As we go deeper, I will be explaining other env variables.

Running Laravel Application

I believe your local development environment is ready. All the Laravel development environment I pointed out in the getting started article provides pretty URL for your project. Visiting litemailer.test on your browser should display our fresh Laravel application. Do well to reload your local server if the pretty url is not working yet.

Running php artisan serve is another way to serve your Laravel application usually served at http://localhost:8000.

Questions

I know you have lots of questions. You can drop your question on the comment box, send me a DM on twitter or send a mail.

Subscribe here to receive email updates of this series directly to your inbox.

Hey, have you tried Litehost lately?

Litehost is my side project which is a shared hosting platform with PHP & Laravel developers in mind. It has Composer, Git & PHP CLI pre-installed on its servers. SSH access is also granted on request. Litehost is pretty affordable. Try it today.