1
votes
  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.

2
public_html/public this is not actually how it sounds, you just need to copy all files from public folder to public_html, you don't create public folder in public_html, public folder is public_html on server, Now just keep css, js and fonts and front-end files into public folder and if you are uploading any image or document (i'm assuming uploaded files are going to be overwritten ) keep these into storage folder which is already in the root, this way you can keep all files safe.My question is do you want css and others front-end files to be overwritten too ?Vipertecpro
@ViperTecPro, hey, thanks for your comment. that's why I didn't want to put all the public files directly in the public_html folder because I have a bunch of other files located there.Troy Mitchel

2 Answers

1
votes

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.

2
votes

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.