Search code examples
phplaravelsymlinklaravel-7shared-hosting

Problem with Symbolic links in PHP\Laravel



I am using Laravel 7 on Direct admin. I don't actually have access to Command Line/Terminal, and I need a Symbolic link of Storage.

I have Tried:

Route::get('/foo', function () {
    Artisan::call('storage:link');
});

and also:

symlink('/domains/MyProject.com/LaravelFolder/storage/app/public', '/domains/MyProject.com/public_html');

But I am receiving this Error:

symlink() has been disabled for security reasons

My LaravelFolder is Placed before public_html.

UPDATE: I realized that the Hosting company disabled this function; I asked them to enable it, But They say: it is impossible. Do you know an alternative way to do that?


Solution

  • Old Solution

    But I finally Solved This, It seems little bit stupid but it works:

    In Ubuntu Linux I tried to create a symlink like the storage symbolic link in Laravel, with the following Command:

    ln -s ../laravelFolder/storage/app/public storage
    

    and then I compressed this symbolic link and uploaded to my public_html Folder and it works. I hope it will be Helpful..

    2022 UPDATE (New Solution)

    In such cases that your projects production environment is a Linux server and you are developing your project on Windows I offer you to set up a WSL (Windows Subsystem for Linux) development environment.

    This way you can simply use Linux terminal to creating a symbolic link with the following command:

    // change laravelFolder with your laravel folder name
    ln -s ../laravelFolder/storage/app/public storage
    

    Here is Microsoft's quick guide to install and use WSL.