在Ubuntu上优化Laravel性能可从以下方面入手:
php artisan config:cache、php artisan route:cache、php artisan view:cache。.env中设置CACHE_DRIVER=redis,并安装对应扩展。with()方法预加载关联数据。.env中设置QUEUE_CONNECTION=redis。sudo apt install supervisor
sudo nano /etc/supervisor/conf.d/laravel-worker.conf
# 配置示例:
[program:laravel-worker]
command=php /path/to/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data
numprocs=4
然后执行:sudo supervisorctl reread && sudo supervisorctl update && sudo supervisorctl start laravel-worker:*。worker_processes和worker_connections参数以适配服务器硬件。gzip on;配置。php.ini中设置:opcache.enable=1、opcache.memory_consumption=128。memory_limit参数,避免内存浪费。