Radio Icecast / Shoutcast PHP Proxy to Re-stream Radio Stream on HTTPS

SHOUTcast doesn’t support SSL/HTTPs. The shoutcast service on port like 8000 is an unencrypted server for HTTP and ICY. So Shoutcast need proxy / restream HTTP stream to HTTPS.

You can use PHP or NodeJS or NGINX to restream Radio Streams. Re-Stream Radio Shoutcast / Icecast using Node JS

Re-Stream PHP Proxy file – stream/index.php

<?php 

/*

Icecast / Shoutcast MP3 Radio Stream 

Shoutcast V1 (http://shoutcast-server-ip:port/) 
Shoutcast V2 (http://shoutcast-server-ip:port/streamname) 
Icecast V2 (http://icecast-server-ip:port/streamname)

Type: Audio
Codec: MPEG Audio layer 1/2 (mpga)
Channels: Stereo
Sample rate: 44100 Hz
Bitrate: 128 kb/s

*/

header('Content-Type: audio/mpeg');

$server = "[Server-IP-Address]";
$port = "[Port]";
$mount = "[Mount-Point]";

// HTTP Radio Stream URL with Mount Point
$url = "http://".$server.":".$port."/".$mount;

// Open Radio Stream URL
// Make Sure Radio Stream [Port] must be open / allow in this script hosting server firewall 
$f=fopen($url,'r');

// Read chunks maximum number of bytes to read
if(!$f) exit;
while(!feof($f))
{
	echo fread($f,128);  
	flush();
}
fclose($f);

?>

.htaccess – stream/.htaccess

<FilesMatch "mp3$">
SetHandler application/x-httpd-php5
</FilesMatch>
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
# Redirect MP3 to PHP
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*).mp3$ index.php [L]
</IfModule>

So if you host these files on HTTPS enabled server in folder “stream” …. Radio Stream Proxy URL will look like

https://www.domain.com/stream/audio.mp3