views:

2020

answers:

4

Simple question, but for some reason I couldn't find the exact answer on Google:

I have a fresh Ubuntu install on Slicehost, and would like to make a public directory in my home dir for a simple website containing a bunch of static HTML files. How do I do this? Is it just a matter of typing mkdir public_html and setting the permissions, or is there a cleaner way? (I remember in the past I've had issues where every time I copied a file into my public_html directory, I would have to manually set its permissions, which was quite frustrating.)

+1  A: 

You need to use mod_userdir for Apache, otherwise you need to set up symlinks from /var/www/ or wherever.

Your permissions issue is because Apache does not have read access to your files. You need to allow read access to www-data (or whatever the user is; distro-specific).

strager
+4  A: 

Assuming you've already installed apache, do the following:

sudo a2enmod userdir
sudo /etc/init.d/apache2 restart

The first command enables the userdir apache mod, which does exactly what you want. The second restarts apache so that it starts using the new configuration.

To install apache2:

sudo apt-get install apache2

Of course, you'll also need to make sure that the permissions on your public_html folder allow the www-data user to see the files in there -- 755 usually works well. To do this:

chmod -R 755 ~/public_html

This will recursively (-R) go through your public_html and set the permissions to 755 (owner rwx, and both group and other r-x, r-x).

rz
+1  A: 

The other answers are on the right track with mod_userdir, but using that will give your website the base URL http://www.yourdomain.com/~username/ - for instance, a file /home/username/public_html/index.html would be accessible as http://www.yourdomain.com/~username/index.html. If you want your files to be accessible under the domain root, as http://www.yourdomain.com/index.html for example, then you'll need to put the directive

DocumentRoot /home/username/public_html

in the Apache configuration file.

By the way, this kind of question is more suited for the Slicehost Forums.

David Zaslavsky
A: 

I,m actually looking for doing something similar. see i have alot of data that i certainly dont whant to put at the same place due to the size. aldo i would like to represent them in a folder system that do not represent the real folder system. i tryed the --bind function but it actualy do not give real access since the right still the same. now how do you give specefic right to a cecific user on a specific folder in linux, in windows it is quite simple you just add the user to the user access list and then set the right. the action that i would like to accomplish is give only read access to the user that appache use. the chmod 775 will certainly work but it do not sepcify any user and i would like to be able to not have to set the right to every one when in fact i what to give the right to a very specific user or group.