在Debian上優化Laravel性能可以通過多種方法實現,以下是一些關鍵的優化策略:
composer require laravel/telescope
php artisan telescope:install
php artisan migrate
app/Providers/AppServiceProvider.php
中注冊Telescope:use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeApplicationServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
Telescope::ignoreMigrations();
}
public function boot()
{
Telescope::night();
}
}
DB::listen
記錄查詢:DB::listen(function ($query) {
Telescope::recordQuery($query);
});
.env
文件中設置隊列驅動程序:QUEUE_CONNECTION=redis
php artisan make:job SendEmail
use App\Jobs\SendEmail;
SendEmail::dispatch($user);
composer require laravel/octane
php artisan octane:install --server=frankenphp
php artisan octane:start
php.ini
:opcache.enable=1
opcache.enable_cli=1
opcache.jit=tracing
opcache.jit_buffer_size=256m
opcache.memory_consumption=512m
opcache.interned_strings_buffer=64m
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.validate_timestamps=1
opcache.fast_shutdown=1
opcache.save_comments=1
sudo aptitude install nginx
/etc/nginx/sites-available/fmtmis
文件:server {
listen 80;
root /var/www/code/fmtmis/webroot/public;
index index.php;
server_name fmtmis.testing;
location / {
try_files uri uri/ /index.php?query_string;
}
location \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location /\.ht {
deny all;
}
}
sudo aptitude install php7.2-fpm php7.2-gd php7.2-json php7.2-mbstring php7.2-mysql php7.2-xml php7.2-zip
sudo vim /etc/supervisor/conf.d/fmtmis.conf
[program:fmtmis-horizon]
process_name=%(program_name)s
command php /var/www/code/fmtmis/webroot/artisan horizon
autostart=true
autorestart=true
user=root
redirect_stderr=true
stdout_logfile=/var/www/code/fmtmis/webroot/horizon.log
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start fmtmis-horizon
通過以上步驟,您可以在Debian上顯著提升Laravel應用程序的性能。這些優化策略包括使用Telescope進行監控、優化隊列處理、使用Octane提高執行速度、開啟OpCache加速PHP執行以及正確配置Nginx和PHP-FPM。