0
votes

I have a problem deploying Laravel to a shared hosting server.

This is how the the directory looks in the server.

|-Laravel(contents of Laravel project folders and files except public folder)  
|
|-public_html  
       |  
       |-example.com(default subfolder))  
             |  
             |-contents of Laravel public folder

I created a folder called "Laravel" at the same level where the public_html folder is and threw all the Laravel project folders and files(except public folder) in there. Then I took everything that was in the public folder and put it in a subfolder in public_html.

Next I changed the index.php file like in the image. index.php

I also changed .env file too(APP_ENV=production and APP_URL).

At this point I think I should be able to see something when I access to http://www.example.com/ but I get a 500 Internal Server Error.

My Laravel is version 7.15.0.

I appreciate if you could tell me what I'm doing wrong or what I should do. Any help would be appreciated as I have tried multiple methods with no success.

Thank you in advance.

2
Hello and welcome to stackoverflow, toyop! One question: Did you create-import the database and database user? And did you set APP_DEBUG=false at the .env? Also get sure to grant the correct righs to the "logs" folder (755).María Antignolo

2 Answers

0
votes

within the index.php file, after where $app is defined, add in the following line

$app->bind('path.public`, function() {
   return __DIR__;
})
0
votes

Generally, in shared hosts you have to symlink the public directory of your Laravel project as public_html in your server.

You can deploy your project to any folder in your server, including the public folder. Then just symlink the public directory as public_html, using the ln -s linux command:

ln -s <PATH TO THE ORIGINAL PUBLIC FOLDER> <PATH TO public_html/example.com>

Note that you should rm -rf public_html/example.com directoy before creating the symlink