How to Install AzuraCast on OpenBSD

AzuraCast is a free and open-source self-hosted web radio management suite. It lets you easily set up and manage your own web radio station.

In this tutorial, we will guide you through the steps to install AzuraCast on your OpenBSD server.

Prerequisites:

Step 1: Installing Dependencies

Since AzuraCast is a web application based on PHP, we need to install all the necessary dependencies before we begin the installation process.

Open a terminal window on your OpenBSD server and type in the following command to install the required dependencies:

$ sudo pkg_add git php php-curl php-mbstring php-intl php-pdo_pgsql php-json php-gd nginx redis mariadb-server

This command will install git (to download the AzuraCast repository), Nginx (to serve the web application), Redis (for caching), MariaDB (for the database), and all the necessary PHP modules.

Once the installation is complete, start the MariaDB service by entering:

$ sudo rcctl enable mysqld
$ sudo rcctl start mysqld

You can check whether the MariaDB server is running by executing:

$ sudo rcctl check mysqld

Step 2: Clone AzuraCast Repository

After installing the dependencies, we can proceed to clone the AzuraCast repository.

Change the current working directory to /var/www/ using the following command:

$ cd /var/www/

Then clone the AzuraCast repository using the following command:

$ sudo git clone https://github.com/AzuraCast/AzuraCast.git azuracast

Once the repository is cloned, set the correct permissions for the azuracast directory by executing the following commands:

$ sudo chown -R www:www azuracast/
$ sudo chmod -R 777 azuracast/

Step 3: Configuration

Now let's create a configuration file for AzuraCast.

Create a new configuration file under /usr/local/etc/php-fpm.d/ called azuracast.conf using your favorite text editor:

$ sudo vi /usr/local/etc/php-fpm.d/azuracast.conf

Add the following lines to the file:

[azuracast]
listen=/run/php-fpm-azuracast.sock
listen.owner=www
listen.group=www
user=www
group=www
pm=dynamic
pm.max_children=5
pm.start_servers=2
pm.min_spare_servers=1
pm.max_spare_servers=3

Save and close the file.

Next, create a new file azuracast in the directory /etc/nginx/sites-available/:

$ sudo vi /etc/nginx/sites-available/azuracast

Add the following configuration to the file:

upstream backend {
    server unix:/run/php-fpm-azuracast.sock;
}

server {
    listen 80;
    server_name your_external_ip_address;

    rewrite ^ https://$server_name$request_uri permanent;
}

server {
    listen 443 ssl http2;
    server_name your_external_ip_address;

    ssl_certificate /etc/ssl/server.crt;
    ssl_certificate_key /etc/ssl/private/server.key;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;
    ssl_session_tickets off;
    
    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256;
    ssl_prefer_server_ciphers off;

    add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;

    root /var/www/azuracast/public;
    index index.php;
    access_log /var/log/nginx/azuracast-access.log;
    error_log /var/log/nginx/azuracast-error.log;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location /radio/ {
        sendfile off;

        add_header Cache-Control "public, max-age=60, stale-while-revalidate=15";
        add_header Last-Modified "";

        # CORS headers
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Allow-Credentials' 'true' always;
        add_header 'Access-Control-Allow-Headers' 'origin,authorization,accept,cache-control,content-type,dpr,save-data,viewport-width,x-csrf-token,x-requested-with' always;
        add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
        add_header 'Access-Control-Expose-Headers' 'content-disposition' always;

        expires 1h;

        auth_basic off;

        proxy_pass http://backend;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_intercept_errors on;
        error_page 404 /index.php?$query_string;
    }

    location /.well-known/acme-challenge {
        root /var/www/letsencrypt;
        auth_basic off;
    }

    location /static {
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public";
        add_header ETag "";
        add_header Last-Modified "";
    }

    location ~ [^/]\.php(/|$) {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTP_PROXY "";
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PHP_VALUE "open_basedir = /var/www/azuracast/:/tmp/:/usr/share/pear/:/usr/local/www/azuracast/:/usr/local/share/pear/:/usr/local/lib/php/:/etc/ssl/certs/";
        fastcgi_pass unix:/run/php-fpm-azuracast.sock;
        fastcgi_index index.php;
    }
}

Replace your_external_ip_address with the external IP address of your OpenBSD server.

Save and close the file.

Create a symlink to enable this configuration:

$ sudo ln -s /etc/nginx/sites-available/azuracast /etc/nginx/sites-enabled/

Next, edit the PHP configuration file:

$ sudo vi /etc/php-7.4.ini

Search for opcache.enable=0 and set it to 1:

opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8M
opcache.max_accelerated_files=8000
opcache.memory_consumption=128M
opcache.validate_timestamps=1

Save and close the file.

Now restart all services by entering the following commands to apply the changes:

$ sudo rcctl restart php74_fpm nginx redis mysqld

Step 4: Configuring the Database

After configuring the website, you need to create a new database and user for AzuraCast.

Login to MariaDB as root:

$ mysql -u root -p

Create a new database:

CREATE DATABASE azuracast;

Create a new user and grant privileges to the database:

GRANT ALL PRIVILEGES ON azuracast.* TO 'azuracast'@'localhost' IDENTIFIED BY 'your_password';

Replace your_password with a secure password of your choice.

Exit the MySQL shell:

exit

Step 5: Installing AzuraCast

Visit your server's IP address in a web browser using http://your_server_ip_address/setup/index.php to begin the installation process.

Follow the steps in the installation wizard, input the details of your database and user created in Step 4, and complete the installation.

After installing the application, you can access AzuraCast dashboard by visiting https://your_server_ip_address.

Congratulations! You have successfully installed AzuraCast on OpenBSD. You can now start setting up your web radio station using AzuraCast.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!