Local Radio Stream

Personal-use only radio streaming application

Project Overview

This is a personal-use-only radio streaming application combining a PHP/MySQL backend with a JavaScript/HTML5 frontend.

Streaming Features

  • Stream MP3 files from local server
  • Upload music with metadata
  • Manage dynamic playlists

Audio Features

  • Real-time audio visualization
  • Advanced playback controls
  • Shuffle and repeat modes

License Information (MIT)

This software is strictly for personal use. Any attempt to deploy it in public production environments will result in immediate legal action under international copyright and intellectual property laws.

Attribution Required Non-Commercial No Warranty

Server Requirements

Software Requirements

  • PHP 8.0+ with mysqli extension
  • MySQL 5.6+ database server
  • Apache/Nginx web server

Directory Permissions

  • 777 permissions on /uploads directory
  • Minimum 1GB storage space
  • Support for large file uploads (64MB+)

Database Configuration

Database Creation

-- Create database
CREATE DATABASE loco_music;
USE loco_music;

Songs Table Schema

CREATE TABLE songs (
  id INT AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(255) NOT NULL,
  file VARCHAR(255) NOT NULL,
  cover VARCHAR(255),
  artist VARCHAR(255) NOT NULL,
  lyrics TEXT,
  uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

This schema supports all core features including metadata storage for songs, cover art references, and lyrics. The uploaded_at timestamp enables chronological playlist sorting.

File Structure

/project-root
├── index.php           # All-in-one PHP/HTML/JS application
├── .htaccess           # Apache configuration
├── /uploads            # Media storage (777 permissions)
│   ├── song1.mp3       # MP3 files
│   └── cover1.jpg      # Album art
└── README.md           # Documentation

index.php

Main application file containing all backend logic and frontend interface.

.htaccess

Apache server configuration for routing, security and performance.

/uploads

Directory for storing uploaded media files (requires 777 permissions).

PHP Configuration

Database Credentials

$host = "localhost"; // Database host
$db   = "loco_music"; // Database name
$user = "root";       // Database user
$pass = "";           // Database password

Security Warning

Credentials are hardcoded in the PHP script. For production-like environments, consider using environment variables or a configuration file outside the web root.

Directory Permissions

Linux/Mac Commands

mkdir -p uploads/
chmod 777 uploads/

Permission Requirements

The uploads directory requires full read/write/execute permissions (777) to allow the web server to create directories, write files, and serve uploaded content.

.htaccess File Explained

1

URL Rewriting

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

Enables clean URLs by routing all requests to index.php unless the request is for an existing file or directory.

2

Security Settings

# Disable directory browsing
Options -Indexes

# Disallow remote access to sensitive files
<FilesMatch "\.(env|ini|log|sql|bak|sh)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

Prevents directory listing and blocks access to configuration/backup files.

3

PHP Settings

<IfModule mod_php7.c>
    php_value upload_max_filesize 64M
    php_value post_max_size 64M
    php_value max_execution_time 300
    php_value max_input_time 300
</IfModule>

Configures PHP to allow large file uploads and increases execution time for upload processing.

4

MIME Types

<IfModule mod_mime.c>
    AddType audio/mpeg .mp3
    AddType image/jpeg .jpg .jpeg
    AddType image/png .png
    AddType image/gif .gif
</IfModule>

Ensures correct content-type headers are sent for media files.

5

Performance Optimization

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript application/javascript application/json
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType audio/mpeg "access plus 1 week"
    ExpiresByType image/jpg "access plus 1 week"
    ExpiresByType image/jpeg "access plus 1 week"
    ExpiresByType image/png "access plus 1 week"
    ExpiresByType image/gif "access plus 1 week"
    ExpiresByType text/css "access plus 1 day"
    ExpiresByType application/javascript "access plus 1 day"
</IfModule>

Enables GZIP compression and sets caching headers for static assets to improve performance.

Core Features

Music Streaming System

  • MP3-only support with browser-native <audio> element
  • Progressive loading with time/duration display
  • Bitrate detection (default: 128kbps)

Playlist Management

  • Reverse chronological display
  • Shuffle functionality using Fisher-Yates algorithm
  • Repeat mode with single-track loop

Upload System

  • MP3 validation by file extension
  • Cover art support (JPG/PNG/GIF)
  • Lyrics storage in database

Audio Visualization

  • Web Audio API integration
  • 50-bar frequency analyzer
  • Waveform-style animation

Security Considerations

Database Credential Exposure

Credentials are hardcoded in PHP script. If source code is exposed, database could be compromised.

$host = "localhost"; $user = "root"; $pass = "";

Insecure File Uploads

Only checks file extensions (.mp3, .jpg, etc.) without content-type verification or file sanitization.

SQL Injection Risk

Prepared statements used for inserts but not for all queries. No input sanitization for search/filter functions.

CSRF Vulnerability

Upload form lacks CSRF token protection. Attackers can forge requests to upload malicious files.

XSS Vulnerability

User-provided lyrics directly displayed without sanitization. Potential for script injection.

Recommendations

  • Move credentials to environment variables
  • Implement file content validation
  • Use prepared statements for all queries
  • Add CSRF protection to forms
  • Sanitize all user-provided content