ali_fattahi's avatar

Error 500 in laravel on shared hosting

Hello dear friends I have a shared host with directadmin control panel . I Uploaded the public folder contents in public_html and other files in parent directory . But when I want to open my website in chrome shows me "Server error 500" and I don't get any error log in laravel and my hosting logs ! even didn't open laravel error page or any page that shows me the error! How can i solve this problem ?

Best Regards Ali

0 likes
20 replies
cimrie's avatar

Hey @ali_fattahi

Maybe make sure that the permissions on the folders are correct. For instance, I think 'storage' has to have more relaxed permissions (755 or so). Quite often uploading via FTP can lose the permissions attached to folders.

Also, can you tell us about the folder structure of your shared host? Have you placed everything inside a 'public_html' folder or something? Just because it's also likely that you need to make sure your public folder is the only one publicly available, and having it in the wrong place might cause issues like this.

Throw as much information as you can think of concerning your shared hosting environment / file structure and what you have done so far and we can go from there.

ali_fattahi's avatar

Hello Clmrie all permissions are currect , all files are 644 and all folders are 755.

the folder structure of my host is : /home/myhost_username/domains/domain.com/public_html or /home/myhost_username/public_html

yes I have placed any file in "public" directory to my host "public_html" directory. and other project's directories in parent of public_html directory.

the vps is mine and I can change any configuration in directadmin and other parts . the webserver is nginx , all nginx configuration is the same as in installation document.

cimrie's avatar

Hi @ali_fattahi

Great, that all sounds ok then. Does the shared environment use cPanel to administer it? If so there should be an 'Error Logs' section that shows server-side errors like 500. Are you able to tell me the domain name or post a screenshot link so that I can see what the error looks like (helps determine if it is server-side or code)?

BrianVeltman's avatar
Level 12

Have you changed the index.php within your public_html?

Bootstrap and Autoload path should be updated to find your app.

//Original path
require __DIR__.'/../bootstrap/autoload.php';

//Modified path
require __DIR__ . '/../your-project/bootstrap/autoload.php';

//Original path
$app = require_once __DIR__.'/../bootstrap/app.php';

//Modified path: 2 levels up 
$app = require_once __DIR__ . '/../your-project/bootstrap/app.php';

Upload your laravel project folder to: /home/myhost_username/domains/domain.com/YOUR-PROJECT Note: this is outside the public_html directory

Upload the contents of YOUR-PROJECT to the public_html directory

2 likes
Snapey's avatar

If the project structure is all in the parent to public_html then no changes to index.php should be necessary.

  • Make sure you have the correct php version enabled
  • Make sure you have the pre-requisite bcrypt library
  • Ensure you have a key set
  • Make sure you have copied the hidden .htaccess file to your server's public_html folder
  • Try serving an image from public_html and check it is displayed
  • deliberately change index.php to have php_info() or similar right at the top (even just echo 'hello';)
  • Put in a simple route, again, echo hello.
  • Dump-autoload and clear-compiled before uploading the project
1 like
BrianVeltman's avatar

You have to remove 'ini_set' from the disabled functions in your php.ini as well.

But what Snapey said; make sure you can access the files in the public_html directory.

If your error log shows 'unexpected . in index.php on line 22' then you you have to update the path as I mentioned above.

BrianVeltman's avatar

@ali_fattahi We need a screenshot of the error log. Please send us a screenshot or output of the <?php phpinfo(); ?> command as well. Without this information we can not help you.

ali_fattahi's avatar

@Brianv Thenk you for reply
I don't get any error log in php and linux... , this is our main problem :)
the error log is empty in my host and php dosen't show any error !
here is phpinfo()
[removed]
laravel project : [removed]

BrianVeltman's avatar

@ali_fattahi can you ssh into the server and tail the /var/log/httpd/error.log ? Or can you create a temporarily account for me on your DirectAdmin server? Then I'll setup a Laravel website and see if I stumble upon any issues.

ali_fattahi's avatar

Thank you brian , You solved my problem :)
for others , the problem was for paths of laravel project.
I tagged the answer

best regards

1 like
Awais_Jameel's avatar

Hello @BrianVeltman I think the same problem is happening to me now. Can you Please guide me how to correctly deploy an laravel website . Thanks.

kdrenski's avatar

Had the same exact issue and in my case the problem was the default php version (which was 5.5+) of the shared hosting service that I use. After I changed it to 7+ (laravel 5.5 needs php version >= 7) everything started to work. Hope that helps someone!

murph133's avatar

I recommend checking the server error logs.

I discovered the follow error: SoftException in Application.cpp:261: File "/home/wpwfcom/public_html/my_project_name/index.php" is writeable by group

When I changed the file permission of the index.php file from 664 to 644, this resolved this particular problem. No more 500 error.

1 like
Jester_'s avatar

For me the problem was not enough memory for php. But the 500 error appeared only after some excel spreadsheet operation.

Please or to participate in this conversation.