运行Voyager安装命令遇symlink权限拒绝错误,安装后无图片求助
Hey there, let's tackle this issue you're facing. That symlink(): Permission denied error pops up because Laravel can't create the required symbolic link between public/storage and storage/app/public—and without that link, Voyager can't serve the images stored in your storage/app/public directory, which is exactly why your media isn't showing up. Let's walk through the most reliable fixes:
1. Manually Create the Symbolic Link
The simplest fix is to create the link yourself via terminal, since the artisan command might be running under a user that doesn't have the right permissions (like your server's web user vs. your terminal user).
For Linux/macOS:
Navigate to your project's root directory and run this command:
ln -s ../storage/app/public public/storage
For Windows (Command Prompt):
mklink /d public\storage ..\storage\app\public
For Windows (PowerShell):
New-Item -ItemType SymbolicLink -Path "public\storage" -Target "..\storage\app\public"
After creating the link, double-check the permissions on your storage folder and the new public/storage link. Set them to something like:
chmod -R 755 storage public/storage chown -R www-data:www-data storage public/storage
(Note: Replace www-data with your server's web user—this might be apache on some systems, or your hosting provider's specific user.)
2. Use a Route to Create the Link (For Shared Hosting/No Shell Access)
If you don't have terminal access to your server, you can temporarily add a route to create the link for you:
- Open
routes/web.phpand add this code:
Route::get('/create-storage-link', function () { $targetPath = storage_path('app/public'); $linkPath = public_path('storage'); if (file_exists($linkPath)) { return 'Storage link already exists!'; } symlink($targetPath, $linkPath); return 'Storage link created successfully!'; });
- Visit your site's URL followed by
/create-storage-link(e.g.,https://yourdomain.com/create-storage-link). - Once you see the success message, delete this route immediately—it's a security risk to leave it accessible.
3. Adjust Filesystem Configuration (Alternative to Symlinks)
If symlinks aren't an option (some shared hosts block them), you can tweak Laravel's filesystem config to serve images directly:
- Open
config/filesystems.phpand find thepublicdisk configuration. Update it to:
'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), 'url' => env('APP_URL') . '/storage', 'visibility' => 'public', ],
- Then, create a
public/storagefolder manually and copy all existing images fromstorage/app/publicinto it. Keep in mind—any new images uploaded via Voyager will go tostorage/app/public, so you'll need to sync these folders regularly (or set up an automated script to handle this).
Once you've implemented one of these fixes, clear your Laravel cache just to be safe:
php artisan cache:clear
Your Voyager images should start showing up right away!
内容的提问来源于stack exchange,提问作者Brendan

