在Debian系统上配置Laravel的文件存储,你需要遵循以下步骤:
sudo apt-get update
sudo apt-get install nginx php-fpm mysql-server
/etc/php/7.4/fpm/pool.d/www.conf文件,找到listen行,将其更改为:listen = /run/php/php7.4-fpm.sock
然后重启PHP-FPM服务:
sudo systemctl restart php7.4-fpm
/etc/nginx/sites-available/default文件,找到location块,添加以下内容:location /storage {
alias /var/www/laravel/storage;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
然后重启Nginx服务:
sudo systemctl restart nginx
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 755 storage bootstrap/cache
这将设置storage和bootstrap/cache目录的所有者和权限,以便Web服务器可以读写这些目录。
.env文件,找到以下行:FILESYSTEM_DRIVER=public
确保它设置为public。这将使Laravel使用public/storage目录作为公共文件存储。
现在,你应该已经成功配置了Laravel的文件存储。你可以运行Laravel项目,并确保一切正常工作。如果遇到问题,请检查Nginx和PHP-FPM服务的状态,以及Laravel项目的日志文件。