Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to point laravel project to a public folder under public_html in shared hosting [duplicate]

Tags:

php

laravel

  1. I have a second domain on my shared hosting account.
  2. My laravel project is in the root dir
  3. The laravel public folder is under public_html. public_html/public

Note: I don't want the public files directly under public_html because I have other files that would be overwritten.

I've already changed these to lines in my index.php file.

require DIR.'/../../MyOtherDomain.com/vendor/autoload.php';

$app = require_once DIR.'/../../MyOtherDomain.com/bootstrap/app.php';

The question is how do i point the laravel project to use the index.php file under public_html/public?

Thanks in advance.

like image 587
Troy Mitchel Avatar asked Oct 20 '25 02:10

Troy Mitchel


2 Answers

Add a .htaccess file in your root directory and paste the following code

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Save and reload your browser.

like image 65
Loyd Tafireyi Avatar answered Oct 21 '25 17:10

Loyd Tafireyi


Since you're using shared hosting, you need to change the document root of the domain to public_html/public. Then you need to point index.php to your Laravel project (which must only be located outside the public_html folder) by editing the following code:

require DIR.'/../../MyOtherDomain.com/vendor/autoload.php';
$app = require_once DIR.'/../../MyOtherDomain.com/bootstrap/app.php';

Note- MyOtherDomain.com folder should contain the Laravel project.

like image 31
planet-pranav Avatar answered Oct 21 '25 15:10

planet-pranav