如何在Ubuntu 20.04上安装Ampache Music Streaming Server

如何在Ubuntu 20.04上安装Ampache Music Streaming Server

Ampache是​​一个免费的,开源的,基于Web的软件,可让您托管自己的音乐流服务器。使用Ampache,您可以通过Internet访问音乐和视频。您可以通过网络浏览器或任何媒体流客户端查看,编辑和播放音乐。

特征

  • 强大的API和流式传输到任何客户端
  • 灵活的目录和定制
  • 现代HTML5网络播放器
  • 支持各种授权方法,例如MySQL,LDAP,HTTP和PAM
  • 与任何Subsonic客户端兼容

在本教程中,我们将学习如何在Ubuntu 20.04上设置Ampache音乐流服务器。

先决条件

  • 运行Ubuntu 20.04的服务器。
  • 在您的服务器上设置了root密码。

入门

在开始之前,最好将系统的软件包更新为最新版本。您可以使用以下命令更新它们:

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

更新所有软件包后,请重新启动系统以应用更改。

安装LAMP服务器

Ampache在使用PHP编写的Web服务器上运行,并使用MySQL / MariaDB存储其数据。因此,您将需要在系统中安装Apache,MariaDB,PHP和其他必需的PHP扩展。您可以通过运行以下命令来安装它们:

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

安装完所有软件包后,打开php.ini文件并进行一些设置:

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

更改以下值:

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

完成后保存并关闭文件。然后,重新启动Apache服务以实现更改:

systemctl restart apache2

配置MariaDB数据库

默认情况下,MariaDB不安全。您可以通过运行以下脚本来保护它:

mysql_secure_installation

回答所有问题,如下所示:

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

一旦MariaDB安全,请使用以下命令登录MariaDB shell:

mysql -u root -p

提供您的MariaDB根密码,并使用以下命令为Ampache创建数据库和用户:

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

接下来,使用以下命令将所有特权授予Ampache数据库:

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

接下来,使用以下命令刷新特权并退出MariaDB shell:

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

下载Ampache

您可以使用以下命令下载最新版本的Ampache:

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

下载完成后,将下载的文件解压缩到Apache Web根目录:

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

接下来,将Ampache目录的所有权更改为www-data:

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

接下来,将目录更改为ampache并重命名所需的.htaccess文件。

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

接下来,创建一个目录来存储音乐文件,并将所有权更改为www-data:Advertisements.banner-1 {text-align:center; padding-top:10pximportant; padding-bottom:10pximportant; padding-left:0pximportant; padding-right:0pximportant; width:100%important; box-sizing:border-boximportant; background -color:#eeeeeeimportant; border:1px实心#dfdfdf}

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

完成后,您可以继续下一步。

为Ampache配置Apache

接下来,您将需要为Ampache创建一个新的Apache虚拟主机配置文件。您可以使用以下命令创建它:

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

添加以下行:



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

    
        AllowOverride All
        Require all granted
    

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


完成后保存并关闭文件。然后,使用以下命令检查Apache配置文件是否存在任何错误:

apachectl configtest

您应该获得以下输出:Advertisements.large-leaderboard-2 {text-align:center; padding-top:10pximportant; padding-bottom:10pximportant; padding-left:0pximportant; padding-right:0pximportant; width:100%important; box-sizing:border-boximportant; background -color:#eeeeeeimportant; border:1px实心#dfdfdf}

Syntax OK

接下来,使用以下命令启用Apache虚拟主机配置文件和必需的模块:

a2ensite ampache
a2enmod expires rewrite

最后,重新启动Apache服务以应用更改:

systemctl reload apache2

此时,已经安装并配置了Ampache。现在,您可以继续下一步。

让我们加密货币SSL来保护Ampache

建议使用“让我们加密货币SSL”来保护您的Ampache网站。

首先,安装Certbot客户端为您的网站下载并安装“让我们加密货币SSL”。

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

安装完成后,运行以下命令为您的网站安装“让我们加密货币SSL”。

certbot --apache -d ampache.linuxbuz.com

系统将要求您提供电子邮件地址并接受服务条款,如下所示:

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

接下来,您将需要选择是否将HTTP流量重定向到HTTPS,如下所示:

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

输入2,然后按Enter键继续。安装完成后,您将获得以下输出:

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

接下来,使用以下命令测试“让我们加密货币”证书的自动更新:Advertisements.leader-1 {text-align:center; padding-top:10pximportant; padding-bottom:10pximportant; padding-left:0pximportant; padding-right:0pximportant; width:100%important; box-sizing:border-boximportant; background -color:#eeeeeeimportant; border:1px实心#dfdfdf}

certbot renew --dry-run

如果测试成功,您应该获得以下输出:

** 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.)

访问Ampache Web界面

现在,您的Ampache网站已使用“让我们加密货币SSL”保护。接下来,打开您的Web浏览器并输入URL https://ampache.linuxbuz.com。您将被重定向到以下页面:

选择语言

选择您的语言,然后单击“开始配置”按钮。您应该看到以下页面:

验证先决条件

确保已安装所有必需的PHP扩展,然后单击“继续”按钮。您应该看到以下页面:

数据库配置

提供您的数据库详细信息,取消选中“创建数据库”,选中“创建表”,取消选中“创建数据库用户”,然后单击“插入数据库”按钮。您应该看到以下页面:

生成配置文件

提供您的数据库详细信息,选择ffmpeg,然后单击“创建配置”。您应该看到以下页面:

创建管理员帐户

提供您的管理员用户名,密码,然后单击“创建帐户”按钮。您应该看到以下页面:

现在更新

单击立即更新按钮以更新所有必需的软件包。您应该看到以下页面:

Ampache更新

单击返回主页链接。您应该看到以下页面:

管理员登入

提供您的管理员用户名,密码,然后单击“登录”按钮。您应该在以下页面中看到Ampache仪表板:

Ampache仪表板

结论

恭喜你您已在Ubuntu 20.04服务器上成功安装并保护了Ampache。现在,您可以创建新目录,上传音乐并通过Internet播放它们。

资讯来源:由0x资讯编译自HOWTOFORGE,版权归作者所有,未经许可,不得转载
你可能还喜欢