vinman75
vinman75

Reputation: 101

Hosting two different applications running on Laravel 4 on shared hosting

I'm about to start development of a site using Laravel4 that will include a cms hosted on a sub-domain. What I want to know if is there is a way to have the main Laravel installation shared between the two apps?

I've had various success in testing using the following example: Laravel full URL routing, however I want to keep the functionality from the app folder separate and have something like say, app_main, app_cms that holds the relevant models, views and controllers for each site in there.

There doesn't seem to be much help that I can find in how to set up Laravel for such a requirement, so any help on this would be great.

Upvotes: 0

Views: 484

Answers (3)

itachi
itachi

Reputation: 6393

use Router for this.

e.g.

Route::group(array('domain'=>'example.com'), function(){
//Define the routes for example.com
});

Route::group(array('domain'=>'cms.example.com'), function(){
//Define the routes for cms.example.com
});

for easier maintanace, you can use namespace for controllers.

e.g. your controller folder can look like this

App
|
|---Controllers
    |-- site
        |
        |-----HomeController.php

    |-- subdomain
        |
        |-----HomeController.php

now, for site controllers, use a namspace like, <?php namespace site;?>

for subdomain controllers, use a namespace like <?php namespace subdomain;?>

in the routes file, define the routes as,

Route::group(array('domain'=>'example.com'), function(){
    Route::get('/', array(
       'as' => 'index',
       'uses' => '\site\HomeController@index'
    ))
});

for subdomains,

Route::group(array('domain'=>'cms.example.com'), function(){
    Route::get('/', array(
       'as' => 'cms.index',
       'uses' => '\subdomain\HomeController@index'
    ))
});

plain and simplest way.

Upvotes: 0

Andreyco
Andreyco

Reputation: 22862

I have a multihosting solution, which after logging into FTP contains this folders:

domaina.com
domainb.com
domainc.com

If I'd like to share same Laravel code between those websites, I just create 'Laravel' folder on the same level, so it looks just like this:

domaina.com
domainb.com
domainc.com
laravel

This 'laravel' folder holds everything except 'app' & 'public' directory.

I just place content of 'public' directory right inside 'domaina.com' folder (for example). Open up 'index.php' and adjust these lines to match actual location. Now you are good to go

require __DIR__.'/../bootstrap/autoload.php';

$app = require_once __DIR__.'/../bootstrap/start.php';

Upvotes: 1

Arda
Arda

Reputation: 6916

bootstrap/paths.php holds the main folder definitions. For each instance, you can alter the app folder, public folder, base folder, storage folder and so on from the file.

You can set a cookie/session, or check domain etc. for main and subdomain and alter it like:

'app' => Session::has('subdomain')?'../../app':__DIR__.'/../app',

Upvotes: 0

Related Questions