From Campworld

LinuxServersFC7: HOWTO Fedora Core 7 Virtual Web Hosting With Apache MYSQL and ProFTPD

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.

Setting Up The Base Server

Install Softwre

Well the only thing we need to install is proftpd with mysql support. Type:
> yum remove vsftpd
> yum install proftpd proftpd-mysql

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 called 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 $

# Load modules for sql support
LoadModule mod_sql.c
LoadModule mod_sql_mysql.c

# Server config
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
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
SQLBackend          mysql
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

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/LinuxServersFC7/FC7VirtWWWServer
Page last modified on August 19, 2007, at 05:53 PM