How To Install the Ampache Music Streaming Server on Ubuntu 20.04

Ampache is a free, open-source, and web-based software that allows you to host your own music streaming server. With Ampache, you can access your music and video over the internet. You can view, edit, and play your music via a web browser or any media streaming client.

Features

  • Powerful API and streaming to any client
  • Flexible catalogs and customization
  • Modern HTML5 Web Player
  • Support various authorization methods such as MySQL, LDAP, HTTP and PAM
  • Compatibility with any Subsonic client

In this tutorial, we will learn how to setup Ampache music streaming server on Ubuntu 20.04.

Prerequisites

  • A server running Ubuntu 20.04.
  • A root password is setup on your server.

Getting Started

Before starting, it is a good idea to update your system's package to the latest version. You can update them using the following command:

apt-get update -y
apt-get upgrade -y

Once all the packages are updated, restart your system to apply the changes.

Install LAMP Server

Ampache runs on the webserver, written in PHP and uses MySQL/MariaDB to store its data. So you will need to install Apache, MariaDB, PHP and other required PHP extensions in your system. You can install them by running the following command:

apt-get install apache2 libapache2-mod-php php php-cli mariadb-server php-mysql php-curl php-json php-gd php-xml unzip curl git zip ffmpeg -y

Once all the packages are installed, open the php.ini file and tweak some settings:

nano /etc/php/7.4/apache2/php.ini

Change the following values:

upload_max_filesize = 100M
post_max_size = 100M
date.timezone = Asia/Kolkata

Save and close the file when you are finished. Then, restart the Apache service to implement the changes:

systemctl restart apache2

Configure MariaDB Database

By default, MariaDB is not secured. You can secure it by running the following script:

mysql_secure_installation

Answer all the question as shown below:

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Once the MariaDB is secured, log in to MariaDB shell with the following command:

mysql -u root -p

Provide your MariaDB root password and create a database and user for Ampache with the following command:

MariaDB [(none)]> CREATE DATABASE ampachedb;
MariaDB [(none)]> CREATE USER 'ampache'@'localhost' IDENTIFIED BY 'password';

Next, grant all the privileges to Ampache database with the following command:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON ampachedb.* TO 'ampache'@'localhost';

Next, flush the privileges and exit from the MariaDB shell using the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Download Ampache

You can download the latest version of the Ampache using the following command:

wget https://github.com/ampache/ampache/releases/download/4.1.1/ampache-4.1.1_all.zip

Once the download is completed, unzip the downloaded file to the Apache web root directory:

unzip ampache-4.1.1_all.zip -d /var/www/html/ampache

Next, change the ownership of Ampache directory to www-data:

chown -R www-data:www-data /var/www/html/ampache

Next, change the directory to ampache and rename the required .htaccess file.

cd /var/www/html/ampache
mv rest/.htaccess.dist rest/.htaccess
mv play/.htaccess.dist play/.htaccess
mv channel/.htaccess.dist channel/.htaccess

Next, create a directory to store music files and change the ownership to www-data:

mkdir -p /data/Music
chown www-data:www-data /data/Music

Once you are finished, you can proceed to the next step.

Configure Apache for Ampache

Next, you will need to create a new Apache virtual host configuration file for Ampache. You can create it with the following command:

nano /etc/apache2/sites-available/ampache.conf

Add the following lines:

<VirtualHost *:80>

    ServerName ampache.linuxbuz.com
    DocumentRoot /var/www/html/ampache

    <Directory /var/www/html/ampache/>
        AllowOverride All
        Require all granted
    </Directory>

    RewriteEngine on
    CustomLog /var/log/apache2/ampache.access.log common
    ErrorLog  /var/log/apache2/ampache.error.log

</VirtualHost>

Save and close the file when you are finished. Then, check the Apache configuration file for any error with the following command:

apachectl configtest

You should get the following output:

Syntax OK

Next, enable the Apache virtual host configuration file and required modules with the following command:

a2ensite ampache
a2enmod expires rewrite

Finally, restart the Apache service to apply the changes:

systemctl reload apache2

At this point, Ampache is installed and configured. You can now proceed to the next step.

Secure Ampache with Let's Encrypt SSL

It is recommended to secure your Ampache website with Let's Encrypt SSL.

First, install the Certbot client to download and install the Let's Encrypt SSL for your website.

apt-get install certbot python3-certbot-apache -y

Once installed, run the following command to install the Let's Encrypt SSL for your website.

certbot --apache -d ampache.linuxbuz.com

You will be asked to provide your e-mail address and accept the term of service as shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for ampache.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/ampache-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/ampache-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/ampache-le-ssl.conf

Next, you will need to choose whether or not to redirect HTTP traffic to HTTPS as shown below:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Type 2 and hit Enter to continue. Once the installation has been completed, you should get the following output:

Redirecting vhost in /etc/apache2/sites-enabled/ampache.conf to ssl vhost in /etc/apache2/sites-available/ampache-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://ampache.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=ampache.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/ampache.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/ampache.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-07-29. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Next, test the autorenewal of Let's Encrypt certificate with the following command:

certbot renew --dry-run

If the test was successful, you should get the following output:

** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/ampache.linuxbuz.com/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)

Access Ampache Web Interface

Your Ampache website is now secured with Let's Encrypt SSL. Next, open your web browser and type the URL https://ampache.linuxbuz.com. You will be redirected to the following page:

Choose language

Select your language and click on the Start Configuration button. You should see the following page:

Verify prerequisites

Make sure all the required PHP extensions are installed then click on the Continue button. You should see the following page:

Database configuration

Provide your database details, uncheck Create Database, check Create Tables, uncheck Create Database Users and click on the Insert Database button. You should see the following page:

Generate configuration file

Provide your database details, select ffmpeg and click on the Create Config. You should see the following page:

Create admin account

Provide your admin username, password and click on the Create Account button. You should see the following page:

Update now

Click on the Update Now button to update all required packages. You should see the following page:

Ampache update

Click on the Return to main page link. You should see the following page:

Admin login

Provide your admin username, password and click on the Login button. You should see the Ampache dashboard in the following page:

Ampache dashboard

Conclusion

Congratulations! you have successfully installed and secured Ampache on Ubuntu 20.04 server. You can now create your new catalog, upload your music and play them over the internet.

Share this page:

Suggested articles

3 Comment(s)

Add comment

Comments

By: Paul Kelly at: 2020-05-25 16:20:08

Apparently 20.04 has changed enough since you wrote this that it no longer works. mariadb no longer installs, mysql-mariadb fails to start after installation.   I'm aborting here.  Nice thought though, wish it would have worked.

By: till at: 2020-05-25 16:28:32

That's not an issue in the tutorial, MariaDB installs fine using the commands from the guide, tested it right after you posted your comment. Have a look at the /var/log/syslog file of your system to find out why it fails on your server. It might be that you don't have enough RAM or something similar. If you need help to set up your system, please make a post in the forum here at howtoforge with the detailed error message from syslog file.

By: Paul at: 2020-05-26 00:21:14

I so wanted this to work, but it doesn't.  Three show stopper issues mostly having to do with authentication or lack therof. Found answers to one of them via Google and one just looking up the program using synaptic to find the version that will actually install.  In the end, apache will not contact the database and I'm uninstalling all of it.  

Thank you for trying, it is a very cool thing and I wish it had worked for me.