Deployment - Laravel 10.x - The PHP Framework For Web Artisans


本站和网页 https://laravel.com/docs/10.x/deployment 的作者无关,不对其内容负责。快照谨为网络故障时之索引,不代表被搜索网站的即时页面。

Deployment - Laravel 10.x - The PHP Framework For Web Artisans
Skip to content
On macOS? Get started with PHP and Laravel faster than ever using Laravel Herd.
Prologue
Release Notes
Upgrade Guide
Contribution Guide
Getting Started
Installation
Configuration
Directory Structure
Frontend
Starter Kits
Deployment
Architecture Concepts
Request Lifecycle
Service Container
Service Providers
Facades
The Basics
Routing
Middleware
CSRF Protection
Controllers
Requests
Responses
Views
Blade Templates
Asset Bundling
URL Generation
Session
Validation
Error Handling
Logging
Digging Deeper
Artisan Console
Broadcasting
Cache
Collections
Contracts
Events
File Storage
Helpers
HTTP Client
Localization
Mail
Notifications
Package Development
Processes
Queues
Rate Limiting
Task Scheduling
Security
Authentication
Authorization
Email Verification
Encryption
Hashing
Password Reset
Database
Getting Started
Query Builder
Pagination
Migrations
Seeding
Redis
Eloquent ORM
Getting Started
Relationships
Collections
Mutators / Casts
API Resources
Serialization
Factories
Testing
Getting Started
HTTP Tests
Console Tests
Browser Tests
Database
Mocking
Packages
Breeze
Cashier (Stripe)
Cashier (Paddle)
Dusk
Envoy
Fortify
Homestead
Horizon
Jetstream
Mix
Octane
Passport
Pennant
Pint
Precognition
Prompts
Sail
Sanctum
Scout
Socialite
Telescope
Valet
API Documentation
Laravel Forge: create and manage PHP 8 servers. Deploy your Laravel applications in seconds. Sign up now!.
Prologue
Release Notes
Upgrade Guide
Contribution Guide
Getting Started
Installation
Configuration
Directory Structure
Frontend
Starter Kits
Deployment
Architecture Concepts
Request Lifecycle
Service Container
Service Providers
Facades
The Basics
Routing
Middleware
CSRF Protection
Controllers
Requests
Responses
Views
Blade Templates
Asset Bundling
URL Generation
Session
Validation
Error Handling
Logging
Digging Deeper
Artisan Console
Broadcasting
Cache
Collections
Contracts
Events
File Storage
Helpers
HTTP Client
Localization
Mail
Notifications
Package Development
Processes
Queues
Rate Limiting
Task Scheduling
Security
Authentication
Authorization
Email Verification
Encryption
Hashing
Password Reset
Database
Getting Started
Query Builder
Pagination
Migrations
Seeding
Redis
Eloquent ORM
Getting Started
Relationships
Collections
Mutators / Casts
API Resources
Serialization
Factories
Testing
Getting Started
HTTP Tests
Console Tests
Browser Tests
Database
Mocking
Packages
Breeze
Cashier (Stripe)
Cashier (Paddle)
Dusk
Envoy
Fortify
Homestead
Horizon
Jetstream
Mix
Octane
Passport
Pennant
Pint
Precognition
Prompts
Sail
Sanctum
Scout
Socialite
Telescope
Valet
API Documentation
Version
Master
10.x
9.x
8.x
7.x
6.x
5.8
5.7
5.6
5.5
5.4
5.3
5.2
5.1
5.0
4.2
Deployment
Introduction
Server Requirements
Server Configuration
Nginx
Optimization
Autoloader Optimization
Caching Configuration
Caching Events
Caching Routes
Caching Views
Debug Mode
Easy Deployment With Forge / Vapor
Introduction
When you're ready to deploy your Laravel application to production, there are some important things you can do to make sure your application is running as efficiently as possible. In this document, we'll cover some great starting points for making sure your Laravel application is deployed properly.
Server Requirements
The Laravel framework has a few system requirements. You should ensure that your web server has the following minimum PHP version and extensions:
PHP >= 8.1
Ctype PHP Extension
cURL PHP Extension
DOM PHP Extension
Fileinfo PHP Extension
Filter PHP Extension
Hash PHP Extension
Mbstring PHP Extension
OpenSSL PHP Extension
PCRE PHP Extension
PDO PHP Extension
Session PHP Extension
Tokenizer PHP Extension
XML PHP Extension
Server Configuration
Nginx
If you are deploying your application to a server that is running Nginx, you may use the following configuration file as a starting point for configuring your web server. Most likely, this file will need to be customized depending on your server's configuration. If you would like assistance in managing your server, consider using a first-party Laravel server management and deployment service such as Laravel Forge.
Please ensure, like the configuration below, your web server directs all requests to your application's public/index.php file. You should never attempt to move the index.php file to your project's root, as serving the application from the project root will expose many sensitive configuration files to the public Internet:
server { listen 80; listen [::]:80; server_name example.com; root /srv/example.com/public; add_header X-Frame-Options "SAMEORIGIN"; 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; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; }}
Optimization
Autoloader Optimization
When deploying to production, make sure that you are optimizing Composer's class autoloader map so Composer can quickly find the proper file to load for a given class:
composer install --optimize-autoloader --no-dev
Note
In addition to optimizing the autoloader, you should always be sure to include a composer.lock file in your project's source control repository. Your project's dependencies can be installed much faster when a composer.lock file is present.
Caching Configuration
When deploying your application to production, you should make sure that you run the config:cache Artisan command during your deployment process:
php artisan config:cache
This command will combine all of Laravel's configuration files into a single, cached file, which greatly reduces the number of trips the framework must make to the filesystem when loading your configuration values.
Warning
If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function for .env variables will return null.
Caching Events
If your application is utilizing event discovery, you should cache your application's event to listener mappings during your deployment process. This can be accomplished by invoking the event:cache Artisan command during deployment:
php artisan event:cache
Caching Routes
If you are building a large application with many routes, you should make sure that you are running the route:cache Artisan command during your deployment process:
php artisan route:cache
This command reduces all of your route registrations into a single method call within a cached file, improving the performance of route registration when registering hundreds of routes.
Caching Views
When deploying your application to production, you should make sure that you run the view:cache Artisan command during your deployment process:
php artisan view:cache
This command precompiles all your Blade views so they are not compiled on demand, improving the performance of each request that returns a view.
Debug Mode
The debug option in your config/app.php configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the APP_DEBUG environment variable, which is stored in your application's .env file.
In your production environment, this value should always be false. If the APP_DEBUG variable is set to true in production, you risk exposing sensitive configuration values to your application's end users.
Easy Deployment With Forge / Vapor
Laravel Forge
If you aren't quite ready to manage your own server configuration or aren't comfortable configuring all of the various services needed to run a robust Laravel application, Laravel Forge is a wonderful alternative.
Laravel Forge can create servers on various infrastructure providers such as DigitalOcean, Linode, AWS, and more. In addition, Forge installs and manages all of the tools needed to build robust Laravel applications, such as Nginx, MySQL, Redis, Memcached, Beanstalk, and more.
Note
Want a full guide to deploying with Laravel Forge? Check out the Laravel Bootcamp and the Forge video series available on Laracasts.
Laravel Vapor
If you would like a totally serverless, auto-scaling deployment platform tuned for Laravel, check out Laravel Vapor. Laravel Vapor is a serverless deployment platform for Laravel, powered by AWS. Launch your Laravel infrastructure on Vapor and fall in love with the scalable simplicity of serverless. Laravel Vapor is fine-tuned by Laravel's creators to work seamlessly with the framework so you can keep writing your Laravel applications exactly like you're used to.
Laravel is a web application framework with expressive, elegant syntax. We believe development must
be an enjoyable and creative experience to be truly fulfilling. Laravel attempts to take the pain
out of development by easing common tasks used in most web projects.
Highlights
Our Team
Release Notes
Getting Started
Routing
Blade Templates
Authentication
Authorization
Artisan Console
Database
Eloquent ORM
Testing
Resources
Laravel Bootcamp
Laracasts
Laravel News
Laracon
Laracon AU
Laracon EU
Laracon India
Larabelles
Jobs
Forums
Shop
Trademark
Partners
WebReinvent
Vehikl
Tighten
64 Robots
Active Logic
Byte 5
Curotec
Cyber-Duck
DevSquad
Jump24
Kirschbaum
Ecosystem
Breeze
Cashier
Dusk
Echo
Envoyer
Forge
Herd
Horizon
Inertia
Jetstream
Livewire
Nova
Octane
Pennant
Pint
Prompts
Sail
Sanctum
Scout
Socialite
Spark
Telescope
Vapor
Laravel is a Trademark of Taylor Otwell. Copyright 2011-2023 Laravel LLC.
Code highlighting provided by Torchlight