Laravel (5.7) Tutorial
Getting Started
Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller architectural pattern and based on Symfony. The aim of the laravel framework is to take the pain out of development by making common tasks used in web development, such as authentication, routing, sessions, and caching a much easy ride. Since it’s first beta release in 2011, the laravel framework has evolved over the years from it’s first version to it’s most recent stable version released in September, 2018. This tutorial is therefore based on the laravel version 5.7 So let’s get started by setting up laravel on our local machine with all its requirements.
Installation:
- Server Requirements
- Installing Laravel
- Configuration
Installation:
Server Requirements
Laravel has a few system requirements. Now, these requirements have been satisfied by a laravel feature known as the Laravel Homestead which is a Vagrant virtual machine that provides Laravel developers with all the tools necessary to develop Laravel straight out of the box, that is useful in developing full scale web applications. It's highly recommended that you use Homestead as your local Laravel development environment.
However, if you are not using Homestead, you will need to make sure your server meets the following requirements:
- PHP >= 7.1.3
- OpenSSL PHP Extension
- PDO PHP Extension
- Mbstring PHP Extension
- Tokenizer PHP Extension
- XML PHP Extension
- Ctype PHP Extension
- JSON PHP Extension
- BCMath PHP Extension
declaring, resolving and using dependencies required by the project in an automated fashion
Installing Laravel
As dependencies in Javascript based projects are managed with package managers such as npm or yarn, similarly, Laravel utilizesComposer to manage its dependencies. So, before using Laravel, make sure you have Composer installed on your machine. There are several ways to install laravel and initialize a laravel project. They are listed below;
Via laravel installer
You will firstly need to download the Laravel installer using Composer:
composer global require laravel/installer
Make sure to place composer's system-wide vendor bin directory in your $PATH . This is to ensure that laravel can be located by your system and also executed. Based on your operating system(macOS or Linux Distributions), this directory exists in different locations; however, some common locations include:
- macOS: $HOME/.composer/vendor/bin
- GNU / Linux Distributions: $HOME/.config/composer/vendor/bin
Once installed, the laravel new command will create a fresh Laravel installation in the directory you specify.
For instance, this command laravel new app will create a directory named app containing a fresh Laravel installation with all of Laravel's dependencies already installed.
Via Composer Create-Project
Another option is to use the composer create-project command in your terminal like this;
composer create-project --prefer-dist laravel/laravel blog
Via Local Development Server
If you have PHP installed locally via the xampp development server, you can use the php artisan serve command, to serve your application. This command will start a development server at
http://localhost:8000
Configuration:
Configuration Files
The config directory in your project includes various configurations and associated parameters required for the smooth functioning of a Laravel application. Various files included within the config folder are as shown in the image here. The filenames work as per the functionality associated with them
Web Server Configuration
Pretty URLs
Apache
Laravel includes a public/.htaccess file that is used to provide URL without the index.php front controller in the path. Before serving laravel with Apache,enable the mod_rewrite module so the .htaccess file will be honored by the server.
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization}
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Nginx
If you are using Nginx, the following directive in your site configuration will direct all requests to the index.php front controller:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
When using Laravel's Vagrant virtual machine called Homestead, these pretty URLs are automatically configured.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/laravel/laravel-tutorial.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics