Matt Stephens
Matt Stephens

Reputation: 922

Volt directory can't be written

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?

Upvotes: 6

Views: 20789

Answers (9)

Kamania
Kamania

Reputation: 107

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.

Upvotes: 0

pras1101
pras1101

Reputation: 41

You should change ownership of your project directory with chown command,

chown -R your_system_user:webserver_user yourproject/

Upvotes: 1

amit.kewal
amit.kewal

Reputation: 11

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.

Upvotes: 0

AaronDanielson
AaronDanielson

Reputation: 2470

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

Upvotes: 6

WCO
WCO

Reputation: 480

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

Upvotes: 0

Santhosh Kumar
Santhosh Kumar

Reputation: 59

Change volt file permission (Inside app/cache) to 777 .Its working fine

Upvotes: 6

Mansoor Cool
Mansoor Cool

Reputation: 51

change the "app/cache" folder permission to 777. in my mac i did like this.

  1. navigate inside the app folder of our phalcon framework
  2. [chmod ugo=rwx cache]
  3. make sure the cache folder permission is 777 by typing [ls -l].

Upvotes: 2

Denys Klymenko
Denys Klymenko

Reputation: 423

I have just made "app/cache" folder with 777 permitions) It works))

Upvotes: 2

Nikolaos Dimopoulos
Nikolaos Dimopoulos

Reputation: 11485

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

Upvotes: 7

Related Questions