Securing a tube site server comes down to a few habits: keep the operating system, PHP and your scripts updated, allow only the network ports you need, lock down admin access, set tight file permissions, back up both the database and the media files to somewhere off the server, and monitor for problems. Video sites hold large amounts of data and attract a lot of automated traffic, so getting these basics right protects both your sites and your visitors.
Keep everything updated
- Operating system: apply security updates regularly. Most Linux distributions can install security updates automatically.
- PHP, web server and database: stay on supported versions that still receive security fixes.
- ffmpeg: it processes files supplied by others, so keep it current.
- Your scripts and templates: install updates when they are released, and remove anything you no longer use.
Firewall and network
Open only the ports you need, typically 80 and 443 for the web and a port for SSH. Everything else, including the database port, should be closed to the internet. The database should listen only on localhost or a private network. Tools such as fail2ban can block addresses that repeatedly fail to log in, and a CDN or reverse proxy in front of the site can absorb some abusive traffic.
Lock down admin access
- Use SSH keys rather than passwords for server logins, and disable root login over SSH.
- Give the admin area a strong, unique password, and keep the number of admin accounts small.
- Restrict the admin area by IP address or put it behind extra HTTP authentication if you can.
- Use HTTPS everywhere so logins are never sent in plain text.
- Remove installers once installation is finished, and keep config files outside the web root or protected from direct access.
- Review who has access to hosting, DNS, domain registrar and CDN accounts, and turn on two-factor authentication where offered.
File permissions
The web server user should be able to write only where it needs to, such as upload, cache and media folders. Code files should not be writable by the web server. In general:
- Files 644 and folders 755 is a common baseline, owned by a deploy user rather than the web server user.
- Writable folders should not allow PHP to execute. Configure the web server so files in media and upload folders are served as static files only.
- Keep originals and temporary uploads outside the public web root.
- Never set anything to 777.
If you allow member uploads, treat every uploaded file as untrusted. Check file types by content, not by extension, and only ever pass uploads to ffmpeg, never execute them. See moderating user uploads for the content side.
Backups of database and media
Tube sites have two very different kinds of data:
| Data | Size | Suggested approach |
|---|---|---|
| Database | Small | Daily or more frequent dumps, several copies kept |
| Config and custom templates | Tiny | Back up with every change, or keep in version control |
| Original videos | Large | Incremental backups to separate storage |
| Encoded files and thumbnails | Large | Back up, or rely on being able to re-encode from originals |
Store backups off the server, ideally with a different provider, so one account problem cannot take out both. Use incremental tools such as rsync or a backup program that only copies changed files, since media folders are too large to copy in full every night. Most importantly, test a restore every few months. A backup that has never been restored is only a hope.
Monitoring
- Uptime: an external check that alerts you when a site stops responding.
- Disk space: video fills disks quickly, and a full disk breaks encoding, uploads and the database. Alert well before it is full.
- Logs: watch web server and PHP error logs, and look for repeated failed logins.
- Background jobs: check that cron and encoding workers are running and that the queue is not growing.
- File changes: unexpected new PHP files in writable folders are a common sign of compromise.
Plan what you would do if a server were compromised: take it offline, rotate passwords and keys, restore from a known good backup and patch the cause. For choosing a suitable server in the first place, see tube site hosting requirements.
How Tube Site Script helps
Tube Site Script is plain, unencoded PHP with no framework, so you or your developer can see exactly what runs on your server. Originals, cache and the FTP drop folder live in a storage/ folder that is not web-served, and the document root points at public/. The installer locks itself after use, and you can switch the in-browser template editor off in Network settings or in config.php if you prefer no code editing through the admin. Signed, expiring MP4 links via nginx secure_link help stop hotlinking of your videos.
Updating means uploading the new files while keeping config.php, storage/, public/media/ and your own templates, which are also the key folders to back up along with the database. See the Tube Site Script features and pricing.
Frequently asked questions
How often should I back up a tube site?
Back up the database at least daily and media incrementally. Keep copies off the server and test a restore every few months.
Which ports should be open on a tube site server?
Usually only 80 and 443 for the web and one port for SSH. Keep the database port closed to the internet.
What is the most common sign of a hacked tube site?
Unexpected PHP files in writable folders such as uploads or cache, often alongside strange redirects or spam pages.
