I am hosting my Laravel project on shared hosting where I don't have access to modify the apache config to look for the index
file in /public
.
I've also tried adding DirectoryIndex index.html
to my .htaccess
file at the place where the hosting is looking for the index.php
file.
This does not work.
That being said, I think I can solve the problem if I simply move the index.php
file out of /public
(where Laravel has it by default) to the root
where the hosting is looking for it.
That being said, what do I need to modify in this index.php
file to allow the Laravel app to work?
My structure is:
public_html/ <-- where my files are served from and where index.php should be
my-project/
public/
index.php <-- where Laravel expects index.php to be to bootstrap the app
Okay here we go:
Let's say this is your folder structure:
MyUser/
public_html/
public/
Step 1. create a folder on the same level as public_html
named laravel
(or something to your liking):
MyUser/
laravel/
public_html/
public/
Step 2. upload ALL your laravel code to the laravel
folder. Your code is now inaccessible through a web browser.
Step 3. Next, you copy all data from MyUser/Laravel/public
to MyUser/public_html
. Now we're getting somewhere. Warning: Don't forget to copy the .htaccess
file too
Step 4. open MyUser/public_html/index.php
in your favorite editor and change
$app = require __DIR__.'/../bootstrap/app.php';
to:
$app = require __DIR__.'/../laravel/bootstrap/app.php';
and change:
require __DIR__.'/../bootstrap/autoload.php'
to:
require __DIR__.'/../laravel/bootstrap/autoload.php'
Step 5. Now, since your storage
directory is outside of your public_html
, it'll most likely not be accessible, so CHMOD
that to 777, and you're done!
A small tip:
See if you can create a symlink
from MyUser/laravel/public
to MyUser/public_html
. That'll let you skip step 3 and 4.
Hope this helped.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.