How Do I Change File Upload Directory From Droplet File System To Volume Block Storage

March 1, 2019 597 views
Block Storage Apache DigitalOcean Storage Ubuntu 18.04

Hi,

How Do I Change File Upload Directory From Droplet File System To Volume Block Storage?

I have a Droplet running Ubuntu 18.04 with Apache. I have a project wherein I need to upload lots of videos and hence I added a Volume of 100GB to my Droplet.

Default project video upload path is /var/www/html/public/uploads/videos and i want to change this location to /mnt/volumeblr101/uploads/videos

I have tried Symlink with the below command but symlink doesn't seems to change location of video upload
sudo ln -s /mnt/volumeblr101/uploads/videos /var/www/html/public/uploads/videos

I also tried adding alias in conf file and failed.

Also, the videos that i upload in block storage /mnt/volumeblr101/uploads/videos needs to be secured where only my project can access it and no direct requests

Can anyone please help how can I achieve this or what would I have to do?

1 Answer

Hey friend,

For the purpose of my answer, I'm going to assume the block storage device is /dev/sda. In that case I would do this:

# Unmount the current mount
umount /dev/sda

# Move the existing content aside for a moment
mv /var/www/html/public/uploads/videos /var/www/html/public/uploads/videos2

# Make a new, empty directory where the content needs to be
mkdir /var/www/html/public/uploads/videos

# Mount the drive to that new, empty folder
mount /dev/sda /var/www/html/public/uploads/videos

# Move the files from that temporary directory back into the right place
# which is now mounted as the directory in question
mv /var/www/html/public/uploads/videos2/* /var/www/html/public/uploads/videos

Then edit /etc/fstab to indicate the new mount location being /var/www/html/public/uploads/videos instead of the existing area in /mnt.

Jarland

  • Thanks a ton, Jarland.

    File upload was successful but throws a 404 error when trying to access it, any idea how to resolve this.

    Not Found
    The requested URL /public/uploads/videos/Mo-videoplayback.mp4 was not found on this server.

    Apache/2.4.29 (Ubuntu) Server at "server IP" Port 80

    I tried to modify .conf file in site-available and apache2.conf both but didn't work.

Have another answer? Share your knowledge.