我使用的共享主机使用cPanel作为其控制面板,并且cPanel中public_html是默认的根目录,因此,我无法正常运行Laravel应用程序。
public_html
有什么方法可以使Laravel public_html代替公用文件夹?
通过简单的搜索就很容易找到它。
在您的index.php中添加以下3行。
/* |-------------------------------------------------------------------------- | Turn On The Lights |-------------------------------------------------------------------------- | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it | will load up this application so that we can run it and send | the responses back to the browser and delight our users. | */ $app = require_once __DIR__.'/../bootstrap/app.php'; // set the public path to this directory $app->bind('path.public', function() { return __DIR__; });
编辑:
正如Burak Erdem提到的,另一个选择(也是更可取的)是将其放入\App\Providers\AppServiceProvider register()方法中。
\App\Providers\AppServiceProvider
register()
/** * Register any application services. * * @return void */ public function register() { // ... $this->app->bind('path.public', function() { return base_path('public_html'); }); }