-
Notifications
You must be signed in to change notification settings - Fork 980
Moving videos directory and securing files from direct access to the video source file
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
Get 1-hour support on our Services Site, we will do it for you
- Ubuntu 16
- Apache XSendFile
- SecureVideosDirectory Plugin
- Root Access to the server
- Admin user for YouPHPTube
This is necessary for secure files and configuration assistant
sudo apt-get install libapache2-mod-xsendfile && sudo a2enmod 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>
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>
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.
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.
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").
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:
Firstly, find the configuration.php
file in your AVideo installation directory. It's typically located at /var/www/html/AVideo/videos/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.
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
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.
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.
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.