更改公用文件夹名称后使用工匠服务 [英] Using artisan serve after changing the public folder name
问题描述
与许多主机一样,我们的公用文件夹称为public_html
.这是在共享主机上,因此无法更改.我已将public
文件夹更改为public_html
以反映此情况,但是当我执行artisan serve
时,它停止工作.每次尝试启动它,我都会得到:
As with a lot of hosts our public folder is called public_html
. This is on shared hosting so can't be changed. I've changed the public
folder to public_html
to reflect this, but when I do artisan serve
stops working. Every time I try to start it I get:
[ErrorException]
chdir(): No such file or directory (errno 2)
如果我将文件夹重命名为public,则artisan serve
再次开始工作.
If I rename the folder back to public then artisan serve
starts working again.
I've tried following this post on laracasts, and the user in the post reports artisan works for them, but it made no difference to me. How can I change the folder and have artisan serve
work?
推荐答案
Dipesh的答案实际上是一个非常糟糕的主意-每当您执行Composer安装/更新/要求时,这些更改都会被吹走. 切勿直接编辑vendor
目录中的任何内容.
Dipesh's answer is actually a very bad idea - those changes will be blown away anytime you do a Composer install/update/require. Never directly edit anything in the vendor
directory.
相反,应在bootstrap/app.php
中添加:
$app->bind('path.public', function() {
return __DIR__;
});
紧接着
$app = new Illuminate\Foundation\Application(
realpath(__DIR__ . '/../')
);
请参见 https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5 进行进一步的讨论,以及以安全的方式进行此操作的替代方法.
See https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5 for further discussion and alternate ways of doing this in a safe manner.
您还可以扩展Illuminate\Foundation\Application
.对于Laravel CLI(以php artisan
开头的任何东西)来说,这似乎是必要的.
You could also extend Illuminate\Foundation\Application
. This appears to be necessary for the Laravel CLI (anything starting with php artisan
) to pick it up.
这篇关于更改公用文件夹名称后使用工匠服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!