Setting up individually accessible public_html for each user of a linux machine

I have a dedicated server on which I have a site http://www.example.com

I need to create a user and:

  • allow him ssh and ftp access into it
  • allow him to access a page such as: http://user.example.com

  1. How do I provide ftp access to him?
  2. How do I setup public_html and all necessary details so that he can access html file from the internet? I want him to be able to execute php scripts as well (which I dont think should be a problem as the website on this site can do it already).

I don't have cPanel. I am running RHEL5/CentOS


Edit1

In httpd.conf I added this:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName www.example.com
  DocumentRoot /var/www/html/
</VirtualHost>

<VirtualHost *:80>
  ServerName david.example.com
  DocumentRoot /home/david/public_html
</VirtualHost>

<VirtualHost *:80>
  ServerName matthew.example.com
  DocumentRoot /home/matthew/public_html
</VirtualHost>

And made sure the corresponding folders existed with 755 permissions.

I have the main site accessible now, but not the subdomain.example.com ones.


Solution 1:

You use mod_userdir to set up public_html and directories that allow users to have websites on your machine.

If you only need this for one user you can also set up a plain virtual host to that directory. EG:

Listen 80
NameVirtualHost *

<VirtualHost *>
  ServerName www.yourdomain.com
  DocumentRoot /var/www/html/
</VirtualHost>

<VirtualHost *>
  ServerName subdomain.yourdomain.com
  DocumentRoot /home/username/public_html/
</VirtualHost>

If you have multiple usernames you want to create VirtualHosts for, you have a few options. The first is to write them out explicitly in your httpd.conf. The second is to use mod_rewrite to look for unknown hostnames and translate them to the default user directory http://yourhostname.com/~username/.

That takes care of the Web aspect of it. For the FTP aspect a daemon such as ProFTPd's DefaultRoot takes care of user directory FTP access. For DNS you could create a wildcard A entry to point the *.yourdomain.com to your server's IP address.

As a side note, please edit this question with the information your provided on your question on StackOverflow (and was eventually ported to ServerFault) so that we do not have duplicate questions floating around. Thanks!