From Campworld

LinuxServers: Virtual Web Hosting with Apache MYSQL and ProFTPD on Fedora Core 4 HOWTO

History / Status

Introduction

There are many ways to do virtual websites under linux. The technique I am going to use is multiple domains on one ip address. I also didn't want to use system users for the virtual hosts. So I decided to use a mysql database to store the virtual user information.

Instaall Softwre

Well the only thing we need to install is proftpd with mysql support. If you want to build it yourself see my page on that.

  1. Type:
    > rpm -ivh http://www.campworld.net/repos/FC4/proftpd-1.2.10-4_mysql.i386.rpm

Configuring Apache

  1. First thing is to create a linux user to hold all the virtual directories. Log in to webmin and create a user call virtwww.
  2. Create the virtual host config file. We will use the name the brouser passes to us to determin the website to load. Type
    > echo "UseCanonicalName Off" > /etc/httpd/conf.d/virtual.conf
    > echo "VirtualDocumentRoot /home/virtwww/%0" >> /etc/httpd/conf.d/virtual.conf
  3. restart apache
    > service httpd restart
  4. Make a directory with your server's ipaddress as its name. Example
    > mkdir /home/virtwww/192.168.1.100
  5. create a test index.html page in your new directory.

Configuring ProFTPD

  1. Create the following proftpd config file
    > nano -w /etc/proftpd.conf
 # This is the ProFTPD configuration file
# $Id: proftpd.conf,v 1.1 2004/02/26 17:54:30 thias Exp $
ServerName                      "YourSite FTP server"
ServerType                      standalone
ServerAdmin                     admin@yoursite.com
ServerIdent                     on "FTP Server ready."
DeferWelcome                    off
DefaultServer                   on
Port                            21
Umask                           022
MaxInstances                    10
User                            ftp
Group                           ftp
DefaultRoot                     ~ !adm
AllowOverwrite                  on

# Do not perform ident nor DNS lookups (hangs when the port is filtered)
IdentLookups                    off
UseReverseDNS                   off

# Default to show dot files in directory listings
ListOptions                     "-a"

# Allow to resume not only the downloads but the uploads too
AllowRetrieveRestart            on
AllowStoreRestart               on

# This is where we want to put the pid file
ScoreboardFile                  /var/run/proftpd.score

# virtual www / ftp users configuration
# mysql settings for authentication
# Be sure to substitute your passord for PASSWORD
SQLAuthTypes                    Plaintext Crypt
SQLConnectInfo                  ftp@localhost proftpd PASSWORD
SQLUserInfo                     ftpuser userid passwd uid gid homedir shell
SQLGroupInfo                    ftpgroup groupname gid members
SQLMinID                        500
SQLHomedirOnDemand              on
SQLLog                          PASS updatecount
SQLNamedQuery                   updatecount UPDATE "count=count+1, accessed=now() WHERE userid='%u'" ftpuser
SQLLog                          STOR,DELE modified
SQLNamedQuery                   modified UPDATE "modified=now() WHERE userid='%u'" ftpuser

# User quotas
# uncomment the following section to enable user quotas
#QuotaEngine                    on
#QuotaDirectoryTally            on
#QuotaDisplayUnits              Mb
#QuotaShowQuotas                on
#SQLNamedQuery                  get-quota-limit SELECT "name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avail, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail FROM ftpquotalimits WHERE name = '%{0}' AND quota_type = '%{1}'"
#SQLNamedQuery                  get-quota-tally SELECT "name, quota_type, bytes_in_used, bytes_out_used, bytes_xfer_used, files_in_used, files_out_used, files_xfer_used FROM ftpquotatallies WHERE name = '%{0}' AND quota_type = '%{1}'"
#SQLNamedQuery                  update-quota-tally UPDATE "bytes_in_used = bytes_in_used + %{0}, bytes_out_used = bytes_out_used + %{1}, bytes_xfer_used = bytes_xfer_used + %{2}, files_in_used = files_in_used + %{3}, files_out_used = files_out_used + %{4}, files_xfer_used = files_xfer_used + %{5} WHERE name = '%{6}' AND quota_type = '%{7}'" ftpquotatallies
#SQLNamedQuery                  insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" ftpquotatallies
#QuotaLimitTable                        sql:/get-quota-limit
#QuotaTallyTable                        sql:/get-quota-tally/update-quota-tally/insert-quota-tally

RootLogin off
#RequireValidShell off

# Normally, we want users to do a few things.
<Global>
  AllowOverwrite                yes
  <Limit ALL SITE_CHMOD>
    AllowAll
  </Limit>
</Global>

# Define the log formats
LogFormat                       default "%h %l %u %t \"%r\" %s %b"
LogFormat                       auth    "%v [%P] %h %t \"%r\" %s"

Setup MySQL database for proftpd

Use the following SQL to create the ftp database

 
-- phpMyAdmin SQL Dump
-- version 2.6.2-pl1
-- http://www.phpmyadmin.net
-- 
-- Host: localhost
-- Generation Time: Dec 18, 2005 at 05:30 PM
-- Server version: 4.1.14
-- PHP Version: 5.0.4
-- 
-- Database: `ftp`
-- 
CREATE DATABASE `ftp` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE ftp;

-- --------------------------------------------------------

-- 
-- Table structure for table `ftpgroup`
-- 

CREATE TABLE `ftpgroup` (
  `groupname` varchar(16) NOT NULL default '',
  `gid` smallint(6) NOT NULL default '5500',
  `members` varchar(16) NOT NULL default '',
  KEY `groupname` (`groupname`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='ProFTP group table';

-- --------------------------------------------------------

-- 
-- Table structure for table `ftpquotalimits`
-- 

CREATE TABLE `ftpquotalimits` (
  `name` varchar(30) default NULL,
  `quota_type` enum('user','group','class','all') NOT NULL default 'user',
  `per_session` enum('false','true') NOT NULL default 'false',
  `limit_type` enum('soft','hard') NOT NULL default 'soft',
  `bytes_in_avail` int(10) unsigned NOT NULL default '0',
  `bytes_out_avail` int(10) unsigned NOT NULL default '0',
  `bytes_xfer_avail` int(10) unsigned NOT NULL default '0',
  `files_in_avail` int(10) unsigned NOT NULL default '0',
  `files_out_avail` int(10) unsigned NOT NULL default '0',
  `files_xfer_avail` int(10) unsigned NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

-- 
-- Table structure for table `ftpquotatallies`
-- 

CREATE TABLE `ftpquotatallies` (
  `name` varchar(30) NOT NULL default '',
  `quota_type` enum('user','group','class','all') NOT NULL default 'user',
  `bytes_in_used` int(10) unsigned NOT NULL default '0',
  `bytes_out_used` int(10) unsigned NOT NULL default '0',
  `bytes_xfer_used` int(10) unsigned NOT NULL default '0',
  `files_in_used` int(10) unsigned NOT NULL default '0',
  `files_out_used` int(10) unsigned NOT NULL default '0',
  `files_xfer_used` int(10) unsigned NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

-- 
-- Table structure for table `ftpuser`
-- 

CREATE TABLE `ftpuser` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `userid` varchar(32) NOT NULL default '',
  `passwd` varchar(32) NOT NULL default '',
  `uid` smallint(6) NOT NULL default '5500',
  `gid` smallint(6) NOT NULL default '5500',
  `homedir` varchar(255) NOT NULL default '/home/virtwww/',
  `shell` varchar(16) NOT NULL default '/sbin/nologin',
  `count` int(11) NOT NULL default '0',
  `accessed` datetime NOT NULL default '0000-00-00 00:00:00',
  `modified` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `userid` (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='ProFTP user table' AUTO_INCREMENT=30 ;

Execute the following sql to create the ftp user

   
grant select on ftp.* to proftpd@localhost identified by 'PASSWORD';
flush privileges;

Execute the following sql to create the ftpgroup and sample ftp virtual host user

  
-- phpMyAdmin SQL Dump
-- version 2.6.2-pl1
-- http://www.phpmyadmin.net
-- 
-- Host: localhost
-- Generation Time: Dec 18, 2005 at 05:56 PM
-- Server version: 4.1.14
-- PHP Version: 5.0.4
-- 
-- Database: `campworld`
-- 

-- 
-- Dumping data for table `ftpgroup`
-- 

INSERT INTO `ftpgroup` (`groupname`, `gid`, `members`) VALUES ('ftpgroup', 5500, 'ftpuser');
INSERT INTO `ftpgroup` (`groupname`, `gid`, `members`) VALUES ('ftpgroup', 5500, 'ftpguest');

-- 
-- Dumping data for table `ftpuser`
-- 

INSERT INTO `ftpuser` (`id`, `userid`, `passwd`, `uid`, `gid`, `homedir`, `shell`) VALUES (1, 'sample.com', 'PASSWORD', 5500, 5500, '/home/virtwww/www.sample.com', '/sbin/nologin');

Conclusion

That's the complete setup. At this point there is no simple gui for adding and removing users. Your best bet is to use the tools we've installed.

Links

proftpd - http://www.proftpd.org

Comments

Retrieved from http://www.campworld.net/thewiki/pmwiki.php/LinuxServers/FC4VirtWWWServer
Page last modified on May 30, 2007, at 06:32 PM