How To Install Laravel?
How to install Laravel? Let’s deep dive into the Laravel.
You can skip by navigating from the right-side quick navigation.
You can also read What is the role of patience in the programming?
What is Laravel?
Laravel is an open-source PHP based framework released under MIT license by Taylor Otwell.
Laravel is a simple and robust MVC PHP Framework. It is available with a powerful toolkit to create the complete-featured web application.
Laravel is a very popular PHP framework because it offers scalability, security,
Basically, Laravel reuses the existing features of other PHP frameworks which help in building a web application.
It is basically using the features of CodeIgniter, Yii, Symfony and other programming languages like Ruby on Rails.
Laravel uses composer to manage its Symfony modules and third-party packages. Laravel has to be downloaded via composer and Laravel uses composer autoloading to load classes.
That’s why a composer is very important and should be in your system before installing Laravel.
How to install Composer on Windows?
- To install composer, click here getcomposer.com
- Download the composer setup executable file and run it to install the composer.
- After installing the
composer open the command prompt or terminal and run the following command:
composer
How to Install Composer on Ubuntu?
Before installing the composer, we must make sure about the dependencies of the composer in our system.
Run the following command to update packages:
sudo apt-get update
The following dependencies are needed to install.
- curl: download the composer
- php5-
cli : install and run Composer - git: used by Composer
We also can use the single command to install all dependencies:
sudo apt-get install curl php5-cli git
To install composer, run the following commands. The 4 lines of code do the following things.
- Download the installer to the current directory
- Verify the installer SHA-384
- Run the installer
- Remove the installer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
This 4 lines of code can be changed with the latest version of the composer. So, click on the button below to get this code from the official composer page.
You can verify the installation of the composer by running the following command:
composer
You must have familiar with the basics
Before diving into Laravel you must have the basic knowledge about the following:
- PHP
- OOP
- MySQL
- Basics of MVC (Model, View, and Controller)
Server Requirements for Laravel 5.8 (latest)
You can meet all the requirements by using Laravel Homestead virtual machine. Otherwise you will need a server with t
- PHP
- PHP >= 7.1.3
- BCMath PHP Extension
- Ctype PHP Extension
- JSON PHP Extension
- Mbstring PHP Extension
- OpenSSL PHP Extension
- PDO PHP Extension
- Tokenizer PHP Extension
- XML PHP Extension
For Windows you can use WampServer, Lamp for Ubuntu or XAMPP and MAMP for both Windows and MacOS.
How to install Laravel?
There are two methods to proceed with Laravel:
- Laravel installer
- Composer create-project
Laravel Installer
Laravel 5 introduces the Laravel installer which makes the installation process easy.
To download Laravel installer run this command:
composer global require laravel/installer
Composer’s system-wide vendor bin directory should be in your $PATH so the
- macOS: $HOME/.composer/vendor/bin
- GNU / Linux Distributions: $HOME/.config/composer/vendor/bin
- Windows: %USERPROFILE%\AppData\Roaming\Composer\vendor\bin
Now we can use the following command to create a Laravel project. So go to your required directory where you want to install Laravel and run the following command.
laravel new project_name
Composer create-project
If you don’t want to follow the above process, don’t worry we have another alternative to create a
Laravel framework is a collection of files and folders hosted in https://packagist.org/packages/laravel/laravel and in https://github.com/laravel/laravel
That’s why we use the following command to create the Laravel application.
composer create-project --prefer-dist laravel/laravel project_name
Run the Application
There is two way to run this Laravel Application, you may use serve artisan command:
Php artisan serve
This command will start a development server at
http://localhost:8000
Or alternatively, you can type the following URL in the browser’s address bar directly:
http://localhost/project_name/public
You can add directory before project_name in the URL if you created your project in the different directory.
Basic Configurations
Storage and Bootstrap cache Permissions
If you are working with Ubuntu, run the following command to grant the administrative permissions to the directory
chmod -R 777 storage chmod -R 777 bootstrap/cache
Public Directory
You can copy index.php and .htaccess file from project/public to project/
So that you can access your project directly.
Database Configuration
To configure the database add following information into the .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= database_name
DB_USERNAME= user_name
DB_PASSWORD= password
Mail Configuration
To configure the mail add following information into the
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465 or 587
MAIL_USERNAME=youmail@gmail.com or other mail
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls or ssl
What is APP_KEY?
This application key available in .env file with 32-characters string. This is auto-generated by Laravel installer. You only need to regenerate it, when you clone the existing app.
This is very important for the protection of your data. It’s used for the encryption of your data (sessions, database, passwords, etc.).
To verify if the key is set, open the.env
file. You should see something like below.
APP_KEY=base64:hCoQQWBvpO++Y1RQIadCG7/LoUhahjCDZdiRrfIazo4=
Otherwise, you need to get it by running the following command:
php artisan key:generate
That’s it, how to install Laravel. I hope it was worth reading if it is then feel free to comment and share it.
2 thoughts on “How To Install Laravel?”