Laragon,laravel symbolyc link 不起作用
Laragon, laravel symbolyc link does not work
我将 laravel 与 laragon 一起使用,一切正常,除了当我上传图像时它们 return 404
并且 public/storage
是空的但是 storage/app/public
有文件,public/public
也有文件,所以它在 public 文件夹中创建了一个错误的文件夹 public,我做了 运行 php artisan storage:link command
作为我说它创建了存储 link 我可以在我的编辑器中看到它,但是文件转到 public/public
而不是 public/storage
,我怎样才能让它工作?我想这是 laragon 的问题,因为它在其他环境中工作,我 运行 我的网站有一个 "named" url : myproject.test ,我使用 apache2 作为网络服务器,拜托帮助修复它
如果你在linux,你可以使用
ln -s [source] [virtual]
创建虚拟 link。在 windows 上,您可以使用
mklink /j [virtual] [source]
做同样的事情。
请注意,您可能需要使用完整路径来创建 link。我在 laragon 上使用了这个方法,它有效。在创建 symlink 后双击 link 检查它是否工作,如果它们转到所需的文件夹。如果没有,则配置有问题。
奖金
我创建了一个控制台命令来自动化操作,也许你可以使用它:
用法:php artisan install:symlink
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class installSymlink extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'install:symlink';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This artisan command installs pinpacker symlinks';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
$links = ["./public/thumbnails","./public/resized"];
$folders = ["./storage/app/public/thumbnails/","./storage/app/public/resized/"];
chdir(base_path());
try {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
foreach($links as $i => $link){
$command = 'mklink /j "' . str_replace('/', '\', $link) . '" "' . str_replace('/', '\', $folders[$i]) . '"';
echo $command."\n";
exec($command);
}
} else {
foreach($links as $i => $link){
$command = 'ln -s ' . realpath($folders[$i]) . ' ' . $link;
echo $command ."\n";
exec($command);
}
}
printf("Symlinks created.\n");
} catch (Exception $e) {
printf($e->getMessage());
print_r($e);
}
}
}
我将 laravel 与 laragon 一起使用,一切正常,除了当我上传图像时它们 return 404
并且 public/storage
是空的但是 storage/app/public
有文件,public/public
也有文件,所以它在 public 文件夹中创建了一个错误的文件夹 public,我做了 运行 php artisan storage:link command
作为我说它创建了存储 link 我可以在我的编辑器中看到它,但是文件转到 public/public
而不是 public/storage
,我怎样才能让它工作?我想这是 laragon 的问题,因为它在其他环境中工作,我 运行 我的网站有一个 "named" url : myproject.test ,我使用 apache2 作为网络服务器,拜托帮助修复它
如果你在linux,你可以使用
ln -s [source] [virtual]
创建虚拟 link。在 windows 上,您可以使用
mklink /j [virtual] [source]
做同样的事情。
请注意,您可能需要使用完整路径来创建 link。我在 laragon 上使用了这个方法,它有效。在创建 symlink 后双击 link 检查它是否工作,如果它们转到所需的文件夹。如果没有,则配置有问题。
奖金
我创建了一个控制台命令来自动化操作,也许你可以使用它:
用法:php artisan install:symlink
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class installSymlink extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'install:symlink';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This artisan command installs pinpacker symlinks';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
$links = ["./public/thumbnails","./public/resized"];
$folders = ["./storage/app/public/thumbnails/","./storage/app/public/resized/"];
chdir(base_path());
try {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
foreach($links as $i => $link){
$command = 'mklink /j "' . str_replace('/', '\', $link) . '" "' . str_replace('/', '\', $folders[$i]) . '"';
echo $command."\n";
exec($command);
}
} else {
foreach($links as $i => $link){
$command = 'ln -s ' . realpath($folders[$i]) . ' ' . $link;
echo $command ."\n";
exec($command);
}
}
printf("Symlinks created.\n");
} catch (Exception $e) {
printf($e->getMessage());
print_r($e);
}
}
}