在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。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:如何在Debian上优化Tomcat性能