【发布时间】:2015-09-27 09:43:19
【问题描述】:
我正在寻找一种在 laravel 5.1 中更改公共文件夹名称的方法,因为我的主机只允许我使用 htdocs 文件夹。
【问题讨论】:
标签: laravel laravel-5 laravel-5.1
我正在寻找一种在 laravel 5.1 中更改公共文件夹名称的方法,因为我的主机只允许我使用 htdocs 文件夹。
【问题讨论】:
标签: laravel laravel-5 laravel-5.1
我遵循了这些步骤,在这里提到:https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5:
在bootstrap/app.php,添加
$app->bind('path.public', function() {
return base_path('htdocs');
});
然后,在/server.php 中,将public 的两个出现更改为htdocs(或任何你想使用的)。
我真诚地希望这在任何情况下都能奏效。
我最近不得不这样做,但这次我的主机允许我删除“htdocs”文件夹(而且我有 ssh 访问权限):
ln -s public htdocs
【讨论】:
这就是我的做法.. 更新和其他事情到现在为止都运行良好..
在根目录创建一个新文件夹.. 并移动其中的所有文件夹(例如,将其称为“myfolder”).. 然后将公用文件夹中的文件移动到根目录.. 所以它应该看起来像..
/myfolder/
/index.php
/server.php
/.htaccess
/favicon
所以用文本编辑器打开 server.php 并替换为这段代码..
<?php /** * Laravel - A PHP Framework For Web Artisans * * @package Laravel * @author Taylor Otwell <taylorotwell@gmail.com> */ $uri = urldecode( parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ); // This file allows us to emulate Apache's "mod_rewrite" functionality from the // built-in PHP web server. This provides a convenient way to test a Laravel // application without having installed a "real" web server software here. if ($uri !== '/' && file_exists(__DIR__.'/'.$uri)) { return false; } require_once __DIR__.'/index.php';
然后在 index.php 上
<?php /** * Laravel - A PHP Framework For Web Artisans * * @package Laravel * @author Taylor Otwell <taylorotwell@gmail.com> */ /* |-------------------------------------------------------------------------- | Register The Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader for | our application. We just need to utilize it! We'll simply require it | into the script here so that we don't have to worry about manual | loading any of our classes later on. It feels nice to relax. | */ require __DIR__.'/myfolder/bootstrap/autoload.php'; /* |-------------------------------------------------------------------------- | 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__.'/myfolder/bootstrap/app.php'; /* |-------------------------------------------------------------------------- | Run The Application |-------------------------------------------------------------------------- | | Once we have the application, we can handle the incoming request | through the kernel, and send the associated response back to | the client's browser allowing them to enjoy the creative | and wonderful application we have prepared for them. | */ $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); $response->send(); $kernel->terminate($request, $response);
然后转到“/myfolder/bootstrap/autoload.php”..
<?php define('LARAVEL_START', microtime(true)); /* |-------------------------------------------------------------------------- | Register The Composer Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader | for our application. We just need to utilize it! We'll require it | into the script here so that we do not have to worry about the | loading of any our classes "manually". Feels great to relax. | */ require __DIR__.'/../vendor/autoload.php'; /* |-------------------------------------------------------------------------- | Include The Compiled Class File |-------------------------------------------------------------------------- | | To dramatically increase your application's performance, you may use a | compiled class file which contains all of the classes commonly used | by a request. The Artisan "optimize" is used to create this file. | */ $compiledPath = __DIR__.'/cache/compiled.php'; if (file_exists($compiledPath)) { require $compiledPath; }
和 app.php 在同一个文件夹中
<?php /* |-------------------------------------------------------------------------- | Create The Application |-------------------------------------------------------------------------- | | The first thing we will do is create a new Laravel application instance | which serves as the "glue" for all the components of Laravel, and is | the IoC container for the system binding all of the various parts. | */ $app = new Illuminate\Foundation\Application( realpath(__DIR__.'/../') ); /* |-------------------------------------------------------------------------- | Bind Important Interfaces |-------------------------------------------------------------------------- | | Next, we need to bind some important interfaces into the container so | we will be able to resolve them when needed. The kernels serve the | incoming requests to this application from both the web and CLI. | */ $app->singleton( Illuminate\Contracts\Http\Kernel::class, App\Http\Kernel::class ); $app->singleton( Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class ); $app->singleton( Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class ); /* |-------------------------------------------------------------------------- | Return The Application |-------------------------------------------------------------------------- | | This script returns the application instance. The instance is given to | the calling script so we can separate the building of the instances | from the actual running of the application and sending responses. | */ return $app;
在开发和生产环境中非常适合我..
【讨论】: