In this article, we will cover Laravel 5.6 installation & configuration of database and server.we will work with windows machine but still, you can follow same command & instruction with other operating systems.
TABLE OF CONTENT
We will cover the following topics.
- Pre-requirements for install Laravel.
- Laravel Installation using composer.
- Configure Laravel project.
Pre-requirements for install Laravel
Before proceeding to install laravel, you have the following programmes need to install.
- Web Server
- PHP (>= 7.1.3)
- Integrated Development Environment (IDE)
Web server, PHP & MySQL
For installation of this, we will use XAMPP, XAMPP comes with Apache server, PHP & MySQL.If you don’t have XAMPP you can download from this link. if you prefer any other web server you can go with it, but i would prefer to use XAMPP for Laravel.
Composer is the dependency package manager for PHP. You can read more about the composer from their official website. you can download the composer from the same link. you can get the instruction how to install from the website.
Integrated Development Environment (IDE)
Will need IDE for write PHP code, this is an optional step but highly recommended. You can use any lightweight text editor like Notepad++, Sublime Text 3 and Visual Studio Code. You can also go with PHPStrom or NetBeans which come along with comprehensive feature set including tools and integrations.
Install Laravel using Composer
Step 1: Navigate to web server root
- Assume you install xampp to C:/xampp/, now open windows explorer and navigate to C:/xampp/htdocs.
- Now Right click anywhere in C:/xampp/htdocs and select “Use Composer here” , you will get below command prompt window
Step 2: Install Laravel project using composer
Run below command
composer create-project laravel/laravel laravel-demo
after run command, you will get following output in windows command prompt,
Now, wait for a moment to complete the installation.
Step 3: Test Project installation
Now you can browse below URL to get access to the website.
You can use Artisan command to run the project.
php artisan serve
once you fire this command project run on 8000 port and you can access project by below url.
Configure Laravel Project
The configuration you can set from
- set debugging mode: it is helpful to configure when to display error/notice/warnings.
- setup environment: it is helpful to configure different environments like dev/uat/prod.
- set the time zone: it helps to set up time zone for your project.
- set the maintenance mode: it helps when do you want to enable & disable maintenance message to your app user.
to enable debugging mode
'debug' => env('APP_DEBUG', true),
to disable debugging mode
'debug' => env('APP_DEBUG', false),
You can set different environments like local/dev/uat/production.
'env' => env('APP_ENV', 'production'),
'timezone' => 'UTC',
To enable maintenance mode, execute
php artisan down
To disable maintenance mode, execute
php artisan up
The database configuration file is located in
/config/database.php. In Laravel MySQL is default database engine.you can also choose different database engine as per your need, but in this article i am going to show you for MySQL.
Below key fields we need to update:
Locate the following lines.
'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ],
Update above code with correct values.
'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhsot'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'larave-demo'), 'username' => env('DB_USERNAME', 'root'), 'password' => env('DB_PASSWORD', 'password'), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ],
In this article we learn about:
- The pre-requirements of Laravel installation. PHP, MySQL, composer and for writing code IDE.
- How to configure Laravel project.