Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I create web accessable user profiles on Ubuntu server

Posted on 2011-05-05
19
Medium Priority
?
569 Views
Last Modified: 2013-12-15
I've setup an Ubuntu 11.04 server

Apache and FTP are enabled and working.

Is there a way to link the machine's name/IP address to home directories?  IFor example, "http://machineiporname/~username"

'd like for students to FTP web pages to their home directories, and have those pages accessable via the web.

I've seen this type of setup with some ISP's and am trying to replicate it locally.
0
Comment
Question by:Randyp53
  • 11
  • 8
19 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 35700658
Yes, it is not hard at all.

Traditionally, on most Unix/Linux you have to have a folder public_html.  Anything under that folder is seen exactly as you described, however, it has to be configured on Apache.

In Apache, you have to have
UserDir public_html

Please check that.

Then suppose you put the following file ~username/public_html/index.html
<html>
<h1>Student Home Page</h1>
</html>

Then you would be able to access it exactly as you described.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35700679
If it doesn't work, then there is either a permission issue--path has to be world reachable (other's permission for each folder in the path has to be at least executable).  I would make permission of public_html as 755
chmod 755 ~/public_html
0
 

Author Comment

by:Randyp53
ID: 35700708
So you create the  "public_html" in the users home directory?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:farzanj
ID: 35700719
Precisely.

So you go to the home directory

cd ~username
mkdir public_html
0
 

Author Comment

by:Randyp53
ID: 35700824
Not getting there yet.  I've created the public_html directory and assigned 0755 for rights.  Here's the url I'm using:

http://ip address/~username/public_html/index.htm

What tells Apache to point to the home directory?  Is it the ~ ?  Or is that a configuration entry?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35700840
NO
http://ip_ADDR/~username/index.html

index.html is optional

SO this should also work
http://ip_ADDR/~username
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35700863
Yes, ~username tells Apache the path of user's home directory.

Then in the Apache configuration file, which I think in Ubuntu is apache.conf, you should have UserDir tag set to public_html

UserDir public_html

And also you should have the module enabled for it

mod_userdir

Make sure it is included in the list of modules and is uncommented.
0
 

Author Comment

by:Randyp53
ID: 35700972
Don't see those entries in the file.  It appears to be Apache2.conf in Ubuntu.  Perhaps they have to be added manually?

Here's the contents:

# Based upon the NCSA server configuration files originally by Rob McCool.
#
# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.2/ for detailed information about
# the directives.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# The configuration directives are grouped into three basic sections:
#  1. Directives that control the operation of the Apache server process as a
#     whole (the 'global environment').
#  2. Directives that define the parameters of the 'main' or 'default' server,
#     which responds to requests that aren't handled by a virtual host.
#     These directives also provide default values for the settings
#     of all virtual hosts.
#  3. Settings for virtual hosts, which allow Web requests to be sent to
#     different IP addresses or hostnames and have them handled by the
#     same Apache server process.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "foo.log"
# with ServerRoot set to "/etc/apache2" will be interpreted by the
# server as "/etc/apache2/foo.log".
#

### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation (available
# at <URL:http://httpd.apache.org/docs/2.2/mod/mpm_common.html#lockfile>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
LockFile ${APACHE_LOCK_DIR}/accept.lock

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15

##
## Server-Pool Size Regulation (MPM specific)
##

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadLimit: ThreadsPerChild can be changed to this maximum value during a
#              graceful restart. ThreadLimit can only be changed by stopping
#              and starting Apache.
# ThreadsPerChild: constant number of worker threads in each server process
# MaxClients: maximum number of simultaneous client connections
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# event MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxClients: maximum number of simultaneous client connections
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_event_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#

AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>

#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain


#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

# Include module configuration:
Include mods-enabled/*.load
Include mods-enabled/*.conf

# Include all the user configurations:
Include httpd.conf

# Include ports listing
Include ports.conf

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
Include conf.d/

# Include the virtual host configurations:
Include sites-enabled/
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35701025
This looks very incomplete file.  You don't even have any virtual server configured.

Yes, I would try to manually add

UserDir public_html

At the bottom and see what happens after restarting the apache service.  If it doesn't work, look for apache logs.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35701081
Cannot believe the basic configuration file on Ubuntu looks so different from Redhat series.

Anyway, please follow the following link, it may be great help to you, especially the last comment.

http://ubuntuforums.org/showthread.php?t=143350
0
 

Author Comment

by:Randyp53
ID: 35701158
I must be missing a module.  I get the below error when trying to restart Apache.

Invalid command 'UserDir', perhaps misspelled or defined by a module not included in the server configuration
Action 'start' failed.
The Apache error log may have more information.
   ...fail!


Does usermin have to be loaded?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35701188
Please follow the last comment on this page


http://ubuntuforums.org/showthread.php?t=143350
0
 

Author Comment

by:Randyp53
ID: 35701205
Hold the horses.  I enabled "userdir" and I'm now getting a "forbidden" error.  It's progress.  The public_html directory is set to 755.  
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35701219
Your path is wrong or permissions.
0
 

Author Comment

by:Randyp53
ID: 35701234
error indicates permissions
0
 
LVL 31

Accepted Solution

by:
farzanj earned 2000 total points
ID: 35701257
What is the permission of index.html?  It would be 755 as well

Suppose the ~username has path

/home/username/

Then do

ls -ld /home
ls -ld /home/username

All of these directories should have 'x' in others part
 rwx??? ??x
0
 

Author Comment

by:Randyp53
ID: 35701303
That's was the problem.  I need to set the public_html for read and execute for group and others.  I suppose I can do this automatically when I create new users.  
0
 

Author Closing Comment

by:Randyp53
ID: 35701312
Very patient -- thanks for the help.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35701324
You can.  You can put this in /etc/skel directory with the correct permissions.  Because files from /etc/skel are copied over to the newly created user directory.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question