Laravel smlink not found - php

I upload my laravel website to shared hosting ". Every things work except i am not able to retrieve images stored in the storage/public folder. I ran
"php artisan storage:link"
but it says not found. I also tried
rm storage
but the getthe message rm: cannot remove. Is directory
php artisan storage:link output from ssh command

Note, I'm not addressing the original answer because it doesn't sound like it can be done. This is an alternate solution.
Solution
In your config/filesystems.php file, you'll see the following code (or something similar).
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
],
],
To link your public disk to a public directory without using OS symlinks, change the disks['public']['path'] to the public path of your choosing. For example,
'disks' => [
/** -- skipped code **/
'public' => [
'driver' => 'local',
'root' => __DIR__ . '../public/images/`,
'url' => env('APP_URL').'/images',
'visibility' => 'public',
],
/** -- skipped code **/
],
Another Solution
You can totally use the S3 storage as well. That will connect you with an AWS bucket that you can use.
Personal Anecdote
Shared hosting can be tricky with Laravel. I would transition away as soon as I could. I use Laravel Forge to deploy servers and Digital Ocean or AWS for hosting.

Related

Fetch Laravel Storage files that are in the storage/folder directory not in storage/app/directory

I'm attempting to pull in a certs file from the directory /storage/certs/certexample.pem in my laravel 6 application.
Whenever I try to run the command:
Storage::get('storage/certs/certexample.pem'))
or use
storage_path('certs')
to fetch the full path I get the error:
League\Flysystem\FileNotFoundException: File not found at path:
The file does exist and I can cat it out on the terminal so there must be something I'm missing.
My filesystem config looks like this:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
I've tried adding in another disk called 'certs' that has storage_path('certs') set however this doesn't seem to help.
Since the file is only ever placed on the server and the app isn't writing it I don't need to write the file using Storage as I've seen in the docs. Is there a way to pull the certsexample.pem file (or a similar file) in this manner or am I missing something with Laravel's Storage functionality?
Update:
After attempting to get a folder to be accessed outside of storage/app with no luck I ended up using the sotrage/app/certs directory and accessing it with storage_path('app/certs').
I had the same problem. I updated config file in config/filesystems.php and added my folder in /storage:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
//my custom directory in storage folder
'orders' => [
'driver' => 'local',
'root' => storage_path('egrn/orders'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
//...default config code
],
And I got the file like:
$storage = Storage::disk('orders')
->get('/kv66cba66ca6cf667995888bf12cc4d25d.xml');
Full path is /storage/egrn/orders/kv66cba66ca6cf667995888bf12cc4d25d.xml

Laravel upload a file to different storage outside the project directory

I'm creating a CMS wherein I can upload files(photos, pdf, etc) using Laravel's file upload. What I'm doing differently is that I want to store the file outside my CMS project directory let's say my website's storage folder. BTW I'm creating two different projects
Laravel documentation says that I can change the path where it will be uploaded in the filesystems.php what I did is get the relative path of my website storage folder and paste it here(see below).
'local' => [
'driver' => 'local', //here
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
As expected it's not working. Any help guys?
You can add multiple disk in your file system.
Just locate on same website storage folder
Example:
Project 1:
'disks' => [
'custom_folder_1' => [
'driver' => 'local',
'root' => '../path/to/your/new/storage/folder',
],
]
Project 2:
'disks' => [
'custom_folder_2' => [
'driver' => 'local',
'root' => '../path/to/your/new/storage/folder',
],
]
the path should be the same location.
../path/to/your/new/storage/folder
and then you can use it like:
Storage::disk('custom_folder_1')->put('filename1', $file_content);
Storage::disk('custom_folder_2')->put('filename2', $file_content);

How to enable mount network disk in elfinder laravel for google drive

I have question of elfinder, how to enable 'Mount Network Disk' on elfinder for use google drive in laravel 5.2. Could tell you me, which are steps to follow.
The steps i followed were:
Installation with composer.
composer require barryvdh/laravel-elfinder
Add the ServiceProvider to the providers array in app/config/app.php
Barryvdh\Elfinder\ElfinderServiceProvider::class
Copy the assets to the public folder, using the following artisan command:
php artisan elfinder:publish
Run command.
composer update
I used the default configuration, I created the folder 'files' in the public folder.
With the command
php artisan vendor:publish --provider='Barryvdh\Elfinder\ElfinderServiceProvider' --tag=config
and
php artisan vendor:publish --provider='Barryvdh\Elfinder\ElfinderServiceProvider' --tag=views
In the file elfinder.php with the route
'vendor/barryvdh/laravel-elfinder/config/elfinder.php'
In the section route use
'route' => [
'prefix' => 'elfinder',
'middleware' => null, //Set to null to disable middleware filter
]
In the file filesystems.php with the route
'/config/filesystems.php'.
In the section disk in the option public, add the line
'root' => base_path().'app/public',
after of the line
'driver' => 'local',
Example:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => base_path().'app/public',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => 'your-key',
'secret' => 'your-secret',
'region' => 'your-region',
'bucket' => 'your-bucket',
],
],
This is how i solved the error that occurs when you use the copy option, open folder, etc.
Error, Unable to connect to backend. HTTP error 0
But I do not know, what is needed to use the mount network disk.And
how to give the folder(example: Reading)
This is link of the project
https://github.com/AlonsoCauich/driveOne

Voyager admin panel on Laravel 5.3 could not find a storage symlink

Help guys: I tried to test the new Laravel admin and got the following error:
Missing storage symlink We could not find a storage symlink. This
could cause problems with loading media files from the browser.
I tried to use:
php artisan storage:link
Set in Nginx config:
disable_symlinks off;
But it still is not working.
Delete first the existing storage link in public.
after, re-run (in app path)
php artisan storage:link
I have fixed the image issue by editing config/filesystems.php
change the 'public' => root & url value as per your project.. i think it will fix it..
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('../../public_html/images'),
'url' => env('APP_URL').'/images',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
Having struggled with this symbolic link, here is the procedure:
Once the installation is done on the production server:
cd public
rm storage
Go to the admin panel of Voyager and click on Fix It. Do not use the PHP command artisan storage:link.
Everything works now.

Why are my filesystem paths differing in local machine and when hosted on VPS?

I have some storage operations being done in my controllers, this is the code that works on my local machine:
Storage::copy('public/filename.pdf', 'public/sub_directory/filename_'.$var.'.pdf');
Storage::delete('public/filename.pdf');
With this code, I am successfully able to copy a file in laravel_root/storage/app/public/, then copy and rename the file to laravel_root/storage/app/public/subdirectory/, the file in public/ gets deleted after the copy operation. This works on my local machine.
When I pushed the code up to the staging server, above paths did not work and I got ERROR: No such file or directory.
I got this working by changing the paths from what worked on the local machine to :
Storage::copy('filename.pdf', 'subdirectory/filename_'.$var.'.pdf');
Storage::delete('job_card.pdf');
I had to remove out the public/from the operations.
My question is - Why does this differ in local machine and when pushed to server?
I am running on macOS on local Machine and ubuntu 16 on the staging server. I did not change any of the config files.
I would say this has to do with your filesystems config.
Look in config/filesystems.php for the root of the disks.
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => 'your-key',
'secret' => 'your-secret',
'region' => 'your-region',
'bucket' => 'your-bucket',
],
],
Local is storage_path('app') and public is storage_path('app/public')

Categories