Problem with Symbolic links in PHP\Laravel - php

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?

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.

You can modify the public disk's root path to point directly public folder. Consider the below snippet;
/** /config/filesystems.php */
'disks' => [
// ...
'public' => [
'driver' => 'local',
'root' => public_path('storage'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
// ...
],
Note that this is not a best practice.

Related

Laravel cannot find public dir

I worked on a team and then clone the laravel/php codes from our repository. When I serve the laravel on localhost, it cannot find all the file inside the public directory and throw an error on the terminal:
[404]: GET /public/css/style.css - No such file or directory
Many answers to similar issues advise me to change the codes in the blade.php file. The problem is that I can't edit the blade.php because it works fine on other team members even though we have the same ubuntu, PHP, and laravel version and .env file.
What I have tried:
Run composer install and composer update
Try different browsers such as firefox and chromium-based browsers
Run php artisan storage:link
Restart apache2
Run npm install and npm run dev
I think there is some package or something missing.
List of paths I get from dd($__data):
"path" => "/project-directory/project-name/app"
"path.base" => "/project-directory/project-name"
"path.lang" => "/project-directory/project-name/resources/lang"
"path.config" => "/project-directory/project-name/config"
"path.public" => "/project-directory/project-name/public"
"path.storage" => "/project-directory/project-name/storage"
"path.database" => "/project-directory/project-name/database"
"path.resources" => "/project-directory/project-name/resources"
"path.bootstrap" => "/project-directory/project-name/bootstrap"
Have you tried?
php artisan storage:link
You need first run
php artisan storage:link
For more details check https://laravel.com/docs/8.x/filesystem
Then you must be check your .env values.
Is correctly APP_URL=
Also in your exception is strange
/public/.../...
Reason is wrong configuration.
First check your .env values like
APP_URL=...
FILESYSTEM_DRIVER=public
then check config/filesystems.php

Laravel get public url for file stored in storage public folder

On Windows I have Xampp. My application is in Anuglar and Laravel 8
I add files to folder public in storage folder.
Configuration in filesystem.php:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
In .env file:
APP_URL=http://localhost:8082/prftbx-crm-api/public
File in public folder:
Directory of C:\xampp\htdocs\crm-api\storage\app\public
06/25/2021 11:01 AM <DIR> .
06/25/2021 11:01 AM <DIR> ..
04/26/2021 10:57 PM 14 .gitignore
06/25/2021 11:01 AM 510 381787c3ad1442cc882ee427e93af805.txt
In Laravel I return url using method:
$fileDTO->filePath = Storage::url($fileEntity->file_name);
And in view I have address:
/storage/381787c3ad1442cc882ee427e93af805.txt
When I type url in the browser:
http://localhost:8082/crm-api/public/storage/381787c3ad1442cc882ee427e93af805.txt
I get 404, file not found
First run following command
php artisan storage:link
then you can
http://localhost:8082/storage/381787c3ad1442cc882ee427e93af805.txt
keep app url as
APP_URL=http://localhost:8082
As document says
The public disk included in your application's filesystems
configuration file is intended for files that are going to be publicly
accessible. By default, the public disk uses the local driver and
stores its files in storage/app/public.
To make these files accessible from the web, you should create a
symbolic link from public/storage to storage/app/public. Utilizing
this folder convention will keep your publicly accessible files in one
directory that can be easily shared across deployments when using zero
down-time deployment systems like Envoyer.
To create the symbolic link, you may use the storage:link Artisan
command:
php artisan storage:link Once a file has been stored and the symbolic
link has been created, you can create a URL to the files using the
asset helper:
Ref:https://laravel.com/docs/8.x/filesystem#the-public-disk

How to display image from another disk in Laravel

I am trying to display an image in my Laravel application. The image comes from another disk which is a samba share. I followed the configuration instructions from the Laravel Doc, here is my setup:
filesystems.php
'shop_storage' => [
'driver' => 'local',
'root' => env('SHOP_STORAGE_PATH', base_path('shop_storage')),
'dir' => [
'public' => 0777,
'private' => 0777,
]
],
My samba share is mounted into the root folder /shop_storage inside my Laravel application with the following command:
sudo mount.cifs //PATH_TO_FILE_SHARE/ARMMAG ./shop_storage -o credentials=$HOME/.smbcredentials,rw,file_mode=0777,dir_mode=0777,mfsymlinks
I correctly see all files when I open the folder.
Then, I added a Symlink from /public/storage to /shop_storage with the following command:
sudo ln -s /shop_storage /public/storage (Using full path starting at /home, removed here for privacy)
When I open /public/storage, I correctly see the symlink pointing to the samba share. If I click to open it, I see all the files. The file I am looking for exists.
The problem is when I am trying to display it in my webpage, the request return a 404.
Here is some of the things that I have tried:
<img src="{{\Storage::disk('shop_storage')->url('products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png')}}">
<img src="http://localhost:8000/shop_storage/products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png">
<img src="{{asset('products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png')}}">
<img src="{{asset('storage/products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png')}}">
What am I doing wrong?
Edit
After some try/error, I managed to get a different response with the following syntax:
<img src="{{asset('storage/shop_storage/products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png')}}">
Now, I am getting the foloowing error
You don't have permission to access /storage/shop_storage/products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png on this server.
My permission are set to 777, what could cause this?
What I ended up doing to make this work is mount my share directly into public/storage instead of using symlinks. Then any I could access the file using the laravel asset helper:
<img src="{{asset('storage/products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png')}}">

Unable to load FFMpeg in file in laravel project

i'm trying to convert a varity of audio files into a specific audio type of my chossing on my laravel project.
on my search i landed on a package called Laravel FFMpeg, i started with a fresh installation with laravel 6.2, and did the installation as it shows on github, as soon as i started using it i had this error :
FFMpeg\Exception\ExecutableNotFoundException: Unable to load FFMpeg in file C:\Users\Hatim\Desktop\Projects\Audio\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\Driver\FFMpegDriver.php on line 55
#0 C:\Users\Hatim\Desktop\Projects\Audio\vendor\pbmedia\laravel-ffmpeg\src\Support\ServiceProvider.php(61): FFMpeg\Driver\FFMpegDriver::create(Object(Illuminate\Log\LogManager), Object(Alchemy\BinaryDriver\Configuration))
I'm currently just working with a simple thing :
FFMpeg::fromDisk('s3');
and yes I have called it my Controller: use ProtoneMedia\LaravelFFMpeg\Support\FFMpeg;
I have also tried to install the PHP-FFMpeg Package and also tried to install FFmpeg on my device and link it using the path in my config\laravel-FFmpeg
This is how it looks now without any modification, I went to my .env folder but it has nothing regarding FFmpeg so it takes the default value, that's why I tried installing it on my device and replacing the default value with the path of the FFmpeg on my device.
return [
'ffmpeg' => [
'binaries' => env('FFMPEG_BINARIES', 'ffmpeg'),
'threads' => 12,
],
'ffprobe' => [
'binaries' => env('FFPROBE_BINARIES', 'ffprobe'),
],
'timeout' => 3600,
'enable_logging' => true
];
I'm currently working on my local environment, but this has to work on a server.
I have solved the problem, this response is for future developers having a problem with the package.
first of all you have to install FFmpeg on your device, [click me][1]
chose your os and download it, unzip it rename it to FFmpeg, and then copy the folder and place it in your c: folder for example.
after that just go to your config\laravel-FFmpeg file in your project and change the defaults to the exact path in c: folder
'ffmpeg' => [
'binaries' => env('FFMPEG_BINARIES', 'C:\ffmpeg\bin\ffmpeg.exe'),
'threads' => 12,
],
'ffprobe' => [
'binaries' => env('FFPROBE_BINARIES', 'C:\ffmpeg\bin\ffprobe.exe'),
],
Like a suggestions: set in your local .env file:
FFMPEG_BINARIES=C:\bin\ffmpeg.exe
FFPROBE_BINARIES=C:\bin\ffprobe.exe

spatie/laravel-backup "mysqldump" doesn't recognized when I run it through Artisan class

I'm using spatie/laravel-backup in a WAMP localhost.
It works fine when I type manually in the windows cmd:
php artisan backup:run
But when I try to run the backup using the laravel Artisan class:
Artisan::call('backup:run');
It throw an error:
'mysqldump' not recognized ...
In the laravel mysql config I've also specified the path to the dumper:
'mysql' => [
'driver' => 'mysql',
// ...
'dump' => [
'dump_binary_path' => 'E:/wamp/wamp64/bin/mysql/mysql5.7.9/bin',
],
],
How can i fix that?
EDIT
Probably it's just support "bug" for windows (finded out thanks Loek's answer), as the author says, so can I run a backup in a controller without a command safely? maybe with something like:
use Spatie\Backup\Tasks\Backup\BackupJobFactory;
BackupJobFactory::createFromArray(config('laravel-backup'))->run();
As the command itself.
I believe it's the forward slashes. Try this:
'mysql' => [
'driver' => 'mysql',
// ...
'dump' => [
'dump_binary_path' => 'E:\\wamp\\wamp64\\bin\\mysql\\mysql5.7.9\\bin',
],
],
EDIT
Support for Windows is wonky at best, with multiple "This package doesn't support Windows" comments from the creators on GitHub issues. This one is the latest: https://github.com/spatie/laravel-backup/issues/311
It could also be a permission problem. Executing from the command line is probably happening from another user than executing from the web server, so Windows is denying access to mysqldump.
2nd edit
As long as you make sure the controller only gets called when it needs to be, I don't see why this wouldn't work!

Categories