This is the 9th day of my participation in the August Wen Challenge.More challenges in August

Before, I wrote an article about Laravel improving the efficiency of DB query. After forwarding it to the group, some people questioned me and said, “Laravel is the framework he used several years ago, I didn’t expect that there are still people using it now.”

Nani, what do you mean? Don’t forget PHP is the best language!

Personally, Laravel is a very elegant development framework: elegant design patterns, powerful feature implementations, easy extensions, constant release updates, and most importantly, the best technology development community to date, in my opinion.

I have to make a Call for Laravel.

Laravel released version 8.0 on September 8, 2020. Laravel is scheduled to release version 9.0 on January 25, 2022.

Here I would like to introduce the new features of the latest Laravel release (8.0) :

Laravel 8 with the introduction of Laravel Jetstream, model factory classes, Migration compression, queue batching, improved rate limiting, queue improvements, dynamic Blade components, Tailwind paging view, Time test Assistant, artisan Serve improvements, Improvements to the event listener, along with various other bug fixes and usability improvements, continue to improve Laravel 7.x.

Laravel deployment

preface

As you prepare to deploy your Laravel application into production, make sure there are a few important considerations to ensure that your application runs as efficiently as possible. In this article we’ll cover a few key points to make sure your Laravel app is deployed properly.

Server Configuration

Nginx

If you want to deploy your application to a Nginx server, you may use the following configuration file as a template to configure your Web server. This file will most likely require some custom modifications based on your server configuration. If you need assistance in managing your server, consider using Laravel Forge:

server { listen 80; server_name example.com; root /srv/example.com/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.php; charset utf-8; location / { try_files $uri $uri/ /index.php? $query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; PHP ${fastcgi_pass Unix :/var/run/ PHP /php7.4-fpm. Sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(? ! well-known).* { deny all; }}Copy the code

To optimize the

Auto loader optimization

When you are ready to deploy your application to production, you should optimize the autoload mapping of the Composer class so that Composer can quickly find the correct load file for the specified class.

composer install --optimize-autoloader --no-dev
Copy the code

Tip: To optimize the autoloader, you should make sure that your project code management includes the composer. Lock file from the library. When you include the composer. Lock file in your project, you can quickly install the dependencies you need in your project.

Optimized configuration loading

When you are ready to deploy your application to production, you should run the config:cache Artisan command during deployment:

php artisan config:cache
Copy the code

This command merges all Laravel configuration files into a cache file, which greatly reduces the number of file system accesses when the framework loads configuration values.

Note: If you run the config:cache command during deployment, you should make sure that you only call env from the configuration file. Once the configuration is cached, the.env file is no longer loaded and the env method will return NULL.

Optimized route loading

If you are building a large application with a large number of routes, you should make sure that you execute route:cache:

php artisan route:cache
Copy the code

This command will make a single function call to all route registries to see a cached file, thus improving the performance of route registries when registering hundreds of routes.

Optimized view loading

When deploying an application to production, you should make sure to run view:cache: during deployment.

php artisan view:cache
Copy the code

This command precompiles all Blade views so they are not compiled on demand, which improves the performance of each request to return a view.

Use Forge/Vapor deployment

If you are not ready to manage your own server configuration or are not familiar with the configuration of the various services required for powerful Laravel applications, Laravel Forge is a good choice. Laravel Forge can create servers on a variety of infrastructure providers (DigitalOcean, Linode, AWS, etc.). In addition, Forge can install and manage a variety of tools needed for powerful Laravel applications, such as Nginx, MySQL, Redis, Memcached, Beanstalk, etc.

Laravel Vapor

If you want to use a full Serverless, automated deployment platform for Laravel applications, refer to Laravel Vapor. Laravel Vapor is a Serverless deployment platform provided by AWS for Laravel. Launch your Laravel infrastructure on Vapor and love the scalable simplicity of ServerLess. Laravel’s creators have fine-tuned Laravel Vapor to work seamlessly with the framework so that you can continue to develop Laravel applications as before.

Gorgeous dividing line

For more on Laravel, check out my column: Server Development from Beginner to Master

Recommended reading

  1. I’m still working on Laravel? Don’t forget PHP is the best language. (1) How does Laravel elegantly set global variables

  2. I’m still working on Laravel? Don’t forget PHP is the best language. (2) Laravel Jetstream and model Factory classes

  3. I’m still working on Laravel? Don’t forget PHP is the best language. (3) Migration compression, queue batch processing, improve rate limit

  4. I’m still working on Laravel? Don’t forget PHP is the best language. (4) Optimization of maintenance mode

  5. I’m still working on Laravel? Don’t forget PHP is the best language. (5) Dynamic Blade event listener optimizes event test assistant

  6. I’m still working on Laravel? Don’t forget PHP is the best language. (6)

  7. I’m still working on Laravel? Don’t forget PHP is the best language. (7) Laravel Installation Guide

  8. I’m still working on Laravel? Don’t forget PHP is the best language. (8) Directory structure

Last but not least

Technical group please come here. Or add my wechat account wangzhongyang0601 to learn together.