# Ampache: Stream your own MP3 and Virtual Hosts HOWTO

## amiatrome

Ampache: Stream your own MP3 and Virtual Hosts HOWTO

by amiatrome

created April 24, 2005

Disclaimer: I put the following guide together from memory. Although great care was taken, there could still be some mistakes. Feedback is very welcomed. Enjoy.  :Very Happy: 

Introduction

Ampache is a PHP-based tool for managing, updating and streaming your MP3/OGG/RM/FLAC/WMA/M4A files via a web interface. It allows you to save playlists, create user accounts, and share your music catalogs with other Ampache servers.

Demo (streaming is disabled)

Ampache is now in Portage thanks to coutts99. I haven't tried it but PChaos has and he says it works great and come complete with instructions in emerge's output. So try that first.  :Razz:  

Prerequisites

Any webserver (but this guide is for Apache)

PHP 4.1.2 or higher

Mysql 3.23 or higher

Get Ampache

1. Download the latest stable Ampache package here.

2. Extract the package to site root,

```
tar -zxvf ampache-3.3.tar.gz -C /var/www/localhost/htdocs/
```

2a. Ampache now extracts to a directory of the same name as the snapshot. Paths will now be Ampache-<version> instead of ampache. You can create a soft link from ./ampache to ./Ampache-<version> if preferred. Thanks to fincoop.

```
cd /var/www/localhost/htdocs

ln -s ./Am<tab> ./ampache
```

Creating and Inserting the Ampache Database

1. Open your web browser and go to http://localhost/ampache/docs/install.php

2. Create and insert the database, ampache by providing a mysql account with database creation rights

 *Quote:*   

> Desired Database Name:	ampache
> 
> MySQL Hostname:	localhost
> 
> MySQL Administrative Username:	root
> ...

 

3. Click on 'Insert Database'

Creating a MySQL account for Ampache

Note: For those who don't like entering SQL(ie. Steps 1-3), you can use phpMyAdmin instead. I have a guide to setting it up here.

```
emerge phpmyadmin
```

1. Go into MySQL shell,

```
mysql -u root -p
```

2. Create a user, ampache (single quotes ' are required)

```
GRANT USAGE ON * . * TO 'ampache'@'localhost' IDENTIFIED BY 'ampache_password' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 ;
```

3. Grant user, ampache, SELECT, INSERT, UPDATE, DELETE, DROP, INDEX, ALTER previleges on database, ampache (single quotes ' are required)

```
REVOKE ALL PRIVILEGES ON `ampache` . * FROM 'ampache'@'localhost';

GRANT SELECT ,

INSERT ,

UPDATE ,

DELETE ,

CREATE ,

DROP ,

INDEX ,

ALTER ON `ampache` . * TO 'ampache'@'localhost';
```

Creating the ampache.cfg file

1. Ampache will attempt to write a basic ampache.cfg configuration file with your inputs onto the webserver.

 *Quote:*   

> Web Path:	/ampache/docs
> 
> Desired Database Name:	ampache
> 
> MySQL Hostname:	localhost
> ...

 

PROCEED TO "Setup Initial Account" BELOW IF 1) ABOVE SUCCEEDED

2. If nothing happens, it means write access is denied. Copy the configuration file over manually

```
cd /var/www/localhost/htdocs/ampache/config/

cp ampache.cfg.dist ampache.cfg
```

3. Open the file, ampache.cfg and uncomment/fill in the following along with other changes you may want to make

```
web_path = "/ampache/docs"

local_host = localhost

local_db = ampache

local_username = ampache

local_pass = ampache_password
```

4. Edit the permissions for ampache.cfg

```
chown apache:root ampache.cfg

chmod 600 ampache.cfg
```

5. Go back to your browser and click on "Check for Config" to ensure everything is in order.

 *Quote:*   

> Ampache.cfg Exists [ OK ]
> 
> Ampache.cfg Configured? [ OK ]

 

6. Hit "Continue to Step 3"

Setup Initial Account

1. Create your Ampache admin account

2. If you are not automatically redirected, go to http://localhost/ampache/docs/index.php

Create A Virtual Host (credit)

Note: If you are not hosting an existing website on the same server, or you do not mind long urls like http://ampache.homelinux.com/ampache/docs/ , you can skip this section.

1. Uncomment the following line in /etc/apache2/conf/apache2.conf

```
#Include conf/vhosts/vhosts.conf
```

2. Add the following into /etc/apache2/conf/vhosts/vhosts.conf

```
NameVirtualHost *:80

#THIS SECTION IS FOR YOUR EXISTING WEBSITE, SKIP IT IF YOU DO NOT HAVE ONE

<VirtualHost *:80>

ServerName arnold.homelinux.com

ServerAdmin webmaster@arnold.homelinux.com

DocumentRoot /var/www/localhost/htdocs/tikiwiki

ServerPath /tikiwiki

 <Directory /var/www/localhost/htdocs/tikiwiki>

   Order Allow,Deny

   Allow from all

 </Directory>

 Setenv VLOG /var/log/apache2/

ErrorLog /var/log/apache2/tikiwiki_error_log

CustomLog /var/log/apache2/tikiwiki_access_log combined

</VirtualHost>

#THIS SECTION IS FOR AMPACHE

<VirtualHost *:80>

ServerName ampache.homelinux.com

ServerAdmin webmaster@ampache.homelinux.com

DocumentRoot /var/www/localhost/htdocs/ampache/docs

ServerPath /ampache/docs

 <Directory /var/www/localhost/htdocs/ampache/docs>

   Order Allow,Deny

   Allow from all

 </Directory>

 Setenv VLOG /var/log/apache2/

ErrorLog /var/log/apache2/ampache_error_log

CustomLog /var/log/apache2/ampache_access_log combined

</VirtualHost>

#I ADDED THIS SECTION BECAUSE I HAD TROUBLE USING LOCALHOST/* WITHOUT IT

<VirtualHost *:80>

ServerName localhost

ServerAdmin webmaster@localhost

DocumentRoot /var/www/localhost/htdocs

ServerPath /

 <Directory /var/www/localhost/htdocs>

   Order Allow,Deny

   Allow from all

 </Directory>

</VirtualHost>
```

3. Restart apache2

```
/etc/init.d/apache2 restart
```

Setting Directories and File Permissions

Set permissions 755 for your directories and 644 for your audio files

```
chmod 755 /mnt/music/

chmod 644 /mnt/music/*
```

Finally...

1. Open your browser and surf to your virtual host, http://ampache.homelinux.com

Note: Get your own dynamic DNS here

2. Enjoy Ampache: for the love of music!  :Very Happy: 

----------

## watorin

Nice howto. Thanks

----------

## amiatrome

bump because I am enjoying my streamed mp3 from work.  :Twisted Evil: 

watorin, have you tried it out? Any comments?

----------

## HOHCEHC

ok i tried howto but sql gives me errors when i try give user amapche privileges

----------

## amiatrome

Ah my bad. There was a mistake in the query, an extra space in the last line between @ and 'localhost'.  :Embarassed: 

It's fixed now.  :Very Happy: 

----------

## TheZog

I installed this today as a lazy Sat. afternoon project and I'm quite pleased.

It works very well, good interface, etc. I recommend it also.

Now I just have to clean up all my ID3 tags.   :Razz: 

----------

## Zyne

This is indeed a great way to share your music over the network!

Now I just gotta find a way to add about 300 albums to the database at once  :Smile: 

Thanks for the howto amiatrome!

----------

## amiatrome

Glad you guys found it useful!  :Very Happy: 

----------

## riksta

 *TheZog wrote:*   

> I installed this today as a lazy Sat. afternoon project and I'm quite pleased.
> 
> It works very well, good interface, etc. I recommend it also.
> 
> Now I just have to clean up all my ID3 tags.  

 

You might want to look at a program with MusicBrainz support to clean up your tags, it can take a digital fingerprint of your music and automatically tag it if it finds a match in the massive database  :Smile: 

----------

## basiaf

does downsampling work for you ? Last time I tried I couldn't get it to work...

// d'oh.. fixed it by not using the outdated ampache.php.dist.de

----------

## coutts99

Ampache ebuild

https://bugs.gentoo.org/show_bug.cgi?id=93544

----------

## fincoop

[quote="amiatrome2. Extract the package to site root,

```
tar -zxvf ampache-3.3.tar.gz -C /var/www/localhost/htdocs/
```

[/quote]

Ampache now extracts to a directory of the same name as the snapshot, perhaps include a 2a step to create a link?

```

cd /var/www/localhost/htdocs

ln -s ./Am<tab> ./ampache

```

Or perhaps just define it in the vhosts, but i think the link is easier to maintain. Thanks!

----------

## fjf3

You should update it. I found it very useful, but now there is no ampache/docs anymore and the installation script is pretty sweet. Besides that it made my life a LOT simpler than if I had to figure it out by myself.

----------

## fjf3

Anyone knows who is maintaining the ebuild? I added ~ppc to my package.keywords so it would build on my amd64 system. It is working fine so far. I think it is almost 100% php so there is nothing to link to or anything like that. Well if anyone here knows, ~amd64 is fine so far.

----------

## amiatrome

Hey guys, sorry for the delay. Busy like a bee recently.

fjf3, would you mind showing me what is the new ampache ebuild dir structure so I can update the howto? Where is the install script now? Is it sufficient to just strip docs/ from all the current paths? Thanks.  :Smile: 

----------

## PChaos

The ampache ebuild is a nice thing. It installs into some dir from where you can install it as an webapp. but emerge gives a nice instruction to this.

If you maybe give the host for your ampache as ampache.homelinux.net on my system everything went to /var/www/ampache.homelinux.net/htdocs/ampache/...

Just set up a proper vhost and you will be able to run http://ampache.homelinux.net/install.php from your browser.

The install.php is able to create as well the database as the neccessary cfg file and asks to create an initial login.

Note: to run ampache i still have my apache2 towd to the totem pole. This little indian ***** somehow refuses to open my index.php and allways asks me to download the index.php. To make it really weird, i was able to open install.php as well as I am able to open login.php.

----------

## Ghent

Okay so, installation went pretty smoothly and I have it up and running for the admin account now and I have to say, I love it (awesome howto) but I do have one little problem. While I myself can log in as admin no user accounts can login. They simply give me the error "Error Access Denied"

I'm not sure what the deal is here but I'd like to be able to share this with a few people without giving them admin. Anybody know what I'm doing wrong?

-Tim

----------

## Phantomal

 *fjf3 wrote:*   

> Anyone knows who is maintaining the ebuild? I added ~ppc to my package.keywords so it would build on my amd64 system. It is working fine so far. I think it is almost 100% php so there is nothing to link to or anything like that. Well if anyone here knows, ~amd64 is fine so far.

 

Ampache is not 100% PHP. it uses PERL Scripts to do some things like retagging MP3s or other cool Things in Future.

But hey, PERL Should work on your AMD64 too. So no problem  :Wink: 

Greetz

Phanti

----------

## denstark

AMAZING howto. Set up was easy as pie, and this peice of software is amazing. Thank you.

----------

## bol

For some reason the mysql-queries didn't work for me, but with phpmyadmin it worked just fine.

Great howto anyway.

Thanks!  :Smile: 

----------

## Mobeater

For the life of me, I can not figure out where the music goes, I simply tried uploading as a test, it does not error out, then again, it does not put my music anywhere to be seen...have Upload turned on, and tried with Quarentine on and off....no dice.

Any help would be great!

Thanks Mob_Eater

----------

## jaycemil

Has anyone here managed to get the XML-RPC in Ampache working on Gentoo?  If so, were there any tricks?

----------

## slestak

I am trying to get this to work with SSL_DEFAULT_VHOST enabled in /etc/conf.d/apache2.

In the admin preferences, I have set force_http_stream to true, and the m3u playlist files that song.php creates do contain http:// instead of https, but no player can play them.  I think the SSL_DEFAULT_VHOST must be forcing everything to port 443.

The ui works fine with https, i just cant stream.  

I do not have any rewrite rules in httpd.conf becasue the force_http_stream (or play, im going from memory) makes appropriate http urls.

----------

## jaycemil

I'm also going on vauge memory so I may be completely off but...  SSL_DEFAULT_VHOST should only pickup port 443.  Do you also have DEFAULT_VHOST defined or no?  If not then IIRC you won't get any response on port 80.

----------

## slestak

 *jaycemil wrote:*   

>  Do you also have DEFAULT_VHOST defined or no?  If not then IIRC you won't get any response on port 80.

 

You are awesome.  Thx.  Ive been working on this for a week.  Didnt know I needed both.

Now to figure out sln for mpd + ssl.  It chokes on https as well.

----------

## slestak

well, to amend my earlier posting, ampache streaming now works with both DEFAULT_VHOST and SSL_DEFAULT_VHOST setup, but nothing prevents port 80 use for all webapps.  I guess I need mod_rewrite rules still...

----------

## lecleremi

Hi

I made one of the stupidest thing ever recently. I followed the brilliant howto and managed to install ampache. Everything was doing just fine. I created 5 users and I began to play with all this stuff. At this point, I disabled my admin account... I know this sounds ridiculous (In fact, it is...) but I was testing all kind of things and it happened.

Any help?

Thx in advance.

----------

## lecleremi

ok that was a false alarm. This is the answer (in case someone would ever be as dumb as me): 

# nano /var/www/localhost/htdocs/config/ampache.cfg.php

find the section # Use auth?

replace "yes" by "no":

use_auth        = "no"

Then log in as Admin and set access to disable (I don't understand why when access is disable you can access though when it is enable you can't...) and reverse the previous process.

 :Embarassed:  Maybe this will help someone.

bye.

----------

## m4chine

Does ampache need a sound card to stream? I've checked everywhere, ampache website, forums, but no where could I find any mention of a need for a sound-card.

I've got ampache up and running on a server w/o a sound card, trying to just stream audio; I created a catalog and a playlist. When I download/attempt to play the play list via xmms, xmms just becomes unresponsive and I end up having to SIGTERM it.

Any suggestions? Thanks.

----------

## m4chine

To answer my own question, no you do not need a sound card to stream.

For the answer to my problem: 

MAD MPEG Decoder is the culprit. I disabled MAD and let MPEG-123 take over, and I can now stream from ampache. See http://ampache.org/forums/viewtopic.php?p=4103 for the original post.

cheers.

----------

## soldstatic

ok I'm having a problem.

I've had ampache installed on a server forever, it was running under windows. 

Now that I am turning into a linux guy, (still very noob), i need to set up my server.

Emerged, got ampache all set up, but now I have a problem:

the harddrive hdb1 is ntfs, its from the windows partition. its where all my music is. and I need to leave it as ntfs.

I can su and mount it, no problem, even play from it, as long as i'm root....

But ampache can't catalog it, and as group users can't play from it that sucks too... 

since I mount it read only (which I would prefer to keep doing), I can't chmod, or chgroup, ....?!?!??????????

HEEEEEEEELP PLEEEEEEEASE its been bugging me for the past week and a half.

----------

## soldstatic

found this:

http://www.mepis.org/node/7076

So the fstab line that did it for him was:

```

/dev/hda1 /mnt/hda1 ntfs auto,users,exec,ro,umask=0222 0 0
```

but i narrowed it down to just the umask, whatever that does lol...

so my line in fstab is:

```

/dev/hda1 /mnt/hda1 ntfs noauto,users,ro,umask=0222 0 0
```

So yea anyyyyyway

----------

## Icer

Rock'n'roll! What an awesome system!  :Smile:   :Very Happy:  No need to take iPod into work anymore. Just need to buy decent headphones.

I see there are many similar features as in amarok. Amarok uses mysql to store much info about the songs ad also the album art. I feel like I've done some things twice now. :p That's only thing dissapointing now.

Also I got weird error when trying to chmod some music files:

```
# chmod 644 music-folder/*

bash: /usr/bin/chmod: Argument list too long
```

Anybody know what's that about? There's gazillion files in the folder other than that I dont know what would prevent chmodding the files.

Anyway ... this is just awesome.  :Smile: 

----------

## soldstatic

no clue about the argument list thing... but as far as amarok, I'm not sure.  I like ampache better cause you can install it with only php, apache, ampache, and music. Great for my webserver which can then take the installation on my home computer's catalog as a source. I dunno just seems nice to have an easy to install music server. 

my only wish is that it would do videos for me too.  :Sad: 

----------

## Icer

Btw, has anybody tried the latest ebuild? 3.3.2.2beta if I recall correctly. Is it working? I just got the 3.3.1.7 working ok.

When I was talking about the amarok vs ampache I meant that both use mysql and made their own database's and entries there. That's f***n redundant to put it mildly.  :Smile:  There should be a standard way to store the data. amarok and ampache could then be used as a interface on top of the music db.

----------

## soldstatic

i've got mine running whatever is latest on the svn. the zip download isnt working on my nokia 770, but haven't figured out if its mine or amp's

----------

## Icer

Lol, your trying to use ampache inside 770? Well good luck. Please keep us informed how it goes. This is interesting.  :Smile: 

I was thinking to purchase a 770 and use it as a music player on university and work and play music which I have in home. Have you tried that? As far as I know it should work. 770 has the real player in it so cant see problems for that use case.

Other use case I was thinking is using 770 as a tv-remotecontrol. I have mythtv in my pc and I was thinking to setup mythweb too so I can for example at university checkout what's up in tv and schedule a recording without needing to leave the lecture.  :Smile:  Not to mention that you could use it as a normal remote control when your at home.

Oh... I should propably mention that we have good wlan coverage both in work and in university. Actually there is a public wlan coverage available in the whole city.  :Very Happy: 

----------

## soldstatic

Actually I've been using the 770 and ampache for awhile now. works perfectly. I now have an effective 200+GB solution for an ipod. not only can i stream any/all of my music, nut i can also use it as a download manager type thing. i can ''reload'' anytime i want.

I also use coppermine photo gallery to organize, download and stream videos. Theres a script on maemo, the 770 dev site, that can strip/reformat optimized vids for the 770. works really well, with little time required to buffer etc. 

get a 770. if youve got wlan then you will nver think about ipods again. there are a couple of things that could be improved but as is this thing is way beyond the mainstream market i think.

----------

## Icer

Awesome!  :Smile:  Heh, might sell the iPod away. However there are places where there's no network at all. Anyway while in the city 770 is a very attractive option and not least because of ampache.   :Cool:   Right on, I must get one 770 asap.   :Very Happy: 

----------

## soldstatic

well amazon has decent deals for 1gb cards. boughrt a 512mb than the gb for the same price. thats plenty for 2hr mivie and lots of music. then if im on campus i can dl a dif movie or reload with dif mp3s.

plus with ssh if im on wlan i cn do whateer. and i have tight vnc viewer so i can access other pcs w/ gui if need be

----------

## Icer

I tried ampache at work today on 770. It works allright however I had few 192kbit/s encoded songs on home pc and they didnt work. I guess it's because of realplayer? There was somekind of downsample option in preferences. What does it mean? Can I have ampache transcode all songs to be 128kbit/s?

Just for comparison I tried ampache with a S60 phone. Well it can be used but the usability is horrible compared to 770. Also the song I tried didnt play but it could be same issue as I mentioned above.

----------

## soldstatic

not sure what happened to your 192s, but my guess is that they were ripped  funny or somethin... all my tracks are 192 and works fine.

most of the other ?s you sould ask at ampahe forums.

----------

## Icer

Ok, I'll check the songs with other than realplayer player. Btw your not using other media player with 770 by chance?

Looks like I might have to upgrade ampache to newer version to get better downsampling options.

Edit: Just checked that the songs which didnt play at work when played with realplayer in 770 work ok at home when played with gxine and amarok.

----------

## soldstatic

hmm... i'm just using the audio player that ame built in, my stream is in  .pls format... mp3s ripped @ 192.... dunno dude...

----------

## Icer

Well I tried again at work and the files play ok, regardles of bitrate. I did some tweaks however I dont recall at the moment what I changed. The problem with playing the few files could have been due to poor wlan coverage at that moment. After all I was trying to play the files using the 770 which needs wlan connection. 

Also I updated the GCC and after update both ampache and worpress web pages didnt work. So I re-emerged the packages. There's the note printed after the emerge telling you to install the app in your virtual host. So I did that and it fixed ampache. So no need to reinstall databases etc. Cool.   :Cool: 

----------

## soldstatic

 :Cool:  8)sweet

----------

## dem1an

do you guys chroot apache?  I'm lost in trying to make this work.  i chrooted apache, but I'm not sure what to do with mysql, php, ampache and everything else.  a walk-thru would be awesome.

----------

## soldstatic

perhaps you could describe your setup...

----------

## JROCK2004

cool stuff

----------

## Disparu

http://localhost/ampache/install.php

just shows a bunch of code, but according to the tes.php file php is running fine, why wont it work?

----------

## JROCK2004

do you have webserver with php and mysql setup?

----------

## Disparu

sure do, i got apache2 running and all that good stuff and when i go to http://localhost/ampache/test.php aka the test page for php mysql etc it says i check out and everything is running minus the databases below because i have yet to get to that part yet.

----------

## JROCK2004

is your webserver local only? If not can you give me sitename so I can go to it and see it?

----------

## Disparu

 *JROCK2004 wrote:*   

> is your webserver local only? If not can you give me sitename so I can go to it and see it?

 

yeah it is local only at the moment

----------

## JROCK2004

could you post the error message or at least some of it?

----------

## Disparu

after re installing php and apache countless times i restarted mysql and apache and now it magically works!

----------

## Disparu

ok i pretty much cleared up alll the previous problems, but am having trouble gettings ampache to be viewable outside of my own network...anyone have a quick rundown on this? i have port 80 forwarded on my router for my network IP and when i access ampache via my cable modems IP it works, but anyone outside of the network cant access anything

----------

