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.
Related
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 use on my application some fonctions about files. creation of files, copy/create from a directory to another, update. On my localhost, all is okay, that's work.
The main purpose is to have a manager for translation on the website.
rights of parent directories : 755
I have error :
1) if files doesn't exist the error is
copy(/blabla/path.php): failed to open stream: Permission denied
2) if I create files before (touch + chown on usr:usr) with basic rights (644) or with updated rights (775) :
file_put_contents(/blabla/path.php) : failed to open stream: Permission denied
On my localhost :
right of directories : 755
right of files : 644
I also tried to clean php cache (php artisan cache:clear)
edit :
I use 2 functions :
copy (who copy default translate file in the directory of second langage) and file_put_contents (who edit file)
public function replaceSlugs(Array $slugs,$filename, $lang)
{
$file=$this->path2File($filename,$lang);
if(!file_exists($file)){$this->duplicateFile($lang,$filename);}
$translate="<?php return ".var_export($slugs,true).";";
return file_put_contents ( $file , $translate, LOCK_EX );
}
private function duplicateFile($lang,$filename)
{
copy($this->path2File($filename),$this->path2File($filename,$lang));
}
private function path2File($filename,$lang="en")
{
return resource_path('lang/'.$lang.'/'.$filename.'.php');
}
Solution is Risky but it will do the trick
Give your folders full permission & clear Cache
Something like this.
sudo chmod -R 777 public/lang/en
if you don't give 777 permission you will also stuck while unit Test.
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'm using Laravel , The following code works on my local machine (Mac)
$Avatarpath = base_path()."/uploads/image/avatar.png"
$filePath = base_path()."/uploads/image/myimage.png" //which gives "/var/www/myproject/uploads/image/myimage.png"
return Response::download(file_exists($filepath) ? $filepath :$Avatarpath);
but when I deploy the same code on linux (Centos) server , it throws the following Exception
throw new FileException('File must be readable.');
Additional info: "uploads" folder has drwxr-xr-x (775) permissions
Thank you your interest to fix this issue.
Important is that the permissions for the file itself are correct too!
Usually in this cases you should run chmod with the recursive flag (-R):
chmod -R 775 uploads/
This Exception is thrown if function http://php.net/manual/en/splfileinfo.isreadable.php is returning false.
Your file permissions must be denying the file read.
I downloaded YiiShop extension from here
Then I followed the instruction:
1.Make a folder in my webapp named modules, then extracted the extension there
2.Do some configuration in webapp/protected/config/main.php
'modules' => array(
...
'shop' => array('debug' => 'true'),
...
),
3.I tried to run it as instructed, webapp/shop/install, but it turns error:
Alias "shop.ShopModule" is invalid. Make sure it points to an existing PHP file and the file is readable.
Any ideas how to fix this?
Thanks.
may be a permission error..
What operating system you are using?
If linux then try this command in terminal -
sudo chmod 777 -R /path_to_root_dir/project_name
warning : do not use this command in your file system!