更改Laravel 5.1的公用文件夹

更改Laravel 5.1的公用文件夹,laravel,laravel-5,laravel-5.1,Laravel,Laravel 5,Laravel 5.1,我正在寻找一种在laravel 5.1中更改公用文件夹名称的方法,因为我的主机只允许我使用htdocs文件夹。我遵循了以下步骤,如这里所述: 在bootstrap/app.php中,添加 $app->bind('path.public', function() { return base_path('htdocs'); }); 然后,在/server.php中,将两个出现的public更改为htdocs(或您想要使用的任何内容) 我真诚地希望这在任何情况下都能奏效 编辑20

我正在寻找一种在laravel 5.1中更改公用文件夹名称的方法,因为我的主机只允许我使用htdocs文件夹。

我遵循了以下步骤,如这里所述:

  • bootstrap/app.php
    中,添加

    $app->bind('path.public', function() {
          return base_path('htdocs');
    });
    
  • 然后,在
    /server.php
    中,将两个出现的
    public
    更改为
    htdocs
    (或您想要使用的任何内容)

  • 我真诚地希望这在任何情况下都能奏效

    编辑2016-10-18: 我最近也不得不这么做,但这次我的主机允许我删除“htdocs”文件夹(我有ssh访问权限):

    • 我在根文件夹“htdocs”文件夹下安装了Laravel
    • 我删除了“htdocs”文件夹
    • 我创建了一个符号链接,将“htdocs”映射到“public”:
      ln-s public htdocs

      • 我就是这样做的。。到目前为止,更新和其他功能都能正常工作

        在根目录上创建一个新文件夹。。并移动其中的所有文件夹(例如,我称之为“myfolder”)。。然后将公用文件夹中的文件移动到根目录。。所以看起来应该是

        /myfolder/
        /index.php
        /server.php
        /.htaccess
        /favicon
        
        因此,使用文本编辑器打开server.php并替换为以下代码


        @michael,我该把它放在哪里?哼。。。我注意到我存储在htdocs/上的文件不再可用。。。查看一下,我将在介绍完之后立即发布一个更新。好的,php artisan serve命令调用vendor/laravel/framework/src/illighte/Foundation/Application.php::publicPath(),其中“public”字符串是硬编码的。我更新了它,但这不是很适合未来,除非它只由artisan serve调用。是的,这似乎是一个很好的选择,当你不能有任何低于公用文件夹。感谢您提供的方法。您可以更改这些文件上的路径以满足您的需要:)
        
        <?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';
        
        <?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);
        
        <?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;
        }
        
        <?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;