Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an application in 2 environments on an Apache server. One is 'dev', and it's a subdomain of the production environment. This is a content managed application, and users upload media. I'd like the ability for the 'dev' site content in certain areas to be updated with the same media.

Is there a way to get my /dev/uploads directory to utilize media from the /prod/uploads directory (recursively) without having to copy content? (want to keep disk space down).

If my dev application calls http://dev.mysite.com/uploads/img.jpg the media should actually be pulled from http://mysite.com/uploads.img.jpg. I'm also using rewrite in the .htaccess file already, as this is a ZF application.

share|improve this question
    
So just to be clear, you'd like to use the content from production just in cases where that content does not exist in dev, right? –  Shane Madden Sep 23 '13 at 0:44
    
You got it. Most content is served from the database. Only media or uploaded files are stored on the fileserver. –  Brian Vanderbusch Sep 23 '13 at 2:32

2 Answers 2

up vote 3 down vote accepted

1) Symlink the parts of the development DocumentRoot to the production document root that you want dev links to serve.

ln -s /prod/uploads/img.jpg /dev/uploads/img.jpg

Make sure the Dev Directory in httpd.conf is allowed to follow symlinks via the FollowSymLinks config option.

2) Rewrite dev URLs that match your requirements to be served from prod. The redirect for your example would be like so;

RewriteCond %{HTTP_HOST}   dev.mysite\.com [NC]
RewriteCond %{REQUEST_URI} /uploads/img.jpg
RewriteRule http://mysite.com/uploads/img.jpg

P.S. This is more a psuedo-code example than something you would want to implement unless it's just one asset you care about.

3) Use the Alias config to map one directory to another.

Alias /dev/uploads /prod/uploads

This would serve any incoming paths that match http://dev.mysite/uploads from /prod/uploads. Very dependent on the vagaries of your particular httpd.conf configuration.

share|improve this answer
    
+1 for file system links. Don't make apache think about those if they are on the same server. Just setup symbolic links and let the file system handle it. Alternatively... You could consider looking into mounting /prod/uploads to /dev/uploads as read only (to actually protect your production data from rampaging dev code). If these are separate servers, consider an nfs export from prod to dev as read only for above reasons. –  lVlint67 Sep 23 '13 at 8:12

You'll want to use mod_rewrite to check for file existence in dev and send the request there if it exists - and to prod if not. Something like..

RewriteCond /path/to/dev/docroot/${REQUEST_URI} -f
# Exists in dev, leave the request alone
RewriteRule ^(.*)$ -
# Doesn't exist, send to prod
RewriteRule ^(.*)$ /path/to/prod/docroot/$1

Note that this will need to be configured in the dev <VirtualHost> context to function, since the target is a filesystem path outside of the dev document root.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.