1. Home
  2. Linux
  3. How to run your own ampache server on ubuntu server

How to run your own Ampache server on Ubuntu Server

Want to host your own sophisticated music streaming service? Try out Ampache. It’s a PHP-powered music streaming service for Linux. Here’s how to get Ampache working on your Ubuntu server.

How to install Ampache on Ubuntu Server

Ampache is a bit difficult to install, as there isn’t anything pre-packaged for Ubuntu Server. To start the installation process, you’ll need to install the required dependencies. These dependencies are installable via the terminal.

Using the apt install command install the packages that Ampache needs to run correctly on your Ubuntu Server system.

sudo apt install apache2 mysql-server php php-intl libapache2-mod-php php-mysql php-xml php-mbstring php-curl ffmpeg lame unzip

Installing these packages could take a few minutes, as there are many things to set up. When everything is configured, use the systemctl start command to start up MySQL and Apache2.

sudo systemctl start apache2
sudo systemctl start mysql

You’ll also need to enable these services if Ubuntu doesn’t do it automatically. You can do it with the systemctl enable commands.

sudo systemctl enable apache2
sudo systemctl enable mysql

You’ll now need to log into MySQL with “root” to create the database that Ampache will use. Ensure you have access to “root”. You can do this by following our Ubuntu root configuration guide.

sudo mysql -u root -p

After logging into MySQL, you need to create the Ampache database using the CREATE DATABASE command.

CREATE DATABASE ampache;

Next, you’ll need to create the Ampache database user account. In this guide, we’ll call the user “ampacheuser”. Note that the CREATE USER command also specifies the hostname and password.

Note: change “hostname” and “password” in the command below with your Ubuntu server hostname and your desired password.

CREATE USER 'ampacheuser'@'localhost' IDENTIFIED BY 'password';

After creating the user and password in the MySQL database, you’ll need to grant privileges to it. Enter the command below. Be sure to change “localhost” to your server’s hostname.

GRANT ALL PRIVILEGES ON ampache.* TO 'ampacheuser'@'localhost';

With the Ampache database fully configured, use the SOURCE command to import the “ampache.sql” file into your new database. This file will create the necessary SQL tables Ampache needs to run.

USE ampache;
SOURCE /var/www/html/resources/sql/ampache.sql;

Next, use the FLUSH PRIVILEGES command to flush privileges. Then, use the exit command to exit MySQL.

FLUSH PRIVILEGES;
exit

After exiting MySQL, you’ll have to download the latest release of Ampache to your computer. Use the wget command to download Ampache.

wget https://github.com/ampache/ampache/releases/download/5.5.6/ampache-5.5.6_all_php8.1.zip

With the ZIP archive downloaded to your Ubuntu Server, use the unzip command to unzip Ampache and install it to /var/www/html/ on Ubuntu.

sudo unzip ampache-5.5.6_all_php8.1.zip -d /var/www/html/

After unzipping everything, use the cd command to access the “config” folder in /var/www/html/.

cd /var/www/html/config/

Inside this directory, use the cp command to create a new configuration file for your Ampache installation.

sudo cp ampache.cfg.php.dist ampache.cfg.php

Update the permissions of the config file.

sudo chown www-data:www-data /var/www/html/config/ampache.cfg.php
sudo chmod 644 /var/www/html/config/ampache.cfg.php

Create and update the permissions of the “.htaccess” files.

sudo mv /var/www/html/public/rest/.htaccess.dist /var/www/html/public/rest/.htaccess
sudo chmod 644 /var/www/html/public/rest/.htaccess

sudo mv /var/www/html/public/channel/.htaccess.dist /var/www/html/public/channel/.htaccess
sudo chmod 644 /var/www/html/public/channel/.htaccess

sudo mv /var/www/html/public/play/.htaccess.dist /var/www/html/public/play/.htaccess
sudo chmod 644 /var/www/html/public/play/.htaccess

sudo chown --recursive www-data:www-data /var/www/html/

Open up the configuration file using Nano and scroll down to “Database.”

Note: if you can’t find “Database” in Nano, press Ctrl + W, and type in “Database.”

sudo nano /var/www/html/config/ampache.cfg.php

First, change the following line from “localhost” to your actual hostname.

database_hostname = localhost

Then, change the following line so that “username” is “ampacheuser”.

database_username = username

Lastly, change this line so that “password” is changed to your Ampache database password.

database_password = password

When you’ve finished editing, press Ctrl + O to save the configuration file. Exit with Ctrl + X. Then, use the touch command to create a new site file.

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

Open up the “ampache.conf” using the Nano command. Then, paste the following code into the editor. Be sure to replace “your_domain.com” with your actual domain name.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/public
    ServerName your_domain.com

    <Directory /var/www/html/public/>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        all from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Use the a2ensite command to enable Ampache in the Apache web server. Then, use the a2enmod command to “rewrite” the config.

sudo a2ensite ampache.conf
sudo a2enmod rewrite

Delete the default Apache index.html file.

sudo rm /var/www/html/index.html

Finally, restart Apache using the systemctl restart command. When it is restarted, open up your Browser at the following URL(s).

http://your-ubuntu-server/public

How to configure Ampache on Ubuntu Server

On the Ampache installation page, you’ll need to select your language. After choosing your language, find the “Start Configuration” button, and click on it with the mouse. Ampache will check your Ubuntu server and make sure everything is ready to go. Assuming there are no errors, scroll to the bottom and click “Continue.”

After selecting “Continue,” you’ll be asked to “Insert” the SQL database. Considering we’ve already created the database and imported the “ampache.sql” file manually, select “skip.”

You’ll now need to enter your SQL password. Enter the password you used to log in with root to access MySQL earlier. Then, scroll down to “Installation Type” and choose the type of Ampache you’d prefer to use.

Once you’ve chosen your installation type, you must choose if you wish to allow transcoding. Select “ffmpeg” if you choose to enable transcoding. Otherwise, leave it blank.

When you’ve finished configuring everything, click the “Create Config” button at the bottom. If you cannot proceed, select the arrow next to “File Insight” to confirm everything is correctly configured.

You’ll now need to create an administrator account for your Ampache installation. Enter “admin” and a secure password. When done, click “Create Account.” After creating your account, you’ll be able to log in and configure your music collection with Ampache.