Introduction
Airsonic is an open-source media server that allows you to fully access your music and share it with colleagues or even enjoy listening to your favorite playlist at any place. This free self-hosted media streamer is based on Java language, and built to deal with a large collection of music and is the ultimate solution for MP3 streaming. Airsonic is compatible with any video or audio file format as long as they are streaming comfortably over HyperText Transfer protocol including FLAX, WMA, APE, and many more. In this article, we will take you through the process of installing Airsonic on your Ubuntu 18.04 server. Similarly, we will also install Airsonic with the help of the reliable.WAR package, activate the service, then configure Nginx server as a reverse proxy for this installation.
Before You Start
- A VPS hosting or dedicated hosting account with a VPS running Ubuntu 18.04
- A non-root user with sudo privileges
With these items in place, let’s get started.
Step 1 – Installing Java OpenJDK
Being a java language based app, Airsonic needs to use Java for the installation process. This process requires the installation of the latest OpenJDK series. First, start by installing Java OpenJDK. You can get it from Webupd8team; the official PPA repository. Remember to install the common packages of the software then include the PPA repository for Java OpenJDK. You can do this by running the following command:
$ sudo apt install software-properties-common apt-transport-https -y $ sudo add-apt-repository ppa:webupd8team/java -y
The next step involves the installation of the Java OpenJDK.
$ sudo apt installoracle-java8-installer -y
The system should automatically install Java OpenJDK application on your Ubuntu 18.04 server. Once you’re done, execute the command below to check the current version of Java OpenJDK:
$ java -version
This will give you the output below:
Javaversion "1.8.0_181" Java (TM) SERuntimeEnvironment (build 1.8.0_181-b13) JavaHotSpot (TM) 64-BitserverVM (build 25.181-b13, mixmode)
Step 2 – Installing and Configuring Airsonic
Airsonic can be installed in several different packages. In this article, we shall explore our stand-alone installation using WAR packages. Start by creating another user with the name ‘airsonic,’ then create a directory named ‘/opt/airsonic.’ For this process, run the following command:
$ sudo useradd airsonic $ sudo mkdir -p /opt/airsonic
Open the newly created directory; /opt/airsonic and search then download the .WAR package for Airsonic using wget as shown below:
$ cd /opt/airsonic $ wget https://github.com/airsonic/airsonic/releases/download/v10.1.1/airsonic.war
Change the name of this directory to ‘airsonic’ user as well as the group.
$ sudo chown -R airsonic:airsonic /opt/airsonic
After that, the .WAR package for the Airsonic installation should be downloaded. The next thing creating a new file for Airsonic. To do so, go to ‘/etc/systemd/system’ directory then create a service file named airsonic.service
$ sudo nano /etc/systemd/system
Edit and include the following lines for the Airsonic configuration as shown below:
[Unit] Description=Airsonic Media Server After=remote-fs.target network.target AssertPathExists=/opt/airsonic [Service] Type=simple Environment="JAVA_JAR=/opt/airsonic/airsonic.war" Environment="JAVA_OPTS=-Xmx700m" Environment="AIRSONIC_HOME=/opt/airsonic" Environment="PORT=8080" Environment="CONTEXT_PATH=/airsonic" Environment="JAVA_ARGS=" EnvironmentFile=-/etc/sysconfig/airsonic ExecStart=/usr/bin/java $JAVA_OPTS -Dairsonic.home=${AIRSONIC_HOME} -Dserver.context-path=${CONTEXT_PATH} -Dserver.port=${PORT} -jar ${JAVA_JAR} $JAVA_ARGS User=airsonic Group=airsonic [Install] WantedBy=multi-user.target
Now save and close the file. Restart your system and go to ‘/etc/default’ directory then create a default file for airsonic.
$ sudo systemctl daemon-reload $ sudo nano /etc/default/airsonic
Add the default configuration file below for airsonic:
# Set the location of the standalone war to use JAVA_JAR=/opt/airsonic/airsonic.war # Set any java opts separated by spaces JAVA_OPTS=-Xmx700m # Set a different location for the airsonic home. # If this path is /opt/libresonic or even contains "libresonic", # the data from a previous libresonic can be used as is (i.e. without # renaming libresonic.properties,db/libresonic*, etc AIRSONIC_HOME=/opt/airsonic # Change the port to listen on PORT=8080 # Change the path that is listened to on CONTEXT_PATH=/airsonic # Add any java args. These are different than JAVA_OPTS in that # they are passed directly to the program. The default is empty: #JAVA_ARGS= # Note that there are several settings for spring boot, not explicitly listed # here, but can be used in either JAVA_OPTS or JAVA_ARGS. The full list # can be found here: # https://docs.spring.io/spring-boot/docs/1.4.5.RELEASE/reference/htmlsingle/#common-application-properties # For example to set debug across the board: #JAVA_ARGS=--debug # Or to change the IP address that is listened to: JAVA_ARGS=--server.address=127.0.0.1
Now, save and close the file. Restart your Airsonic service then set it to start on boot time.
$ sudo systemctl start airsonic $ sudo systemctl enable airsonic
Now the installation process for airsonic alone is done. Use a netstat command to check its status.
$ netstat -plntu
At this point, the default Airsonic service will listen to port ‘8080’ that is used by Airsonic’s Java service.
Step 3 – Generating A New SSL Lets Encrypt Cert
As aforementioned, we will install Airsonic via the HTTP connections for Nginx web server, but you have to choose a domain name of your choice. Now, we will try to create the SSL certificate using Letsencrypt. First, execute the command below to install the required Letsencrypt tool:
$ sudo apt install letsencrypt -y
Once the tool is installed, you can now create a new SSL certificate for your domain name using the following command. Remember to replace the value “domian name” with your precise domain name:
$ certbot certonly --standalone -domain name
When you run the command above, you’ll be prompted to provide your email address to receive notifications. Type ‘A’ for the TOS agreement on Letsencrypt to show that you agree with the terms then type ‘N’ for No for the shared email address. Once you’re done, you will receive a congratulatory message to show that your certificate has been successfully generated and saved in the /etc/letsencrypt/live/domain directory.
Step 4 – Installing and Configuring Nginx Reverse Proxy
Now we shall start installing the Nginx server then configure it on port 8080 on Airsonic software as a reverse proxy. To start the Nginx installation, run the apt command below:
$sudo apt install nginx -y
Now, open the ‘/etc/nginx’ directory then create a new virtual host file named ‘airsonic.’ cd /etc/nginx/
$ sudo nano sites-available/airsonic
Add the following lines in the configuration:
server { listen80; listen [::]:80; server_name music.hakase-labs.io; # enforce https return301 https://$server_name$request_uri; } server { listen 443 ssl; server_name music.hakase-labs.io; ssl_certificate /etc/letsencrypt/live/music.hakase-labs.io/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/music.hakase-labs.io/privkey.pem; location /airsonic { 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 https; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header Host $http_host; proxy_max_temp_file_size 0; proxy_pass http://127.0.0.1:8080; proxy_redirect http:// https://; } }
Now, save and close the file. The next step is to activate the already created ‘airsonic host file then start testing the configuration:
$ sudo ln -s /etc/nginx/sites-available/airsonic /etc/nginx/sites-enabled/ nginx -t
Confirm that there are no errors, then restart the Nginx service and set it to start at boot time.
$ sudo systemctl restart nginx $ sudo systemctl enable nginx
By this point, the Nginx service is successfully operating as the reverse proxy for Airsonic. It should listen to port 8080 under a secure https connection. To confirm this, use the netstat command as shown below:
$ netstat -plntu
Step 5 – Configuring Uncomplicated Firewall (UFW) Firewall
Here, we shall work on Ubuntu UFW firewall. Start by accessing the Uncomplicated Firewall by opening the SSH, HTTPS, and HTTP service using the commands below:
$ sudo ufw allow ssh $ sudo ufw allow http $ sudo ufw allow https
Go ahead and activate your ufw firewall.
$ sudo ufw enable
Now, enter ‘y’ for Yes then click Enter to complete the activation.
Step 6 – Verifying The Installation
For this step, open your favorite web browser, then enter the URL for Airsonic installation.
https://yourdomainname/airsonic/
You should see the login page for Airsonic.
$ suod mkdir -p /var/music $ sudo chown -R airsonic:airsonic /var/music
On Airsonic dashboard, select Settings then locate the Media folders icon.
Conclusion
That is it! Airsonic has been successfully installed on your Ubuntu 18.04 server.
Check out these top 3 VPS services:
- Get answer to all of your queries about best VPS hosting by clicking here.