When developing web shops, we do not want to copy all media assets to the local development machine.
Still it would be nice, to get a real view on the system, i.e. load the media images on demand from the production server.
How can this be achieved?
When developing web shops, we do not want to copy all media assets to the local development machine.
Still it would be nice, to get a real view on the system, i.e. load the media images on demand from the production server.
How can this be achieved?
For Magento 2 there is a open source module which does exactly this.
If you are on Linux, a more generic solution seems to be possible, using http and union fuse file systems. This could work on different Shop- and CMS systems such as Shopware, TYPO3 and so on.
The following example was tested on Ubuntu 20.04
But: the solution is not well tested on production installations, so please be careful.
First install the required packages
apt install httpdirfs unionfs-fuse
We assume, the production server uses Apache. In the next step we enable directory listing, but only for a certain - secret - user agent. Make sure to replace "ThisIsSecret" by your secret.
<If "%{HTTP_USER_AGENT} == 'ThisIsSecret'">
Options +Indexes +MultiViews
AllowOverride None
</If>
<Else>
Options -Indexes -MultiViews +FollowSymLinks
AllowOverride All
</Else>
Go to your local development directory and move the current media directory:
cd /home/me/projects/example.com/public
mv media media_local
Now httpdirfs is used to mount the server's directory via HTTP. httpdirfs parses the directory listing and lets you see the remote files. Editing is not possible.
mkdir media_remote
httpdirfs --cache --user-agent ThisIsSecret https://example.com/media/ media_remote
Next, we use unionfs with the CopyOnWrite (cow) option to be able to still write to the media folder.
mkdir media
unionfs-fuse -o cow media_local=RW:media_remote=RO media