Forums

[resolved] How to sync uploads folder between servers (5 posts)

  1. x3110
    Member
    Posted 4 years ago #

    I have wordpress installed and load balanced.

    Is there anyway to synced the wp-content/uploads folder between server or better yet sync it to a dedicated static content server and still be able to use the native upload functionality?

    I would prefer to have my uploads folder reside on a dedicated box where it can be offloaded to a CDN in the near future.

    At the moment, i'm not using the built-in upload.

  2. WishyKohaku
    Member
    Posted 4 years ago #

    *Bump*

    Could anyone please try to answer the question. It would be a great help to me!
    Thank you in advance to any suggestions!

  3. Otto
    Tech Ninja
    Posted 4 years ago #

    Okay. The answer to the question is no.

    At least, it cannot be done without extreme modification of the uploading functionality. So much that it would be simpler to replace it entirely.

    Of course, you can always do an end run around the whole process. Simply make the uploads folder a symlink to another folder on another machine entirely, say, via an NFS mount or some such thing.

  4. crpearson
    Member
    Posted 4 years ago #

    Are the two servers UNIX machines? If so, I really like the rsync command for doing this. It's a pretty common package on most UNIX systems these days.

    To do this, create a script called something like syncit.sh
    #######snip######
    #!/bin/sh
    # syncit.sh script on server.foo.com

    /usr/bin/rsync --recursive --perms --update --links --delete --owner --group --times --progress /path/to/source/directory/* server.bar.com:/path/to/destination directory/`
    ######/snip#####

    The machine we are on is called server.foo.com, while the machine we want to send the files to is called server.bar.com

    It uses ssh to make the connection, so you have to have ssh connectivity between them. Also, it will ask you for your password, so there are a few more steps if you want to have this happen all by itself. If this seems like the road you want to go down, I can help you with the other steps.

  5. x3110
    Member
    Posted 4 years ago #

    Found a solution.

    I've set it up so that that wp-admin is always loaded in to SERVER1. Once a user has uploaded files using WordPress into SERVER1, I rsync wp-upload to SERVER2.

    The key was making sure that wp-admin is accessible on 1 server that is being load balanced.

    Once we have a need to use a CDN to serve wp-upload items, I would only have to modify the $siteurl to point to the CDN url for the upload's base url (wp_upload_dir function).

    Thanks for the other suggestions.

Topic Closed

This topic has been closed to new replies.

About this Topic