I have some troubles running artisan commands in my Laravel project.
I had to change the storage directory location in my project and now, when I try to run any artisan command, it output this error :
{"error":{"type":"ErrorException","message":"file_put_contents(\/meta\/services.json):
failed to open stream: No such file or directory"
I changed the storage path in the bootstrap/path.php file and the application works just fine. (I can see the view, logs, sessions generated in my custom storage directory)
But artisan cannot find the storage/meta/services.json file.
I checked and the file exists in my storage directory.
If I create a storage/meta directory in the /appfolder it's working, but I need to use a custom storage directory.
Does artisan need a special configuration file? Am I missing something?
Thanks.
This is what contains my path file:
'app' => 'C:/wamp/www/myproject/app/',
'public' => 'C:/wamp/www/myproject/public',
'base' => __DIR__.'/..',
'storage' => 'C:/wamp/www/storage',
Are you using laravels storage_path() function to determine the path?
Before creating the file, maybe do:
$path = storage_path() . '/meta';
if (!File::exists($path)) {
File::makeDirectory($path, $mode = 0755, true, true);
}
Related
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')}}">
I've been trying to deploy my Laravel 6 App to the standard environment of Google App Engine the whole day, but seems like I'm just stuck at how to make cache and some "local" files to work.
This is the error I get when I try to load any page:
(1/1) InvalidArgumentException
Please provide a valid cache path.
in Compiler.php line 36
at Compiler->__construct(object(Filesystem), false)
in ViewServiceProvider.php line 92
at ViewServiceProvider->Illuminate\View\{closure}(object(Application), array())
in Container.php line 799
at Container->build(object(Closure))
in Container.php line 681
at Container->resolve('blade.compiler', array(), true)
in Application.php line 785
(...)
I followed every tip at this question, this tutorial and this issue, but anything seemed to help me.
As CACHE_DRIVER, for convenience, I'm trying to just use file, instead of database or any other else. So, my app.yaml, have the additional env_variables :
CACHE_DRIVER: file
SESSION_DRIVER: cookie
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
I know that the /tmp folder is the only writable folder for the App Engine Standard Environment. With that in mind, I put the above at app.yaml, and even tried renaming /storage folder to /tmp.
I've added the following line to my bootstrap/app.php file:
$app->useStoragePath(env('APP_STORAGE', base_path() . '/tmp'));
At my composer packages, I made sure that it doesn't have facade/ignition. Also, as I can't run any command after deploy my app to Google App Engine, at composer.json I have:
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
],
"post-install-cmd": [
"composer dump-autoload",
"php artisan config:clear",
"php artisan view:clear",
"php artisan cache:clear"
]
I also tried to put at post-install-cmd php artisan storage:link, while using $app->useStoragePath(env('APP_STORAGE', base_path() . '/storage')); and the /storage folder as storage itself, but nothing worked.
I have the whole folder tree for caching at my /temp (or /storage, if this is the right way) folder:
/tmp
/framework
/cache
/data
/sessions
/testing
/views
/logs
/medialibrary
/temp
Also, besides the views not rendering, I noticed that when trying to load the favicon.ico, located at /public folder, it returns an 500 error. I am new to AppEngine, but even reading everything I can find I've been struggling to make it work. I really appreciate any help.
I figured out I had some config files published at /config, and besides changing /bootstrap/app.php, some of them had their own path to /storage folder. So, my solution was just gave up on using files cache, and for the views cache, and some other packages I had, use the path /tmp, at their respective config files. Also, I removed all cache cleaning artisan commands from composer, as I wasn't sending any cache files to deploy.
Also, I needed to make some changes in order to be able to access /public files, like some local css and js. For this, I followed these docs.
I was struggling with the same problem today and the solution was I changed the 'compiled' value in config/view.php to a root folder:
Go to root directory.
mkdir compiled_views
Change 'compiled' value to 'compiled' => realpath(base_path('compiled_views/')),
I solved it by explicitly adding the APP_STORAGE env in config/view.php:
'compiled' => realpath(env('APP_STORAGE', realpath(storage_path('framework/views')))),
(which surprises because I do have $app->useStoragePath(env('APP_STORAGE', base_path() . '/storage')); added to app.php - but it seems that it didn't yet(?) override storage_path )
I hosted laravel application on shared hosting server.
on server there are 2 folders :
1) laravelapp -> contains (app,config,database,vendor...etc folders)
2) public_html -> contains (css,js,images,storage folders)
I use below code to upload image :
if($request->hasFile('file')){
$filenameWithExt=$request->file('file')->getClientOriginalName();
$filename=pathinfo($filenameWithExt,PATHINFO_FILENAME);
$extension=$request->file('file')->getClientOriginalExtension();
$fileNameToStore=str_slug($filename,'_').'_'.time().'.'.$extension;
request()->file->move(public_path('storage/profile'), $fileNameToStore);
$image="/storage/profile/".$fileNameToStore;
}
It is successfully upload file to laravelapp/public/storage/profile folder
I have created symlink to laravelapp/public/storage with public_html/storage
in database : imagepath is saved as /storage/profile/user1.png
in blade template i use : <img src="{{$img}}" />
but imageurl :
www.mydomain.com/storage/profile/user1.png redirect to 404 page and image not displaying .
anyone please help me to solve problem.
This worked for me on a shared hosting server:
edit your config/filesystems.php and modify the public part like this
'public' => [
'driver' => 'local',
'root' => storage_path(),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
]
Notice that the storage_path() does not take any argument. Now remove storage folder from your public directory if already exists, then do:
php artisan storage:link
So, as per our discussion in comments and according to Laravel 5.5 docs, your publicly accessible files should be put in directory storage/app/public To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public.
ln -s /path/to/laravel/storage/app/public /path/to/laravel/public/storage
Now you can create in your view an URL to the files using the asset helper:
echo asset('storage/file.txt');
Hope this will helps you and other users!
1) To store file in laravelapp/storage/app/public/cover/ folder
use Illuminate\Support\Facades\Storage;
$path=$request->file('cover_image')->storeAs('public/cover_images',$fileNameToStore);
2) To store file in laravelapp/public/cover/ folder
$path=request()->cover_image->move(public_path('storage/profile'), $fileNameToStore);
in shared hosting server there are 2 folders :
laravelapp and public_html
As im using 2nd way to upload image , I have solved this issue by creating symlink from laravelapp/public/storage folder to public_html/
ln -s /home/username/laravelapp/public/storage /home/username/public_html/
is posible that the symlink of your storage/public folder was wrong, you can review if this is pointing to the correct folder Use the ls -l command to check whether a given file is a symbolic link, and to find the file or directory that symbolic link point to.
ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Apr 16 2020 /usr/bin/python -> python2.7
The first character ālā, indicates that the file is a symlink. The ā->ā symbol shows the file the symlink points to.
The rm command removes given files and directories. To delete a symlink, invoke the rm command followed by the symbolic link name as an argument:
rm symlink_name
create a new symlink to the storage public folder
php artisan storage:link
In cPanel or any live server make sure your storage folder and subfolders have the correct permission right. It should be 644, 755 or 777
I have an image within the public/badges directory called 1.png - I am trying to use the Storage library in laravel but keep getting the following error even though the file does exist at that location:
// Error
FileNotFoundException in Filesystem.php line 381:
File not found at path: Users/gk/Sites/mysite/public/badges/1.png
// Code
$filePath = 'badges/1.png';
$path = public_path()."/".$filePath
Storage::disk('local')->get($path);
dd($contents);
Form Laravel 5.2 documentation:
When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory.
So You are looking for file in: storage/app/Users/gk/Sites/mysite/public/badges/1.png
Error is quite confusing.
[Update]
Add to config/filesystems.php
'disks' => [
//...
'local_public' => [
'driver' => 'local',
'root' => public_path(),
],
//...
],
then
$filePath = 'badges/1.png';
$content = Storage::disk('local_public')->get($filePath);
dd($content);
I had the same problem in Laravel 5.7, this fix my problem:
php artisan storage:link
The error I am getting is
Warning: Phalcon\Mvc\View\Engine\Volt\Compiler::compileFile(../app/views/index/index.phtml.php): failed to open stream: Permission denied in /Users/mattstephens/Sites/magpie/public/index.php on line 26 Phalcon Exception: Volt directory can't be written
I have declared the volt engine usage in my bootstrap like so
$view->registerEngines(array(
'.phtml' => 'Phalcon\Mvc\View\Engine\Volt'
));
The mention of line 26 in my code points to the application handle function shown below
echo $application->handle()->getContent();
Is this a permissions related thing or due to a missing directory?
Unless you specify a different folder for Volt to compile its templates, the folder where the view file is located will be used to create the relevant compiled file.
You can change this behavior by setting the proper option when you register your service as such:
use \Phalcon\Mvc\View as PhView;
use \Phalcon\Mvc\View\Engine\Volt as PhVolt;
...
public function initView($options = array())
{
$config = $this->di['config'];
$di = $this->di;
$this->di['volt'] = function ($view, $di) use ($config) {
$volt = new PhVolt($view, $di);
$volt->setOptions(
array(
'compiledPath' => $config->app_volt->path,
'compiledExtension' => $config->app_volt->extension,
'compiledSeparator' => $config->app_volt->separator,
'stat' => (bool) $config->app_volt->stat,
)
);
return $volt;
};
/**
* Setup the view service
*/
$this->di['view'] = function () use ($config, $di) {
$view = new PhView();
$view->setViewsDir($config->app_path->views);
$view->registerEngines(array('.volt' => 'volt'));
return $view;
};
}
The $config will store all the information you need. By using the compiledPath you instruct Volt to compile the templates there and then serve them to the front end. That folder needs to be writeable for the user that runs your web server www-data or other and can be outside your public folder.
The file structure I usually use is:
app
\controllers
\models
\views
public
\js
\css
\img
var
\volt
\logs
\config
\cache
Change volt file permission (Inside app/cache) to 777 .Its working fine
Contrary to several of the other answers here, don't just willy-nilly set permissions to 0777 and pretend everything's okay, that's completely ridiculous. Your server needs to write to the volt folder inside your cache directory.
You might need to create the folder first.
sudo mkdir cache, and sudo mkdir cache/volt. Then chown that folder with whatever is the username that your server runs.
NOTE: Depending on your configuration, the cache folder might be located at the project root and not inside app.
For example, if your server launches under the permissions of user named 'www-data' (which is most common), after creating the proper folder structure, the following command will fix your issue:
sudo chown www-data:www-data -R cache
I have just made "app/cache" folder with 777 permitions) It works))
change the "app/cache" folder permission to 777.
in my mac i did like this.
navigate inside the app folder of our phalcon framework
[chmod ugo=rwx cache]
make sure the cache folder permission is 777 by typing [ls -l].
Changing the app/cache and app/cache/volt with these commands worked for my project structure.
chmod -R a+w app/cache
chmod -R a+w app/cache/volt
Just go to /project_name/store/app/config/config.php and change cacheDir from 'cacheDir' => __DIR__ . '/../../app/cache/' to 'cacheDir' => __DIR__ . '/../../cache/'.
Also, change its write permission to 777.
You should change ownership of your project directory with chown command,
chown -R your_system_user:webserver_user yourproject/
Check if the baseUri in the config.php is same as the installation directory
if the issue persist, tail nginx logs tail -f /var/log/nginx/*.log.
Also try use sudo setenforce 0. This worked for me.