Setup Icecast with PHP

Setting up multiple audio streams using Icecast in PHP requires a combination of server-side and client-side code. Below, I’ll provide a simple example of how you can set up a basic Icecast server with multiple streams and a PHP script to stream audio from the microphone using the Icecast source client, ices.

Step 1: Install Icecast

First, make sure you have Icecast installed on your server. You can follow the official Icecast documentation for installation: Icecast Installation

Step 2: Configure Icecast

Edit the Icecast configuration file (usually located at /etc/icecast2/icecast.xml on Linux systems) to include multiple mount points:

<!-- /etc/icecast2/icecast.xml -->
  <!-- Other Icecast configuration settings -->

    <!-- Other mount-specific settings -->

    <!-- Other mount-specific settings -->

  <!-- Add more mount points as needed -->

  <!-- Other Icecast configuration settings -->

Step 3: Install Ices

Ices is the source client for Icecast. Install it on your server:

sudo apt-get install ices2

Step 4: Create a PHP script to stream audio from the microphone

Create a PHP script (stream_mic.php) to execute the ices command and stream audio from the microphone:

// stream_mic.php

$stream1Command = "ices /path/to/ices-config-stream1.xml";
$stream2Command = "ices /path/to/ices-config-stream2.xml";

// Execute commands in the background
exec($stream1Command . " > /dev/null 2>&1 &");
exec($stream2Command . " > /dev/null 2>&1 &");

echo "Audio streams started.";

Step 5: Create Ices Configuration Files

Create separate Ices configuration files (ices-config-stream1.xml and ices-config-stream2.xml) for each stream:

<!-- ices-config-stream1.xml -->

      <name>Stream 1</name>
      <description>First audio stream from the microphone</description>

Create a similar configuration file for the second stream (ices-config-stream2.xml) with appropriate settings.

Step 6: Run the PHP script

Run the PHP script to start streaming audio from the microphone to multiple Icecast streams:

php stream_mic.php

Ensure that the Icecast server is running, and you should be able to listen to the streams at:

  • http://your-server:8000/stream1
  • http://your-server:8000/stream2

Adjust the configuration files and PHP script as needed based on your requirements and server setup.