.htaccess

14 09 2008

So after I made my music available in my web root, I felt it necessary to password protect it. I don’t want anyone to download my music or stream it or anything like that. No one except me, that is. No illegal activity should be coming from my server I figured. So I thought of the most basic way to do it which was htaccess.

Basically, you create a file called .htaccess with certain parameters. Here’s mine:

AuthType Basic
AuthName "Music"
AuthUserFile /var/.htpasswd
require valid-user

I’m not exactly sure what

AuthType

is, but

AuthName

is whatever you wanna call the folder you’re protecting. It doesn’t change the folder name, this is just what shows up in the little login window that pops up when you navigate to this folder.

AuthUserFile

is where the .htpasswd file is stored. The .htpasswd file specifies which user and password combinations are allowed to access this folder.

require valid-user

just lets it know that any valid user specified within the .htpasswd file is required for access.

In .htpasswd, each individual user should have his own line, and username and password should be seperated by a colon. i.e.

username:password
username:password

Finally, in your apache settings, specifically if you’re using Ubuntu the file will be located at /etc/apache2/sites-available/default. Find the line

AllowOverride None

and change it to

AllowOverride All

Advertisements




Real Quick

10 09 2008

Sorry for the two short posts after each other, but this is definitely worth a mention.

With the external HDD working, and everything being saved on there, I wasn’t sure how to make it accessible without having to connect via FTP every time. More importantly, everyone doesn’t necessarily wanna download every song they wanna listen to, so streaming is nice.

Since all the music and pictures are saved outside the webroot (/var/www/) I wasn’t sure how to make them accessible within the webroot. Well, after searching around, I found this line. It creates what’s called a Symbolic Link. For those familiar with windows, it’s basically like a shortcut, except it’s a little different because it treats it as though the files are saved in the location where the link is. I don’t know if I did a good job of explaining that, but you’ll see what I’m talking about if you have to do this for yourself. So the line is

sudo ln -s source_file my_file

The sudo gives you the correct permissions to do this, which is necessary in Ubuntu. source_file gets replaced with the path to the file (or folder) you wanna make the symbolic link for. my_file gets replaced with the path where you want to place this link.

So now when I open up my page and click on the music link, it takes me to all my music and I can stream it straight through my browser. Pretty sweet!