Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento/Zend not allowing symbolic links

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.

like image 841
Marlon Creative Avatar asked Dec 17 '10 18:12

Marlon Creative


4 Answers

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. :-)

like image 69
Hendy Irawan Avatar answered Nov 04 '22 09:11

Hendy Irawan


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".

like image 36
John K Avatar answered Nov 04 '22 08:11

John K


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

like image 22
Herrmann Hinz Avatar answered Nov 04 '22 09:11

Herrmann Hinz


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.

like image 37
t10u Avatar answered Nov 04 '22 07:11

t10u