Deployment
Introduction
When you're ready to deploy your LaraGram 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 LaraGram application is deployed properly.
Server Requirements
The LaraGram framework has a few system requirements. You should ensure that your web server has the following minimum PHP version and extensions:
- PHP >=
8.2
- Ctype PHP Extension
- cURL PHP Extension
- Fileinfo PHP Extension
- Filter PHP Extension
- Hash PHP Extension
- Mbstring PHP Extension
- OpenSSL PHP Extension
- PCRE PHP Extension
- PDO PHP Extension
- Tokenizer 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.
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;
index index.php;
charset utf-8;
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "DENY";
add_header X-Robots-Tag "noindex, nofollow";
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_hide_header X-Powered-By;
}
location ~ \.php$ {
return 404;
}
location ~ /\.(?!well-known).* {
deny all;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { return 403; }
}
Directory Permissions
LaraGram will need to write to the bootstrap/cache
and storage
directories, so you should ensure the web server process owner has permission to write to these directories.
Optimization
When deploying your application to production, there are a variety of files that should be cached, including your configuration, events, listens, and templates. LaraGram provides a single, convenient optimize
Commander command that will cache all of these files. This command should typically be invoked as part of your application's deployment process:
php laragram optimize
The optimize:clear
method may be used to remove all of the cache files generated by the optimize
command as well as all keys in the default cache driver:
php laragram optimize:clear
In the following documentation, we will discuss each of the granular optimization commands that are executed by the optimize
command.
Caching Configuration
When deploying your application to production, you should make sure that you run the config:cache
Commander command during your deployment process:
php laragram config:cache
This command will combine all of LaraGram'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
You should cache your application's auto-discovered event to listener mappings during your deployment process. This can be accomplished by invoking the event:cache
Commander command during deployment:
php laragram event:cache
Caching Listens
If you are building a large application with many listens, you should make sure that you are running the listen:cache
Commander command during your deployment process:
php laragram listen:cache
This command reduces all of your listen registrations into a single method call within a cached file, improving the performance of listen registration when registering hundreds of listens.
Caching Templates
When deploying your application to production, you should make sure that you run the template:cache
Commander command during your deployment process:
php laragram template:cache
This command precompiles all your Blade templates so they are not compiled on demand, improving the performance of each request that returns a template.
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.
WARNING
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.