ethar's avatar
Level 5

images not working after upload to shared host

im using laravel 11 in local host image showing successfully, but after upload image not showing.

after upload i devide project into tow folder code public_html //move content of public folder inside it

when i go to public_html im not found storage simlink that created using

php artisan storage:link

i edited index.php

<?php

// // Specify the paths
$sourcePath = __DIR__ . '/../code/storage/app/public';
$targetPath = __DIR__ . '/../public_html/storage';

// Check if the symlink doesn't exist before creating it
if (!file_exists($targetPath)) {
    symlink($sourcePath, $targetPath);
}

// Continue with the rest of your index.php code
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));

// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__.'/../code/storage/framework/maintenance.php')) {
    require $maintenance;
}

// Register the Composer autoloader...
require __DIR__.'/../code/vendor/autoload.php';

// Bind the public path...
$app = require_once __DIR__.'/../code/bootstrap/app.php';
$app->bind('path.public', function() {
    return __DIR__.'/../public_html';
});

// Bootstrap Laravel and handle the request...
$app->handleRequest(Request::capture());

then simlink recreated but image still now showing

0 likes
1 reply
Snapey's avatar

I would

  1. undo changes to index.php
  2. restore the public folder contents
  3. delete the public_html folder
  4. create a symlink called public_html pointing to laravel's public folder
  5. run the artisan storage:link command

Please or to participate in this conversation.