当我在laravel本地开发服务器上工作php artisan storage:link
对我来说很好。但是当我将我的网站转移到生产服务器时,我看到我的公共存储链接是一个文件夹。然后我删除了试图创建链接。我收到错误,因为我的应用程序位于根文件夹中并试图解决此问题。
答案 0 :(得分:9)
我通过另一个用于创建符号链接的命令解决了这个问题:
ln -s /path/to/laravel/storage/app/public /path/to/public/storage
答案 1 :(得分:2)
另一种简单的方法是以编程方式运行执行php artisan storage:link
命令
在routes / web.php上
Route::get('/foo', function () {
Artisan::call('storage:link');
});
答案 2 :(得分:2)
使用SSH在Web服务器中创建符号链接
在Laravel文档中,应创建从public / storage到storage / app / public的符号链接(符号链接或软链接),以使文件可以从网络上访问。
(此程序将在Laravel项目目录内创建符号链接)
以下是有关如何使用SSH客户端在Linux Web服务器中创建符号链接的步骤:
1。。使用SSH客户端(例如PUTTY)连接并登录到您的Web服务器。
2。。使用语法将存储/应用/公共链接到公共/存储。
ln -s target_path link_path
示例(在CPanel文件目录中)
ln -s /home/cpanel_username/project_name/storage/app/public /home/cpanel_sername/project_name/public/storage
答案 3 :(得分:1)
假设您的laravel项目的“ public”目录和“ public_html”目录不同。或您的子域指针目录可能不同,然后在给定的过程中使用您的子域指针目录,例如“ public_html”。
应用命令:$ php artisan storage:link
此命令将创建符号链接到laravel项目的“ public”目录。不在“ public_html”内。因此我们需要将“存储”链接移至“ public_html”目录。为此,您可以直接移动。如果它不起作用,则使用command将其移动。进入“ public”目录,然后根据您的“ public_html”目录位置运行以下命令。
$ mv storage /home/yourHostinInfo/domains/domainName/public_html
根据您的托管信息,路径可能会有所不同。
答案 4 :(得分:1)
如果您使用的是 CPANEL 网络托管,则其常见的域根目录是 public_html
目录,这可能是一个问题,因为默认情况下 Laravel 应用程序会尝试在您的目录中查找名为 public
的文件夹项目根。
要解决此问题,请打开您的 config/filesystems.php
文件并进行更改:
/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/
'links' => [
public_path('storage') => storage_path('app/public'),
],
为此:
/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/
'links' => [
base_path('public_html/storage') => storage_path('app/public'),
],
请注意,我们已将 links
数组值从默认 public_path('storage')
更改为我们自定义的 base_path('public_html/storage')
目录
答案 5 :(得分:0)
我在创建指向subdomain
下的文件夹的符号链接时遇到了问题,尝试了将近3个小时的一切,但没有任何运气。我的情况如下:
images.example.com
下。$_SERVER['DOCUMENT_ROOT'].'/uploads/
最后,我尝试了此解决方案,它可以按预期工作:
ln -s /home/customer/www/images.example.com/public_html/uploads /home/customer/www/example.com/public_html/uploads
注意:我使用PuTTY
创建了该符号链接
答案 6 :(得分:0)
如果有人正在寻找另一个使用 php 的灵活解决方案:
Route::get('/link', function () {
$target = '/home/public_html/storage/app/public';
$shortcut = '/home/public_html/public/storage';
symlink($target, $shortcut);
});
并根据文件结构对 $target 变量和 $shortcut 进行任何必要的更改。
您可以在该网络路由或任何其他函数中使用上述代码。
答案 7 :(得分:0)
你所要做的就是通过SSH访问服务器,导航到你的laravel项目的根路径,例如:
cd /path/to/your/domain/public_html
然后导航到 public
目录(laravel 项目)并删除 storage
目录(如果您已上传)...
然后返回 public_html
并运行命令:
php artisan storage:link
这将完成工作...