简体   繁体   English

如何在多个项目中安装一个 Laravel PHP?

[英]How can I have one Laravel PHP install with multiple projects?

I noticed that Laravel 5.3 takes about 41MB on average of disk space per project.我注意到 Laravel 5.3 每个项目平均占用大约 41MB 的磁盘空间。

Is there a tidy way to configure things so that Laravel is installed once on my PHP server (which is dedicated to Laravel-only stuff) and then have multiple projects (some as separate domains, some as subdirs) use that same Laravel instance?有没有一种整洁的方式来配置东西,以便 Laravel 在我的 PHP 服务器上安装一次(专用于 Laravel 的东西),然后让多个项目(一些作为单独的域,一些作为子目录)使用同一个 Laravel 实例?

So for instance, I could have /usr/share/laravel and put everything in there, but then in /var/www, I could put each of my domains (/var/www/test1.com, /var/www/test2.com) and subfolders on domains (/var/www/test1.com/project2) and then they would all utilize the same /usr/share/laravel.因此,例如,我可以拥有 /usr/share/laravel 并将所有内容都放在那里,但是在 /var/www 中,我可以将我的每个域(/var/www/test1.com、/var/www/test2 .com) 和域 (/var/www/test1.com/project2) 上的子文件夹,然后它们都将使用相同的 /usr/share/laravel。

You could use symlinks, I've never tried this but I guess it would involve creating separate directories for each application then creating symlinks to a shared vendor directory (which includes Laravel).您可以使用符号链接,我从未尝试过,但我想这将涉及为每个应用程序创建单独的目录,然后创建指向共享供应商目录(包括 Laravel)的符号链接。

This would allow you to separately version control all the application specific files but share the dependencies.这将允许您单独版本控制所有应用程序特定文件,但共享依赖项。 Watch out though, if your composer.json files have differing versions listed you might run into trouble.但请注意,如果您的composer.json文件列出了不同的版本,您可能会遇到麻烦。

Well the solution I did the last time I tried this it was bit different.好吧,我上次尝试的解决方案有点不同。 For any means I think it is a good one or the best one.无论如何,我认为这是一个很好的或最好的。 but it has worked so far:但到目前为止它已经奏效:

  • First all domains loads the same laravel project首先所有域加载相同的 Laravel 项目
  • customize route service provider自定义路由服务提供商

So first the changes to the RouteServiceProvider :首先是对RouteServiceProvider的更改:

public function map(Router $router)
{
       if (strstr(Request::getHost(), 'domain_one')) {
            $router->group([
                'namespace' => $this->namespace,
                'middleware' => ['default_middle_wares'],
            ], function ($router) {
                require app_path('Http/Routes/domain_one.php');
            });
        }

        if (strstr(Request::getHost(), 'domain_two')) {
            $router->group([
                'namespace' => $this->namespace,
                'middleware' => ['default_middle_wares'],
            ], function ($router) {
                require app_path('Http/Routes/domain_two.php');
            });
        }
}

After create the route files.创建路由文件后。 and it should work...它应该工作......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM