Ricerca nel sito web

Come installare Ampache Music Streaming Server su Ubuntu 20.04


Questo tutorial esiste per queste versioni del sistema operativo

  • Ubuntu 20.04 (Focal Fossa)
  • Ubuntu 12.04 LTS (Precise Pangolin)

Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa il server LAMP
  4. Configura database MariaDB
  5. Scarica Ampache
  6. Configura Apache per Ampache
  7. Proteggi Ampache con Lets Encrypt SSL
  8. Accedi all'interfaccia web di Ampache
  9. Conclusione

Ampache è un software gratuito, open source e basato sul Web che ti consente di ospitare il tuo server di streaming musicale. Con Ampache, puoi accedere alla tua musica e ai tuoi video su Internet. Puoi visualizzare, modificare e riprodurre la tua musica tramite un browser Web o qualsiasi client di streaming multimediale.

Caratteristiche

  • Potente API e streaming su qualsiasi client
  • Cataloghi flessibili e personalizzazione
  • Giocatore Web HTML5 moderno
  • Supporta vari metodi di autorizzazione come MySQL, LDAP, HTTP e PAM
  • Compatibilità con qualsiasi client Subsonic

In questo tutorial impareremo come configurare il server di streaming musicale Ampache su Ubuntu 20.04.

Prerequisiti

  • Un server che esegue Ubuntu 20.04.
  • Una password di root è impostata sul tuo server.

Iniziare

Prima di iniziare, è una buona idea aggiornare il pacchetto di sistema all'ultima versione. Puoi aggiornarli usando il seguente comando:

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

Una volta aggiornati tutti i pacchetti, riavvia il sistema per applicare le modifiche.

Installa LAMP Server

Ampache funziona sul server web, scritto in PHP e utilizza MySQL/MariaDB per archiviare i propri dati. Quindi dovrai installare Apache, MariaDB, PHP e altre estensioni PHP richieste nel tuo sistema. Puoi installarli eseguendo il seguente comando:

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

Una volta installati tutti i pacchetti, apri il file php.ini e modifica alcune impostazioni:

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

Modificare i seguenti valori:

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

Salva e chiudi il file quando hai finito. Quindi, riavvia il servizio Apache per implementare le modifiche:

systemctl restart apache2

Configura database MariaDB

Per impostazione predefinita, MariaDB non è protetto. Puoi proteggerlo eseguendo il seguente script:

mysql_secure_installation

Rispondi a tutte le domande come mostrato di seguito:

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

Una volta che MariaDB è protetto, accedi alla shell MariaDB con il seguente comando:

mysql -u root -p

Fornisci la tua password root MariaDB e crea un database e un utente per Ampache con il seguente comando:

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

Quindi, concedi tutti i privilegi al database Ampache con il seguente comando:

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

Quindi, svuota i privilegi ed esci dalla shell MariaDB usando il seguente comando:

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

Scarica Ampache

Puoi scaricare l'ultima versione di Ampache usando il seguente comando:

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

Una volta completato il download, decomprimere il file scaricato nella directory root Web di Apache:

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

Successivamente, modifica la proprietà della directory Ampache in www-data:

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

Quindi, cambia la directory in ampache e rinomina il file .htaccess richiesto.

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

Quindi, crea una directory per archiviare i file musicali e cambia la proprietà in www-data:

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

Una volta terminato, puoi procedere al passaggio successivo.

Configura Apache per Ampache

Successivamente, dovrai creare un nuovo file di configurazione dell'host virtuale Apache per Ampache. Puoi crearlo con il seguente comando:

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

Aggiungi le seguenti righe:

<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>

Salva e chiudi il file quando hai finito. Quindi, controlla il file di configurazione di Apache per eventuali errori con il seguente comando:

apachectl configtest

Dovresti ottenere il seguente output:

Syntax OK

Successivamente, abilita il file di configurazione dell'host virtuale Apache e i moduli richiesti con il seguente comando:

a2ensite ampache
a2enmod expires rewrite

Infine, riavvia il servizio Apache per applicare le modifiche:

systemctl reload apache2

A questo punto, Ampache è installato e configurato. Ora puoi procedere al passaggio successivo.

Proteggi Ampache con Lets Encrypt SSL

Ti consigliamo di proteggere il tuo sito Web Ampache con Lets Encrypt SSL.

Innanzitutto, installa il client Certbot per scaricare e installare Lets Encrypt SSL per il tuo sito web.

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

Una volta installato, esegui il seguente comando per installare Lets Encrypt SSL per il tuo sito web.

certbot --apache -d ampache.linuxbuz.com

Ti verrà chiesto di fornire il tuo indirizzo e-mail e di accettare i termini di servizio come mostrato di seguito:

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): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

Successivamente, dovrai scegliere se reindirizzare o meno il traffico HTTP su HTTPS come mostrato di seguito:

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

Digita 2 e premi Invio per continuare. Una volta completata l'installazione, dovresti ottenere il seguente 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

Successivamente, prova il rinnovo automatico del certificato Lets Encrypt con il seguente comando:

certbot renew --dry-run

Se il test ha avuto successo, dovresti ottenere il seguente 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.)

Accedi all'interfaccia web di Ampache

Il tuo sito Web Ampache è ora protetto con Lets Encrypt SSL. Quindi, apri il tuo browser web e digita l'URL https://ampache.linuxbuz.com. Verrai reindirizzato alla seguente pagina:

Seleziona la lingua e fai clic sul pulsante Avvia configurazione. Dovresti vedere la seguente pagina:

Assicurati che tutte le estensioni PHP richieste siano installate, quindi fai clic sul pulsante Continua. Dovresti vedere la seguente pagina:

Fornisci i dettagli del tuo database, deseleziona Crea database, seleziona Crea tabelle, deseleziona Crea utenti database e fai clic sul pulsante Inserisci database. Dovresti vedere la seguente pagina:

Fornisci i dettagli del tuo database, seleziona ffmpeg e fai clic su Crea configurazione. Dovresti vedere la seguente pagina:

Fornisci il nome utente e la password dell'amministratore e fai clic sul pulsante Crea account. Dovresti vedere la seguente pagina:

Fare clic sul pulsante Aggiorna ora per aggiornare tutti i pacchetti richiesti. Dovresti vedere la seguente pagina:

Fare clic sul collegamento Torna alla pagina principale. Dovresti vedere la seguente pagina:

Fornisci il nome utente e la password dell'amministratore e fai clic sul pulsante Accedi. Dovresti vedere la dashboard di Ampache nella pagina seguente:

Conclusione

Congratulazioni! hai installato e protetto con successo Ampache sul server Ubuntu 20.04. Ora puoi creare il tuo nuovo catalogo, caricare la tua musica e riprodurla su Internet.