Skip to content

Moving videos directory and securing files from direct access to the video source file

Daniel Neto edited this page Jul 22, 2023 · 20 revisions

This tutorial shows you how to enable Apache XSendFile to prevent your videos from being accessed by external or unauthorized users. It will also help you set up the symbolic link to allow you to move your videos to another location

Need help to configure it?

Get 1-hour support on our Services Site, we will do it for you

DIY

What we use for that:

  1. Ubuntu 16
  2. Apache XSendFile
  3. SecureVideosDirectory Plugin

What will you need

  1. Root Access to the server
  2. Admin user for YouPHPTube

Enable SecureVideosDirectory

This is necessary for secure files and configuration assistant

Install apache xsendfile

sudo apt-get install libapache2-mod-xsendfile && sudo a2enmod xsendfile

Configure your apache XSendFile

sudo nano /etc/apache2/apache2.conf

<Directory /var/www/html/YouPHPTube/>
    Options Indexes FollowSymLinks
    XSendFile on
    XSendFilePath /var/www/html/YouPHPTube/
    AllowOverride All
    Require all granted
    Order Allow,Deny
    Allow from All
</Directory>

Uncomment your .htaccess file

sudo nano /var/www/html/YouPHPTube/.htaccess

<IfModule mod_xsendfile.c>
    RewriteRule    ^videos/([A-Za-z0-9-_.]+)$ view/xsendfile.php?file=$1    [NC,L]
</IfModule>

Moving AVideo Videos Directory to Another Drive and Creating a Symbolic Link

This guide will walk you through the process of moving the AVideo videos directory to another drive and creating a symbolic link to ensure the videos are accessible from the new location. Please make sure to follow the steps carefully to avoid any potential issues.

Note: Before proceeding, ensure you have a complete backup of your AVideo installation and videos.

Steps to Move AVideo Videos Directory

Step 1: Identify the New Mounted Drive

Ensure you have mounted the new drive to your server and obtained its absolute path. For this guide, we will use the placeholder "newMountedDisk" to represent the absolute path of the newly mounted drive.

Step 2: Move Videos to the New Drive

Change to the AVideo installation directory and move the videos to the newly mounted drive using the following commands:

cd /var/www/html/AVideo/
sudo mv ./videos /newMountedDisk/videos

Note: Replace "/newMountedDisk" with the actual absolute path to the newly mounted drive.

Creating a Symbolic Link

Step 3: Create the Symbolic Link

Creating a symbolic link is a convenient way to host the videos directory on the new drive while maintaining access from the original location. Use the ln command as follows:

sudo ln -s /newMountedDisk/videos /var/www/html/AVideo/videos

Note: Replace "/newMountedDisk" with the actual absolute path to the newly mounted drive.

Now, the AVideo videos should be accessible both from the new location (e.g., "/newMountedDisk/videos") and through the symbolic link (e.g., "/var/www/html/AVideo/videos").

Modifying configuration.php When Moving AVideo Videos Directory

When moving the AVideo videos directory to another drive, you may need to modify the configuration.php file to ensure your site correctly references the video directory.

Follow these steps to make the necessary modifications:

Step 1: Locate configuration.php

Firstly, find the configuration.php file in your AVideo installation directory. It's typically located at /var/www/html/AVideo/videos/configuration.php.

Step 2: Backup configuration.php

Before you make any changes, it's a good idea to back up the original configuration.php file. You can do this by copying the file to another location:

cp /var/www/html/AVideo/videos/configuration.php /path/to/backup/directory

Replace /path/to/backup/directory with your actual backup directory.

Step 3: Edit configuration.php

Next, open the configuration.php file in a text editor. If you're working on a command line interface, you can use nano:

nano /var/www/html/AVideo/videos/configuration.php

Step 4: Modify webSiteRootURL parameter

In the configuration.php file, locate the following code:

if(!empty($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME']!=='localhost' && !filter_var($_SERVER['SERVER_NAME'], FILTER_VALIDATE_IP)) {
    // get the subdirectory, if exists
    $file = str_replace("\\", "/", __FILE__);
    $subDir = str_replace(array($_SERVER["DOCUMENT_ROOT"], 'videos/configuration.php'), array('',''), $file);
    $global['webSiteRootURL'] = "http".(!empty($_SERVER['HTTPS'])?"s":"")."://".$_SERVER['SERVER_NAME'].$subDir;
}else{
    $global['webSiteRootURL'] = 'https://mysite.com/';
}

Replace this code with a static definition for webSiteRootURL:

$global['webSiteRootURL'] = 'https://mysite.com/';

Remember to replace 'https://mysite.com/' with your actual site URL.

Step 5: Save and Exit

Save the changes and exit the text editor. If you're using nano, you can do this by pressing Ctrl + X, then Y to confirm saving changes, and finally Enter to confirm the file name.

Verification

To ensure everything is working as expected, access your AVideo application and play some videos. Verify that the videos are loading and playing correctly from the new location and through the symbolic link.

By following these steps and creating a symbolic link, you have successfully moved the AVideo videos directory to another drive, utilizing the benefits of a new storage location while preserving accessibility from the original path. This approach can help improve storage efficiency and optimize your AVideo installation.

Clone this wiki locally