Using artisan serve after changing the public folder name

允我心安 提交于 2019-12-01 03:50:19

问题


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)

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?


回答1:


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.

Instead, in bootstrap/app.php, you should add:

$app->bind('path.public', function() {
    return __DIR__;
});

right after

$app = new Illuminate\Foundation\Application(
    realpath(__DIR__ . '/../')
);

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.

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.




回答2:


find /vendor/laravel/framework/src/Illuminate/Foundation/Application.php this file
and change on following function

/**
 * Get the path to the public / web directory.
 *
 * @return string
 */
public function publicPath()
{
    return $this->basePath.DIRECTORY_SEPARATOR.'public_html';
}


来源:https://stackoverflow.com/questions/30350933/using-artisan-serve-after-changing-the-public-folder-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!