Magento/Zend not allowing symbolic links
Asked Answered
N

5

6

Anyone know why Magento won't allow symbolic links for template .phtml files that are outside the app/design folder?

If I do a symlink within that folder, it works fine, but if it's linked outside that, it doesn't work. So it seems like it's some permissions/security thing, but I can't find any info anywhere.

Possibly a Zend setting? http://zend-framework-community.634137.n4.nabble.com/Zend-Tool-not-working-with-symbolic-links-in-include-path-td662569.html

Anyone?

WORKAROUND: Thanks to Alan's suggestion below I found a workaround - as I'll only be using this myself for local development I'm happy enough. In case this helps anyone else, I'm gonna add it here. So I'm inserting the following in core/Mage/Core/Block/Template.php, directly after the line Varien_Profiler::start($fileName);

    $storeId = Mage::app()->getStore()->getId();
    $theme = Mage::getStoreConfig('design/package/name', $storeId);
    Mage::Log($this->_viewDir.DS.$fileName); 
    $includes = $this->_viewDir.DS.$fileName; 
    if(strpos($includes, 'frontend/'.$theme )) { 
         include $this->_viewDir.DS.$fileName;
        };

Using the IF statement here stops any base templates being doubled, and only allows your custom theme templates through.

Naji answered 17/12, 2010 at 18:29 Comment(5)
I'm not sure if this is helpful or not, but I've been able to create symbolic links for phtml files to files outside the magento structure without any issues. So it is possible. I would say it would have to be a permission of some sort. If it's any help I make my link form inside the magento template folder.. ex: ln -s header.phtml ~/www/somefolder/somewhere/somefile.phpBilliton
Tried this but no joy either. I should probably add that I'm using this locally, with MAMP on a Mac. What are you using?Naji
Gotcha.. Yeah, I'm using it on a debian linux server. That could make a difference I imagineBilliton
You've got a hacked core system. The line "if(strpos($includes, 'frontend/'.$theme )) { " isn't a part of the Template.php core code. I imagine it, and other posible hacks, are what's preventing your system from running.Northerly
It's not part of the core code, that's what I've added now to get the symlinks working. Although of course the edited file should be added in the local directory so it justs overrides the core file. And yeah it is very hacky, but it's working now, and it's purely for use on my development machine, so I'm running with it!Naji
D
18

As of Magento 1.5.1.0 (maybe 1.5.x?) there is an option at System > Configuration > Developer > Template Settings > Allow Symlinks that you can enable.

No need for dirty hacks/workarounds anymore. :-)

Down answered 1/9, 2011 at 15:25 Comment(2)
You can do it through the SQL query too: UPDATE core_config_data SET value = '1' WHERE path = 'dev/template/allow_symlink';Cynarra
There is ALWAYS a configuration option for everything in Magento :)Squama
M
5

This was caused by a change in 1.4.2 where Magento no longer allows symlinked folders. If you look in Template.php

        $includeFilePath = realpath($this->_viewDir . DS . $fileName);
        if (strpos($includeFilePath, realpath($this->_viewDir)) === 0) {
            include $includeFilePath;
        } else {
            Mage::log('Not valid template file:'.$fileName, Zend_Log::CRIT, null, null, true);

        }

you see that it won't load if the template is not under the "viewDir".

Multinuclear answered 1/1, 2011 at 19:34 Comment(1)
Cool. If you comment out that if statement, just leaving in the include $includeFilePath; then you can use symlinks ok.Naji
S
3

found another nice little solution which works for me:

sshfs 192.168.1.12:/srv/www/vhosts/dev.****.*****.de/media/catalog/product/ catalog/product/ -o allow_other

this mounts the remote file system via sshfs, allow_other option is necesarry to make the files mounted from the remote box without the remote box file rights:

This option will allow you to use -o allow_other in your SSHFS command which will allow your non-root user access to the specific resource you're mounting.

hope this helps to anyone of you

Screening answered 5/7, 2011 at 12:35 Comment(0)
L
2

I am also using symlinks to my custom code and I managed to overcome this issue by using mount --bind instead of creating symlinks, e.g. custom theme directory: /home/user/workspace/magento/app/design/frontend/default/mytheme

cd <magento dir>/app/design/frontend/default
mkdir mytheme
sudo mount --bind /home/user/workspace/magento/app/design/frontend/default/mytheme mytheme

This method will not work on OSX.

Lullaby answered 13/1, 2011 at 16:49 Comment(0)
N
0

Add some logging code to the base template block

#File: app/code/core/Mage/Core/Block/Template.php
public function fetchView($fileName)
{
    ...
    Mage::Log($this->_viewDir.DS.$fileName); 
    var_dump($this->_viewDir.DS.$fileName);
    include $this->_viewDir.DS.$fileName;
    ...
}

Ultimately, rendering a template block is a call to include with a system path. Once you get the path Magento is constructing to your template, create a one line PHP file

<?php
include('/path/that/was/logged/foo.phtml');

And attempt to load the template. This should allow you to isolate the reason any particular call to include is failing. My immediate guess is a PHP safe mode setting, but it's been a long time since I had to fight shared hosting restrictions.

Good luck!

Northerly answered 17/12, 2010 at 18:55 Comment(4)
Hmmmmmm, when I add the code to the base template block, my page loads no problem, but with all the log info being shown. So why can it now load the symlinked file?Naji
Well, for some reason, adding Mage::Log($this->_viewDir.DS.$fileName); include $this->_viewDir.DS.$fileName; is making it work - if was doubling every file that wasn't symlinked, but once they are all symlinked it's showing fine now! Guess this'll do.Naji
Added my workaround to my original question above, incase it's of use to others...Naji
The line include $this->_viewDir.DS.$fileName; is part of the core block template. You weren't intended to add it. Based on what you've said here and above, it seems like you have a hacked core system.Northerly

© 2022 - 2024 — McMap. All rights reserved.