在 Debian 上“提升 Laravel 速度”通常可以从系统层面、PHP 层面、Laravel 层面、缓存与队列、数据库几个方向入手。下面给你一套比较实用、可落地的优化清单。
sudo apt install php-fpm
Nginx + PHP-FPM 是 Debian 上跑 Laravel 的标准组合。
编辑:
sudo vim /etc/php/*/fpm/conf.d/10-opcache.ini
推荐配置:
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.validate_timestamps=0 ; 生产环境
重启:
sudo systemctl restart php-fpm
APP_ENV=production
APP_DEBUG=false
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
⚠️ 注意:
config/app.php 中:
composer install --optimize-autoloader --no-dev
composer dump-autoload -o
$table->index(['user_id', 'created_at']);
User::with('posts')->get();
DB::enableQueryLog();
sudo apt install redis-server
.env:
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis
php artisan queue:work --daemon
用 supervisor 保活:
sudo apt install supervisor
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=laravel:10m;
gzip on;
gzip_min_length 1024;
开启:
composer require laravel/octane
php artisan octane:start
php -v
php -m | grep opcache
php artisan config:cache
php artisan route:cache
如果你愿意,可以告诉我:
我可以给你一套精确到命令的优化方案。