7

I can't find any information whatsoever about performing a Laravel installation in a subfolder.

Is it even possible to do this? Or is it a Laravel requirement to be installed at root level?

My hosting provider doesn't allow me to create VirtualHosts, and I need to install a Laravel application alongside what's currently up there...

UDPATE: turns out it was mainly an .htaccess issue:

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>
Pierlo Upitup
  • 1,614
  • 4
  • 19
  • 27

1 Answers1

9

First, take in consideration that this answer is just to make it work, I am not sure about any implications this may have in security due to every folder being in the public part of your site.

Second, I just tried this with a barebones laravel installation, so I'm not sure if this can have effects later in development (my guess is not, but you never know).

1) Copy all the contents of the public folder in the root laravel folder (which is your subfolder)

2) You can now remove the empty public folder

3) edit index.php and change

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

to

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

4) edit paths.php and change

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

to

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

5) Edit the .htaccess file in the laravel folder to make it redirect no more into public

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
mrzard
  • 311
  • 1
  • 4
  • well, moving all the contents of the public folder to the root is already not what I'm looking for, as the css, img and js folders would clash with the other installation. Also, as I said, keep in mind that there is already anoter custom framework on the root level, so overwriting the /index.php file is no option. – Pierlo Upitup Oct 08 '12 at 14:36
  • By root folder I was referring to the root laravel folder, you can put this into a folder in your installation and then access it in www.yourdomain.com/laravelfolder – mrzard Oct 08 '12 at 14:46
  • I followed your instructions but I'm getting a 500 Internal Server Error. What could that be? – Pierlo Upitup Oct 08 '12 at 14:57
  • Without looking at the logs it's hard to say. As I said, I tried this with a clean laravel installation in a subfolder and it worked for me, but it may not be compatible with all configurations. I'd check the logs, then the .htaccess files to see whether it is possible to determine where that 500 is coming from. – mrzard Oct 08 '12 at 15:00
  • MAMP apache log says: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. My htaccess is ` RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L] ` – Pierlo Upitup Oct 08 '12 at 15:07
  • Ok, that looks like a .htaccess problem in your root folder (not the laravel one). Try adding `RewriteCond %{REQUEST_FILENAME} !-f` and in the next line `RewriteCond %{REQUEST_FILENAME} !-d` before `RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L]` – mrzard Oct 08 '12 at 15:08
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/17704/discussion-between-pierlo-upitup-and-mrzard) – Pierlo Upitup Oct 08 '12 at 15:11