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): hitjethva@gmail.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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:
Select your language and click on the Start Configuration button. You should see the following page:
Make sure all the required PHP extensions are installed then click on the Continue button. You should see the following page:
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:
Provide your database details, select ffmpeg and click on the Create Config. You should see the following page:
Provide your admin username, password and click on the Create Account button. You should see the following page:
Click on the Update Now button to update all required packages. You should see the following page:
Click on the Return to main page link. You should see the following page:
Provide your admin username, password and click on the Login button. You should see the Ampache dashboard in the following page:
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.