photo Laravel: change public html to public_html

The correct solution suggested to resolve this issue , is to move your existing files in laravel “public” directory to the adequate required document root folder , example “public_html”


Moving Laravel onto a production server may cause some issue with the document root folder (public folder), in the most shared servers the default public folder is named public_html or www, whats may present a problem since the server document root and Laravel public folder are not the same.

The correct solution suggested to resolve this issue , is to move your existing files in laravel “public” directory to the adequate required document root folder , example “public_html” (the most used in shared servers runing WHM/CPanel)

then go to your public_html/index.php and add, just after the line where $app is created:

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

this will bind the document root to he current file path, where index.php exists

also, to fix the path for scripts used in CLI mode or Artisan script, you should add the code below to the file /bootstrap/app.php

$app->bind('path.public', function() { return base_path().'/public_html'; });

this will bind Laravel document root with the correct one, in this case we are linking it to public_html folder, you can also put the full path to your document root instead of the dynamic approach.

make a changes to the server.php file for it to work local.

if ($uri !== '/' && file_exists(__DIR__.'/public_html'.$uri)) {
return false;
}
Go back