Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Install Laravel 6 on a Server & Make Your App More Powerful

October 29, 2019

7 Min Read
install laravel
Reading Time: 7 minutes

In this tutorial, we will demonstrate how to install Laravel 6, what are the new features introduced in it and what benefits it brings for the developers. From semantic versioning to improved custom authorization responses, we will go through all the major features that have been introduced in this release and their use case processes.

Laravel 6.0 Features

Laravel 6 comes up with amazing dev features which makes the framework more powerful and secure than ever.

Here’s what you will get after installing Laravel 6 on server:

  • Semantic versioning
  • Job middleware
  • Lazy collections
  • Eloquent subquery enhancements
  • Improved custom authorization responses
  • Laravel UI
  • Laravel spark

Semantic versioning

Laravel 6 has moved to semantic versioning but you are wondering what is that and does it impact how you work with your Laravel projects? Let’s see what impact does it creates in your Laravel projects.

Semantic versioning is a set of rules that dictate the types of changes that increment the version number or more precisely each of the three numbers representing the version. It’s also called semver.

Job Middleware

Job middleware is a feature that allows jobs to run through middleware instead of adding them manually by using custom logic in the body of the handle () method.

In previous Laravel versions, jobs were wrapped with a rate-limiting call back function as shown below:

Path:// app/Jobs/JobToBeThrottled.php
//Execute job

public function handle() {
// allow job to execute every 6 seconds  
   Redis::throttle('key')->block(0)->allow(1)->every(6)->then(function () {    
  }, function () {    
    return $this->release(6);
  });
}

Laravel 6.0 introduces the idea of job middleware, which allows you to keep your job’s handle method free of any rate-limiting responsibilities:

public function handle($job, $next)
    {
        Redis::throttle('key')
                ->block(0)->allow(1)->every(6)
                ->then(function () use ($job, $next) {
                    // Lock obtained...

                    $next($job);
                }, function () use ($job) {
                    // Could not obtain lock...

                    $job->release(6);
                });
    }

After creating middleware, you can return jobs by creating middleware jobs method:

use App\Jobs\Middleware\RateLimited;

public function middleware()
{
    return [new RateLimited];
}

Powerful Laravel Hosting For All Your Needs

Grow your Laravel app with our feature-rich managed hosting

Lazy collection

The lazy collection is an amazing feature that allows Laravel developers to work with large datasets with low memory usage. It works with Eloquent model collection by adding the following class:

use Illuminate\Support\LazyCollection;

For example, when you are working with multi-gigabytes datasets and you need to parse log files, you can use lazy collections to keep only a small part of the file in memory at a given time, rather than reading an entire file into memory at once.

If you are working with Eloquent models, or you like to choose one model into memory at a time, you can use the cursor() method instead of using the all() method.

$posts = App\Post::all()->filter(function ($post) {
    return $post->id > 500;
});

By switching from all() to cursor(), only one Eloquent model is loaded into memory at a time because cursor() uses the new LazyCollection instance.

$posts = App\Post::cursor()->filter(function ($post) {
  return $post->id > 500;
});

foreach ($posts as $post) {
  echo $post->id;
}

Eloquent Subquery Enhancements

One of the best solutions to reduce memory load in an application is to use push work in the database layer of the application. It uses a query optimizer to reduce the amount of time to process given requests. Laravel 6 introduces a new subquery feature that helps to select all destination and the name of the flight using a single query. Using this feature, developers can reduce their workload as well as can optimize the processing time of the given requests.

For example:

return Destination::addSelect(['last_flight' => Flight::select('name')
    ->whereColumn('destination_id', 'destinations.id')
    ->orderBy('arrived_at', 'desc')
    ->limit(1)
])->get();

Order By

You can also check this new subquery feature by using the orderBy function.

return Destination::orderByDesc(
    Flight::select('arrived_at')
        ->whereColumn('destination_id', 'destinations.id')
        ->orderBy('arrived_at', 'desc')
        ->limit(1)
)->get();

Custom Authorization Responses

Laravel 6 introduces easy to understand authorization messages for developers. In previous versions, these authorization messages were not easily understandable and were a bit complicated. Moreover, to give a custom message, developers were required to create a new file and write their exceptions in it, which was a bit a time-taking task.

But in Laravel 6, you can get a customizable authorization response by simply using the Gate::inspect method when linking to the function that enables you to receive the response. Delivery of the message to the front-end is also easy to organize. Simply add $this->authorize or Gate::authorize to a suitable route or controller.

Laravel UI

In previous Laravel versions, developers can easily integrate Bootstrap and VueJS for front end development. Using the auth command, they can easily create login and registration page UI for the web application. But in Laravel 6, it is not available.

To restore the traditional Vue / Bootstrap scaffolding available in previous releases of Laravel, you can install the Laravel/ui package and use the UI Artisan command to install the frontend scaffolding in web applications:

composer require laravel/ui --dev

php artisan ui vue --auth

Laravel Spark

Laravel Spark is an amazing new version of Laravel built on top of advanced dev features such as per-seat pricing, location, bootstrapping, new user interface and others. It has optimized security features as well that takes the development and protection of data to the next level.

Install Laravel 6 on Server (Local host)

To install Laravel on localhost, you will require the following server setup:

  • PHP >= 7.2
  • Composer
  • Xampp / Wamp

Laravel uses composer files to manage its dependencies. To begin installing Laravel with composer, you have to first install the composer in your local machine as shown in the image below:

laravel composer installation

Once the installation of Laravel Composer is complete, you must launch the Laravel 6 app on the server by entering the following command:

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

You Might Also Like: Integrate Laravel Cache & Skyrocket Your Web App Performance

Starting Laravel Server

If you have installed PHP application on a local host, and you want its built-in development server to host the application, you can use the Laravel Artisan command. This command will help starting Laravel server at http://localhost:8000.

You Might Also Like: Laravel Notification System On Slack And Email

php artisan serve

Now, you can open your application URL and can see the Laravel page in it. You have successfully installed Laravel 6 on your local server.

Why Use Cloudways?

Cloudways provides managed cloud hosting services on top of the rank Cloud servers including AWS, DigitalOcean, Linode and others. Its flawless features make it one of the best Laravel hosting service providers today.

Performance

Cloudways provides a complete stack of web tools called Thunderstack, which helps developers in optimizing Laravel website speed and performance. The stack consists of different web tools including Memcached, Redis, Varnish, Nginx, PHP-FPM and others. The primary purpose of integrating all these tools in a single stack is to give developers the ease to find all web tools at one place, thus helping them get fast web and content delivery speed.

Security

To enhance website security, Cloudways provides one-click SSL certificate installation facility to ensure data security from malicious web attacks. Meanwhile the auto healing servers ensure the safety of your website in case of any accidental failure or unwanted letdown.

The IP whitelisting feature allows you to set up secure connections with unrestricted SSH and SFTP access.

Install Laravel 6 on Cloudways

To begin installing Laravel on server, select your PHP server and application according to your project requirements. Select server size as per your website traffic and location according to your preferred region.

cloudways platform

After completing all these steps, you can finally go to the application tab where you will find your newly installed Laravel PHP application. Click on it to find further details inside:

laravel 6 cloudways

SSH Terminal

Now, to install Laravel 6, you have to open the SSH terminal to run the composer command. You can either use the Putty terminal or Cloudways SSH terminal as per the requirements.

Let’s start with Putty, go to the application public_html folder and type the following Laravel Composer installation command:

composer create-project laravel/laravel

install laravel

laravel installation

Once you have executed the above-mentioned command, go to your application path “url/Cloudways/public”, where you will see the following screen.

Laravel-5.8

How to Solve Composer Downloader Transport Exception?

When you start to install Laravel 6 with composer, a transport exception error often pops up on the screen as shown below:

composer downloader transport

You can simply resolve this error by using the following Composer update command:

Composer update 

Laravel 6 New Features [Infographic]

laravel 6 new features

Q: How to disable Xdebug during Laravel installation via composer?

A: To streamline Laravel app installation, you can easily disable Xdebug in PHP from the console’s php.ini file. Here’s how to do it using composer:
# Set xdebug autostart to false
xdebug.remote_autostart=0
xdebug.remote_enable=0
# Disable your profiller
xdebug.profiler_enable=0

Q: Where to find the Laravel installation folder?

A: Once finishing the installation with composer, you can find the newly created Laravel folder inside the xampp\htdocs folder. First cd into the xampp\htdocs folder and then use ‘cd myApp’ to go inside your newly installed Laravel folder.

Q: How to install Laravel in PHP server without composer?

A: To install Laravel without composer, you have to once run composer install/update command, which will download all the libraries locally. You can then upload all those files manually to the server and right after your project will have all the dependencies available on server.

Q: How to upload Laravel project to the server?

A: Simply upload all your project files into the root directory of your domain, while upload the contents of public into the public_html folder. This is one of the easiest way of uploading a Laravel project on the web server.

Final Words

This brings us to the end of this article which highlighted how to install Laravel 6 and its newly introduced features. The new updates enhance the security protocols of the framework and make it more developer-friendly for performing various complex operations. Moreover, features like ‘Custom authorization response’ enables developers to code and write their exceptions, making their debugging outcomes more understandable than ever.

If you still have some more questions regarding the release of Laravel 6 or want to contribute more about its newly introduced features, feel free to write down your thoughts below in the comments section.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Launch Laravel apps with 1-Click Install. Painless Server Management

Deploy your apps on optimized Laravel hosting servers.

Pardeep Kumar

Pardeep is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. He love to work on Open source platform , Frameworks and working on new ideas. You can email him at pardeep.kumar@cloudways.com

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!