You are not logged in.

Important Note: This forum is being archived and will be completely locked down on the 7th of February. The new forum can be found at http://laravel.io.

Announcement

    Laravel 4 Advanced Architecture: Book Now On Sale

#1 2013-01-27 00:31:44

bllim
Artisan
Registered: 2012-09-07
Posts: 27

Laravel on shared hosting

Hi,

I've encountered with this problem several times and tried different solutions. But, solutions which I tried don't work for all situations. Because some shared hostings can be too strict. For example, your hosting provider may not let you to reach your home directory because of the some security concerns (really don't understand why but I've encountered). On this situation you can't place the laravel working and system directories (I mean except public in root) as a sibling of public directory. They should be in public like I will show below. But before that, I should indicate this method may not be secure. (Actually if you write your opinion about security of the method, It will be great.)

Step 1: First of all, we gather application, bundles, laravel, storage directories, paths.php and artisan in a different directory which we named as larasys (It will be better, if you use different name).

map of directories:

- public
-- larasys
--- application
--- bundles
--- laravel
--- storage
--- paths.php
--- artisan
-- index.php

Step 2: Create a .htaccess file in larasys like below:

deny from all

This will prevent direct access to larasys directory.


Step 3: Then we place larasys in the public (probably in shared hosting you should rename this too. htdocs, public_html, for example) folder.


Step 4: Now we configure our php files. First of all, index.php in public fires the laravel by using paths.php and we changed directory of the paths.php. Because of the fact that, we should change the index.php like below:

<?php
/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @version  3.2.13
 * @author   Taylor Otwell <taylorotwell@gmail.com>
 * @link     http://laravel.com
 */

// --------------------------------------------------------------
// Tick... Tock... Tick... Tock...
// --------------------------------------------------------------
define('LARAVEL_START', microtime(true));

// --------------------------------------------------------------
// Indicate that the request is from the web.
// --------------------------------------------------------------
$web = true;

// --------------------------------------------------------------
// Set the core Laravel path constants.
// --------------------------------------------------------------
require 'larasys/paths.php';

// --------------------------------------------------------------
// Unset the temporary web variable.
// --------------------------------------------------------------
unset($web);

// --------------------------------------------------------------
// Launch Laravel.
// --------------------------------------------------------------
require path('sys').'laravel.php';

Step 5: As you realize, we don't touch place and name of application, laravel, bundles, storage directories. But actually we changed the public. Because of this, we should change paths.php. In brief, we will just change the $paths['public'] = 'public' to $paths['public'] = '..'  , full content of file is below:

<?php
/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @version  3.2.6
 * @author   Taylor Otwell <taylorotwell@gmail.com>
 * @link     http://laravel.com
 */

/*
|----------------------------------------------------------------
| Application Environments
|----------------------------------------------------------------
|
| Laravel takes a dead simple approach to environments, and we
| think you'll love it. Just specify which URLs belong to a
| given environment, and when you access your application
| from a URL matching that pattern, we'll be sure to
| merge in that environment's configuration files.
|
*/

$environments = array(

  'local' => array('http://localhost*', '*.dev'),

);

// --------------------------------------------------------------
// The path to the application directory.
// --------------------------------------------------------------
$paths['app'] = 'application';

// --------------------------------------------------------------
// The path to the Laravel directory.
// --------------------------------------------------------------
$paths['sys'] = 'laravel';

// --------------------------------------------------------------
// The path to the bundles directory.
// --------------------------------------------------------------
$paths['bundle'] = 'bundles';

// --------------------------------------------------------------
// The path to the storage directory.
// --------------------------------------------------------------
$paths['storage'] = 'storage';

// --------------------------------------------------------------
// The path to the public directory.
// --------------------------------------------------------------
$paths['public'] = '..';

// --------------------------------------------------------------
// The path to the upload directory.
// --------------------------------------------------------------
$paths['upload'] = $paths['public'].'/files';

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// END OF USER CONFIGURATION. HERE BE DRAGONS!
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

// --------------------------------------------------------------
// Change to the current working directory.
// --------------------------------------------------------------

//define('__DIR__','/home/hediyemi');

chdir(__DIR__);
// --------------------------------------------------------------
// Define the directory separator for the environment.
// --------------------------------------------------------------
if ( ! defined('DS'))
{
  define('DS', DIRECTORY_SEPARATOR);
}

// --------------------------------------------------------------
// Define the path to the base directory.
// --------------------------------------------------------------
$GLOBALS['laravel_paths']['base'] = __DIR__.DS;

// --------------------------------------------------------------
// Define each constant if it hasn't been defined.
// --------------------------------------------------------------
foreach ($paths as $name => $path)
{
  if ( ! isset($GLOBALS['laravel_paths'][$name]))
  {
    $GLOBALS['laravel_paths'][$name] = realpath($path).DS;
  }
}

/**
 * A global path helper function.
 * 
 * <code>
 *     $storage = path('storage');
 * </code>
 * 
 * @param  string  $path
 * @return string
 */
function path($path)
{
  return $GLOBALS['laravel_paths'][$path];
}

/**
 * A global path setter function.
 * 
 * @param  string  $path
 * @param  string  $value
 * @return void
 */
function set_path($path, $value)
{
  $GLOBALS['laravel_paths'][$path] = $value;
}

That's all. No more step. I tried it works but I might have forgetten to mention something. If you meet some error and unexpected situation, please comment.
Thanks for your attention.

Last edited by bllim (2013-01-27 00:38:04)

Offline

#2 2013-02-12 13:52:59

mdhb2
Apprentice
Registered: 2013-02-12
Posts: 2

Re: Laravel on shared hosting

i try your setting and get these error

 Warning: require(J:\AppServLive\www\laravel\laravel\ioc.php): failed to open stream: No such file or directory in J:\AppServLive\www\laravel\system\laravel\core.php on line 45
Fatal error: require(): Failed opening required 'J:\AppServLive\www\laravel\laravel\ioc.php' (include_path='.;C:\php\pear') in J:\AppServLive\www\laravel\system\laravel\core.php on line 45

please help

Offline

#3 2013-02-12 13:58:42

bllim
Artisan
Registered: 2012-09-07
Posts: 27

Re: Laravel on shared hosting

Are you sure you edit index.php and paths.php correctly?

Offline

#4 2013-02-12 14:13:36

mdhb2
Apprentice
Registered: 2013-02-12
Posts: 2

Re: Laravel on shared hosting

sorry my bad big_smile

i delete all files, extract laravel again copy your configuration, and its ON, thx

Offline

#5 2013-03-06 05:21:54

marron28
Apprentice
Registered: 2013-03-06
Posts: 2

Re: Laravel on shared hosting

Hi,

I got an error following your post.. i checked the paths.php and index.php files and its same as what you did..

heres the error :

Unhandled Exception

Message:

Undefined offset: 6
Location:

/usr/lib/php/head.php on line 90

Thanks in Advance..

Offline

#6 2013-03-06 11:06:54

bllim
Artisan
Registered: 2012-09-07
Posts: 27

Re: Laravel on shared hosting

This may not be related to changing directory structure or index.php/path.php. Can you give more information. For example what is there in /usr/lib/php/head.php on line 90 ?

Offline

#7 2013-03-07 16:56:35

marron28
Apprentice
Registered: 2013-03-06
Posts: 2

Re: Laravel on shared hosting

I dont know whats in there.. its not accecible by my account.. im on a shared host..

Offline

#8 2013-03-07 18:21:55

bllim
Artisan
Registered: 2012-09-07
Posts: 27

Re: Laravel on shared hosting

That's a weird exception smile. I can't really estimate what is the reason behind the error. Undefined offset 6 means there isn't any member of array which its key is 6. But because we can't see the head.php, Thats all what I can say smile.

I would suggest you report this your hosting provider. At least they can see head.php smile.

Offline

#9 2013-03-16 07:49:03

butirpadi
Artisan
From: Indonesia
Registered: 2013-02-18
Posts: 25
Website

Re: Laravel on shared hosting

bllim wrote:

Hi,

I've encountered with this problem several times and tried different solutions. But, solutions which I tried don't work for all situations. Because some shared hostings can be too strict. For example, your hosting provider may not let you to reach your home directory because of the some security concerns (really don't understand why but I've encountered). On this situation you can't place the laravel working and system directories (I mean except public in root) as a sibling of public directory. They should be in public like I will show below. But before that, I should indicate this method may not be secure. (Actually if you write your opinion about security of the method, It will be great.)

[snip]

That's all. No more step. I tried it works but I might have forgetten to mention something. If you meet some error and unexpected situation, please comment.
Thanks for your attention.

I use your way. but I get error like this :

Unhandled Exception

Message:

Class 'PDO' not found
Location:

/home/mysite/public_html/web/application/config/database.php on line 31

please help me....1 month I deploy laravel on shared hosting...with no solution.


Let's Visit Indonesia
You will not be disappointed, come!!!, even once in your life or you'll regret it.

Offline

#10 2013-03-16 10:20:42

bllim
Artisan
Registered: 2012-09-07
Posts: 27

Re: Laravel on shared hosting

Laravel requires PDO library. Are you sure PDO library is installed on your hosting? You can check it by writing this:

<?php new PDO();  

in a file outside of laravel and running it.

Offline

#11 2013-05-04 16:52:18

ricbermo
Artisan
From: Barranquilla, Colombia
Registered: 2013-05-04
Posts: 14

Re: Laravel on shared hosting

Hi.
I've just fallowed this method and I got this error; I also did it on my local enviroment and got the same error. Using Laravel 3.2.14

Unhandled Exception

Message:

Error rendering view: [users.index]

Undefined variable: users
Location:

/home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/storage/views/0c70ee5cce2d0d833e43cbca6be998c1 on line 7
Stack Trace:

#0 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/laravel.php(42): Laravel\Error::native(8, 'Undefined varia...', '/home/vol8/byet...', 7)
#1 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/view.php(386) : eval()'d code(7): Laravel\{closure}(8, 'Undefined varia...', '/home/vol8/byet...', 7, Array)
#2 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/view.php(386): eval()
#3 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/blade.php(71): Laravel\View->get()
#4 [internal function]: Laravel\{closure}(Object(Laravel\View))
#5 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/event.php(199): call_user_func_array(Object(Closure), Array)
#6 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/event.php(138): Laravel\Event::fire('laravel.view.en...', Array, true)
#7 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/view.php(348): Laravel\Event::until('laravel.view.en...', Array)
#8 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/view.php(590): Laravel\View->render()
#9 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/response.php(268): Laravel\View->__toString()
#10 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/laravel.php(180): Laravel\Response->render()
#11 /home/vol8/byethost16.com/b16_13081292/htdocs/index.php(34): require('/home/vol8/byet...')
#12 {main}

Offline

#12 2013-05-04 17:08:28

bllim
Artisan
Registered: 2012-09-07
Posts: 27

Re: Laravel on shared hosting

ricbermo wrote:

Hi.
I've just fallowed this method and I got this error; I also did it on my local enviroment and got the same error. Using Laravel 3.2.14

Unhandled Exception

Message:

Error rendering view: [users.index]

Undefined variable: users
Location:

/home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/storage/views/0c70ee5cce2d0d833e43cbca6be998c1 on line 7
Stack Trace:

#0 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/laravel.php(42): Laravel\Error::native(8, 'Undefined varia...', '/home/vol8/byet...', 7)
#1 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/view.php(386) : eval()'d code(7): Laravel\{closure}(8, 'Undefined varia...', '/home/vol8/byet...', 7, Array)
#2 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/view.php(386): eval()
#3 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/blade.php(71): Laravel\View->get()
#4 [internal function]: Laravel\{closure}(Object(Laravel\View))
#5 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/event.php(199): call_user_func_array(Object(Closure), Array)
#6 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/event.php(138): Laravel\Event::fire('laravel.view.en...', Array, true)
#7 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/view.php(348): Laravel\Event::until('laravel.view.en...', Array)
#8 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/view.php(590): Laravel\View->render()
#9 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/response.php(268): Laravel\View->__toString()
#10 /home/vol8/byethost16.com/b16_13081292/htdocs/nucleo/laravel/laravel.php(180): Laravel\Response->render()
#11 /home/vol8/byethost16.com/b16_13081292/htdocs/index.php(34): require('/home/vol8/byet...')
#12 {main}

It is a rendering issue. The error says, you try to use $users variable in users.index view without send it to view.

Offline

#13 2013-05-04 17:57:21

ricbermo
Artisan
From: Barranquilla, Colombia
Registered: 2013-05-04
Posts: 14

Re: Laravel on shared hosting

Hi. Thanks  for the help but why is this working if I run the same code inside a clean instalation, i mean, using the same model, controllers and views without changing the folder structure?

Offline

#14 2013-05-04 18:08:16

bllim
Artisan
Registered: 2012-09-07
Posts: 27

Re: Laravel on shared hosting

Can you check steps again ? I changed the structure of directory on a live website. I didn't get anything like these.

Offline

#15 2013-05-04 18:20:26

ricbermo
Artisan
From: Barranquilla, Colombia
Registered: 2013-05-04
Posts: 14

Re: Laravel on shared hosting

This is what i did. I created a folder inside my public_html called nucleo and uploaded everything but public dir. Then uploaded the js/css/img .htcacces and index.php in public_html; same level as nucleo folder. Next in index.php changed the path route to nucleo/path.php, finally in path.php changed the public variable to "..". I hope you coulld help me. I could give you acces to my hosting since this is a free hosting just for testing.
Thanks for your time

Offline

#16 2013-05-04 19:44:49

ricbermo
Artisan
From: Barranquilla, Colombia
Registered: 2013-05-04
Posts: 14

Re: Laravel on shared hosting

Hi.
I found what was happening. and bllim you were right. In my routes.php i got this.
Route::get('/', function(){
    return View::make('users.index');
});

in my UsersController this:

public function __construct(){
      parent::__construct();
      $this->filter('before', 'auth');
}

I thought that this part in the controller was going to redirect me to login if the user was not logged in.

the i just changed the route to

Route::get('/', array('before' => 'auth', function(){

    return View::make('users.index');
}));

Offline

#17 2013-05-04 20:38:13

bllim
Artisan
Registered: 2012-09-07
Posts: 27

Re: Laravel on shared hosting

I'm happy about your problem is solved smile . Have a nice day...

Offline

#18 2013-06-06 19:25:04

santiagogg
Artisan
From: Argentina & UK
Registered: 2013-06-04
Posts: 10

Re: Laravel on shared hosting

Thanks!

Offline

#19 2013-06-18 13:41:10

ardinotow
Apprentice
From: Bandung, Indonesia
Registered: 2012-09-24
Posts: 4

Re: Laravel on shared hosting

butirpadi wrote:

please help me....1 month I deploy laravel on shared hosting...with no solution.

What hosting provider do you use? I'm from Bandung and looking for nice shared hosting, hehe

Offline

Board footer

Powered by FluxBB

');