Search code examples
laravel-8laravel-routing

Laravel Project - After upload hosting server faced the issue for 500 Server Error and website menu link issue


I have faced the issue for website not working properly.[Project file uploaded in sub folder]. Folder Path : example.com->public_html->lrvproject Please note the below issues:

  1. Home Page - 500 Server Error. https://www.example.com/lrvproject/
  2. Sub Pages open - I have manually enter page path it's showing page. Example: https://www.example.com/lrvproject/contact
  3. After loading subpages Menu link URL showing is "https://www.example.com/contact".

I have refer the tutorial inside public(folder copy all file and paste outside public folder).

index.php [https://www.example.com/lrvproject/index.php]

if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
require __DIR__.'/../storage/framework/maintenance.php';
}

require __DIR__.'/../lrvproject/vendor/autoload.php';

$app = require_once __DIR__.'/../lrvproject/bootstrap/app.php';

$kernel = $app->make(Kernel::class);

$response = tap($kernel->handle(
$request = Request::capture()
))->send();

$kernel->terminate($request, $response);

web.php (routes)

use Illuminate\Support\Facades\Route;
//use App\Http\Controllers\UserAuthController;

Route::get('/','HomeController@index');
Route::get('/about', function () {
return view('pages/about');
});
Route::get('/gallery','ImageGalleryController@index');
Route::get('/contact','ContactController@index');
Route::post('/contact','ContactController@sendmail');

server.php [https://www.example.com/lrvproject/server.php]

   $uri = urldecode(
   parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
   );

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

   require_once __DIR__.'/public/index.php';
   //require_once __DIR__.'/index.php';

.htaccess [https://www.example.com/lrvproject/.htaccess]

<IfModule mod_rewrite.c>
  <IfModule mod_negotiation.c>
    Options -MultiViews -Indexes
  </IfModule>

  # Disable Directory listing
  Options -Indexes

  # block files which needs to be hidden, specify .example extension of the file
  <Files ~ "\.(env|json|config.js|md|gitignore|gitattributes|lock)$">
    Order allow,deny
    Deny from all
  </Files>

  RewriteEngine On

  # Handle Authorization Header
  RewriteCond %{HTTP:Authorization} .
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

  # Redirect Trailing Slashes If Not A Folder...
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} (.+)/$
  RewriteRule ^ %1 [L,R=301]

  # Send Requests To Front Controller...
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [L]
  </IfModule>

Already Server Folder Permission enabled. PHP extensions enabled. How to solve the issue. please help.


Solution

  • I have solved the issue. I have updated the below steps.

    1. .env file database details updated, now my home page worked.

    2. index.php [https://www.example.com/lrvproject/index.php] -Edit

      require DIR.'/vendor/autoload.php'; $app = require_once DIR.'/bootstrap/app.php';

    3. Web menu links URL-Edit

      href="/lrvproject/contact" link path update "Contact US"

    4. Clear Cache in Server

    5. My Laravel Application Running in Server (Sub-folder directory)