【问题标题】:Install LARAVEL 5 Locally Same as Share Hosting Directory (Deploy L5 Share Hosting Solution)在本地安装 LARAVEL 5 与共享主机目录相同(部署 L5 共享主机解决方案)
【发布时间】:2016-02-14 21:54:41
【问题描述】:

我正在尝试找到一种方法来组织我的 Laravel 应用程序,就像共享托管目录一样。

“server”文件夹中的示例

1.安装新鲜的laravel应用

composer create-project laravel/laravel main-app --prefer-dist

2.将“Public”目录向上移动到主应用文件夹旁边。重命名为public_html

3.在 public_html 文件夹内还创建新的“app”文件夹以保留 index.php 内的所有文件

总结

server │
└───main-app │ │ app │ │ bootstrap │ │ ...... │ └───public_html │ app │ │─── index.php │

这是我需要做的。但我做不到! 每次我尝试运行 artisan 时,我都会得到 ​​p>

chdir() 没有这样的文件或目录 (errno 2)

使用 Laravel 4,我可以编辑 path.php,仅此而已。但 L5 看起来像是退了一步!

我已经尝试过扩展 Application.php 类但很遗憾没有成功!

【问题讨论】:

    标签: laravel-5 laravel-artisan


    【解决方案1】:

    这里是解决方案!

    1.在app文件夹内创建MyApp.php类,扩展Applicaton.php类

    <?php 
    namespace App;
    
    class MyApp  extends \Illuminate\Foundation\Application
    {
        public function publicPath()
        {
            return $this->basePath.DIRECTORY_SEPARATOR.'/../public_html/app';
        }
    }
    

    2.Inside bootsrap/app 使用自己的类

    确保注释掉旧的! ,你不再需要了

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

    3.在 server.php 中更改目标 index.php

    if ($uri !== '/' && file_exists(__DIR__.'/../public_html/app'.$uri)) {
          return false;
    }
    
    
    require_once __DIR__.'/../public_html/app/index.php';
    

    4.在 index.php 中进行更改

    require __DIR__.'/../../main-app/bootstrap/autoload.php';
    

    和

    $app = require_once __DIR__.'/../../main-app/bootstrap/app.php';
    

    完成

    现在工匠工作和 Index.php 与共享托管一样!

    server │
    └───main-app │ │ app │ │ bootstrap │ │ ...... │ └───public_html │ app │ │─── index.php │

    【讨论】:

    • 您有ssh 访问权限吗?如果是,您必须将public 符号链接到public_html。
    • 是的,我有 ssh 访问权限,并且我正在通过 git 提交更新而不使用符号链接。作为第一步,在服务器上的临时文件夹中拉 git,然后将所有文件复制到主应用程序!这样就没有损坏的文件了!
    • 所选答案中描述了最佳解决方案:stackoverflow.com/questions/28433715/…
    • @LittleFinger “最适合”谁?它是相同的文件夹结构吗?你怎么知道我已经没试过了?投反对票对您有帮助吗?
    猜你喜欢
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 2021-06-28
    • 2019-09-25
    • 1970-01-01
    • 2015-06-17
    • 1970-01-01
    • 2019-07-16
    相关资源
    最近更新 更多