================================================================================ RADIO STREAM RECORDING SYSTEM - INSTALLATION GUIDE ================================================================================ QUICK START CHECKLIST □ Upload all files to /home/radio/ □ Create database and import radio_streams.sql □ Create db.php with your database credentials □ Install Composer dependencies (php-ffmpeg) □ Verify FFMpeg is installed □ Set file permissions □ Update PHP CLI path if needed □ Access stream-manager.php to test □ Set up cron job for automation ================================================================================ STEP 1: UPLOAD FILES ================================================================================ Upload these files to: /home/radio/ ✓ config.php ✓ e.php ✓ logging_utility.php ✓ radio_streams.sql ✓ record_stream.php ✓ stream-manager.php ✓ streams_db_tool.php ✗ db.php (CREATE THIS - see Step 3) Note: The 'streams/' directory will be created automatically. ================================================================================ STEP 2: CREATE DATABASE ================================================================================ 1. Log into MySQL: mysql -u root -p 2. Run these commands: CREATE DATABASE radio_streams_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; USE radio_streams_db; SOURCE /home/radio/radio_streams.sql; EXIT; 3. Verify: mysql -u root -p -e "USE radio_streams_db; SELECT * FROM radio_streams;" ================================================================================ STEP 3: CREATE DATABASE CONNECTION FILE (CRITICAL!) ================================================================================ Create: /home/radio/db.php connect_error) { die("Connection failed: " . $conn->connect_error); } $conn->set_charset("utf8mb4"); ?> IMPORTANT SECURITY NOTES: - Replace YOUR_DB_USERNAME and YOUR_DB_PASSWORD with actual values - NEVER commit this file to version control - Set strict permissions: chmod 600 db.php - Use a strong, unique password ================================================================================ STEP 4: INSTALL COMPOSER DEPENDENCIES ================================================================================ Navigate to the directory: cd /home/radio/ Install php-ffmpeg: composer require php-ffmpeg/php-ffmpeg If Composer is not installed: curl -sS https://getcomposer.org/installer | php php composer.phar require php-ffmpeg/php-ffmpeg ================================================================================ STEP 5: VERIFY FFMPEG INSTALLATION ================================================================================ Check if FFMpeg is installed: which ffmpeg which ffprobe Expected output: /usr/bin/ffmpeg /usr/bin/ffprobe If paths are different, edit record_stream.php: $ffmpegBinary = '/your/path/to/ffmpeg'; $ffprobeBinary = '/your/path/to/ffprobe'; To install FFMpeg (if missing): Ubuntu/Debian: sudo apt-get update sudo apt-get install ffmpeg CentOS/RHEL: sudo yum install epel-release sudo yum install ffmpeg cPanel: Usually pre-installed. Check with: which ffmpeg ================================================================================ STEP 6: SET FILE PERMISSIONS ================================================================================ Run these commands: # Create and set directory permissions mkdir -p /home/radio/streams chmod 755 /home/radio/streams chmod 755 /home/radio # Set PHP file permissions chmod 644 /home/radio/*.php chmod 664 /home/radio/config.php # Needs to be writable # Secure database credentials chmod 600 /home/radio/db.php # Set SQL file permission chmod 644 /home/radio/radio_streams.sql Verify permissions: ls -la /home/radio/ Expected output similar to: drwxr-xr-x /home/radio/ -rw-rw-r-- config.php -rw------- db.php -rw-r--r-- e.php drwxr-xr-x streams/ ================================================================================ STEP 7: UPDATE PHP CLI PATH ================================================================================ Find your PHP CLI path: which php Common paths: /usr/bin/php /opt/cpanel/ea-php83/root/usr/bin/php /usr/local/bin/php Update in stream-manager.php: $phpCliPath = '/your/path/to/php'; ================================================================================ STEP 8: TEST WEB INTERFACE ================================================================================ 1. Open your browser and navigate to: http://yourdomain.com/stream-manager.php 2. You should see: ✓ Radio Stream Manager interface ✓ Current Active Stream status ✓ Available Streams table (with sample data) ✓ Add New Stream form 3. Test adding a stream: Station Name: Test Station Stream URL: https://kexp-mp3-128.streamguys1.com/kexp128.mp3 Click: Add Stream 4. Test setting active stream: Click "Set Active" next to any stream Verify the Active Stream Configuration updates 5. Test manual recording: Click "Start Recording Now" Check /home/radio/streams/ for output file File format: recording_YYYYMMDD_HHMMSS.mp3 ================================================================================ STEP 9: TEST ERROR LOG VIEWER ================================================================================ Navigate to: http://yourdomain.com/e.php You should see: ✓ Log statistics (Total Entries, Errors, Info) ✓ Log content display ✓ Refresh and Clear buttons ================================================================================ STEP 10: SET UP AUTOMATED RECORDING (CRON) ================================================================================ Edit crontab: crontab -e Add this line for daily recording at 1:00 AM: 0 1 * * * /opt/cpanel/ea-php83/root/usr/bin/php /home/radio/record_stream.php >> /home/radio/cron_output.log 2>&1 Other scheduling examples: Every hour: 0 * * * * /path/to/php /home/radio/record_stream.php Every day at 6 AM: 0 6 * * * /path/to/php /home/radio/record_stream.php Twice daily (6 AM and 6 PM): 0 6,18 * * * /path/to/php /home/radio/record_stream.php Every Sunday at 2 PM: 0 14 * * 0 /path/to/php /home/radio/record_stream.php Verify cron is set: crontab -l ================================================================================ TROUBLESHOOTING ================================================================================ PROBLEM: "Database connection failed" SOLUTION: - Verify db.php exists with correct credentials - Test: mysql -u username -p -e "USE radio_streams_db;" - Check MySQL is running: systemctl status mysql PROBLEM: "Could not write to config.php" SOLUTION: - Check permissions: ls -la /home/radio/config.php - Should be: -rw-rw-r-- (664) - Fix: chmod 664 /home/radio/config.php PROBLEM: "FFMpeg Exception" SOLUTION: - Verify FFMpeg: which ffmpeg - Test stream URL: ffmpeg -i "http://stream-url" -t 10 test.mp3 - Check paths in record_stream.php match system paths PROBLEM: Recording doesn't start SOLUTION: 1. Check error_log.txt: cat /home/radio/error_log.txt 2. Test stream URL in browser or VLC 3. Verify active stream is set (not "Not Set.") 4. Check file permissions on streams/ directory 5. Review e.php for detailed errors PROBLEM: Cron job not running SOLUTION: - Verify PHP CLI path: which php - Check cron output: cat /home/radio/cron_output.log - Test manually: /path/to/php /home/radio/record_stream.php - Verify cron service: systemctl status cron PROBLEM: Web interface shows blank page SOLUTION: - Check PHP error log: tail -f /var/log/php-error.log - Verify all files uploaded - Check db.php exists - Test PHP: php -l /home/radio/stream-manager.php PROBLEM: "Composer not found" SOLUTION: Install Composer: curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer composer require php-ffmpeg/php-ffmpeg ================================================================================ VERIFICATION CHECKLIST ================================================================================ Before going live, verify: □ Database connection works (stream-manager.php loads) □ Can add/edit/delete streams □ Can set active stream □ config.php updates when setting active stream □ Manual recording creates MP3 file in streams/ □ Error logging works (check e.php) □ Cron job is scheduled □ File permissions are correct □ FFMpeg paths are correct □ PHP CLI path is correct □ All sample streams work (test each one) ================================================================================ MAINTENANCE TIPS ================================================================================ Regular maintenance tasks: 1. Monitor disk space: du -sh /home/radio/streams/ 2. Clean old recordings: find /home/radio/streams/ -name "*.mp3" -mtime +30 -delete 3. Review error logs weekly: Access: e.php or cat /home/radio/error_log.txt 4. Backup database monthly: mysqldump -u username -p radio_streams_db > backup.sql 5. Test recordings periodically: Ensure cron is running and files are being created 6. Update stream URLs: Radio streams change URLs - verify periodically ================================================================================ SECURITY BEST PRACTICES ================================================================================ 1. Database: □ Use strong password (minimum 16 characters, mixed case, numbers, symbols) □ Create dedicated database user (don't use root) □ Grant only necessary permissions □ chmod 600 db.php 2. Web Access: □ Use HTTPS if possible □ Consider password-protecting stream-manager.php with .htpasswd □ Place sensitive files outside web root if possible 3. File System: □ Regularly review file permissions □ Don't make unnecessary files world-readable □ Keep error logs secure 4. Backups: □ Backup database regularly □ Backup recordings to external storage □ Keep backup of working configuration ================================================================================ SUPPORT RESOURCES ================================================================================ Documentation: - README.md (included) - This installation guide Check logs: - Web interface: http://yourdomain.com/e.php - File: /home/radio/error_log.txt - Cron: /home/radio/cron_output.log Test components: - Database: mysql -u username -p radio_streams_db - FFMpeg: ffmpeg -version - PHP: php -v - Stream URL: ffmpeg -i "http://url" -t 5 test.mp3 ================================================================================ INSTALLATION COMPLETE! ================================================================================ If all steps completed successfully, you should have: ✓ Working web interface at stream-manager.php ✓ Database with radio streams ✓ Ability to record streams manually ✓ Automated recording via cron ✓ Error logging and monitoring Next steps: 1. Add your favorite radio streams 2. Test manual recording 3. Verify cron job runs 4. Monitor error logs 5. Enjoy automated radio recordings! ================================================================================