From Campworld

LinuxServersCentOS: HOWTO CentOS 5.x 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

For a dedicated server start with the base server setup for CentOS 5.x.

Install Softwre

We need to install is proftpd with mysql support. Type:
> yum -y remove vsftpd
> yum -y install proftpd proftpd-mysql

Now lets download and install proftpd admin.
> wget http://downloads.sourceforge.net/proftpd-adm/proftpd_admin_v1.2.tar.gz
> tar -xzvf proftpd_admin_v1.2.tar.gz
> mv proftpd_admin_v1.2 /usr/share/proftpd_admin

Configuring Apache

  1. First we need to create a user called virtwww. We will also make the directory world writable.
    > adduser -m virtwww
    > passwd virtwww
    > chmod a+rwx /home/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
    > mv proftpd.conf proftpd.conf.old
    > nano -w /etc/proftpd.conf
 
# This is the ProFTPD configuration file

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

ServerName                      "Servername"
ServerType                      standalone
ServerIdent                     on              "Servers identifying string"
DeferWelcome                    off
DefaultServer                   on
DefaultRoot                     ~ !adm
AllowOverwrite                  on
UseReverseDNS                   off
IdentLookups                    off

Port                            21
Umask                           022
MaxInstances                    15
MaxClientsPerHost               3               "Only %m connections per host allowed"
MaxClients                      10              "Only %m total simultanious logins allowed"
MaxHostsPerUser                 1

User                            ftp
Group                           ftp

ScoreboardFile                  /var/run/proftpd.score

# Some logging formats
LogFormat                       default         "%h %l %u %t \"%r\" %s %b"
LogFormat                       auth            "%v [%P] %h %t \"%r\" %s"
LogFormat                       write           "%h %l %u %t \"%r\" %s %b"

# Define log-files to use
TransferLog                     /var/log/proftpd/xferlog
ExtendedLog                     /var/log/proftpd/access_log    WRITE,READ write
ExtendedLog                     /var/log/proftpd/auth_log      AUTH auth
ExtendedLog                     /var/log/proftpd/paranoid_log  ALL default
SQLLogFile                      /var/log/proftpd/mysql

# Set up authentication via SQL
# ===========
AuthOrder                       mod_sql.c
SQLAuthTypes                    Backend
SQLConnectInfo                  proftpd_admin@localhost proftpd password
SQLUserInfo                     usertable userid passwd uid gid homedir shell 
SQLGroupInfo                    grouptable groupname gid members 
SQLUserWhereClause              "disabled=0 and (NOW()<=expiration or expiration=-1 or expiration=0)"
SQLHomedirOnDemand  on

# Log the user logging in
SQLLog PASS counter
SQLNamedQuery counter UPDATE "lastlogin=now(), count=count+1 WHERE userid='%u'" usertable

# logout log
SQLLog EXIT time_logout
SQLNamedQuery time_logout UPDATE "lastlogout=now() WHERE userid='%u'" usertable

# display last login time when PASS command is given
SQLNamedQuery login_time SELECT "lastlogin from usertable where userid='%u'"
SQLShowInfo PASS "230" "Last login was: %{login_time}"

# xfer Log in mysql
SQLLog RETR,STOR transfer1
SQLNamedQuery  transfer1 INSERT "'%u', '%f', '%b', '%h', '%a', '%m', '%T', now(), 'c', NULL" xfer_stat
SQLLOG ERR_RETR,ERR_STOR transfer2
SQLNamedQuery  transfer2 INSERT "'%u', '%f', '%b', '%h', '%a', '%m', '%T', now(), 'i', NULL" xfer_stat

AllowStoreRestart               on
AllowRetrieveRestart            on
RequireValidShell               off
#RootLogin off

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

Configuring ProFTPD Administrator

First lets create the apache config file and restart apache. The file has been set to only allow access from the local host. Change the access to meet your needs.

/etc/httpd/conf.d/proftpd_admin.conf

 
alias /ftpadmin /usr/share/proftpd_admin

<Location /ftpadmin>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    Allow from ::1
    # Allow from .example.com
</Location>

> service httpd restart

Edit the file /usr/share/proftpd_admin/misc/database_structure_mysql/db_structure.sql
Skip to the last three lines. Enter the desired password in these three lines.

Lets create the database and tables. Type the following.
> mysql -u root -p < /usr/share/proftpd_admin/misc/database_structure_mysql/db_structure.sql

Now type the following to do a little housekeeping for php5.
> chmod o+w /usr/share/proftpd_admin/configuration.xml

Now start proftpd. Be sure to also have it start at boot time.
> service proftpd start

Now go to the web interface configuration screen http://yourserver.tld/ftpadmin/configure.php
You will need to configure database access and some other settings.

Conclusion

That's the complete setup. Proftpd Admin dose almost everything we need. You will need to create links for multiple host names pointing to the same directory. For example if your directory is '/home/virtwww/yourdomain.com' and you want www.yourdomain.com to work then you'll have to create a link called '/home/virtwww/www.yourdomain.com/' which points to '/home/virtwww/yourdomain.com'.

Comments

tklim?16 August 2010, 07:57

/ftpadmin/configure.php where is this file locate ?

nicolas?09 February 2010, 04:23

hey another message to thanks you a lot, it works perfectly.

really really thanks to you !!!!

nicolas?09 February 2010, 01:48

thanks a lot for your answer!

do you think that this fonction will resolv the authentification problem (user that haven't home directory can't connect to server ftp ? )

nicolas?09 February 2010, 00:35

hello,

first of all thanks for this tutorial.

i encounter a trouble and it makes hours i try and try to resolve my problem. i copy and paste your proftpd.conf, i change value in # Set up authentication via SQL.

the only point is the :SQLHomedirOnDemand on

if i comment this line, the server start and restart, if i take off comment, the server doesn't start (no message).

So i comment this line and create a user in proftpd_admin (all is ok) and try to connect with the user and it's impossible:

530 Authentification incorrecte.

i really don't know where i do mistake, i follow the tutorial step by step. My server is updated.

i can't too connect with system users.

really after hours of research i come to ask your help (if you can)

thanks a lot for your answer

rcamp?08 February 2010, 11:00

In newer versions of proftpd you wiil need to do the following change in /etc/proftpd.conf.

Replace
SQLHomedirOnDemand on
with
CreateHome on

rcamp?21 May 2009, 13:44

Terry, I'm glad it worked for you. I write these howtos very bare bones. AKA I don't explain why I did the steps I did. Someday when I get more time I'll expand these howtos to include explanations

rcamp?21 May 2009, 13:36

Under /var/log Usually when proftpd gives an error starting up is with the config file or connecting to the database. If you copy and pasted from my page be sure that line wrapping didn't happen.

Sander Datema?18 May 2009, 02:00

I get an error when i start the service proftpd. Is there a log where i can wat went wrong.

Terry Antonio?30 April 2009, 19:07

G'Day I cant thank you enough for this how to. I had V 1.2 on a old server and decided it was time to upgrade to V 1.3 thinking it would only take half an hour.

After a day and a half of failure trying to understand the incomprehensible instructions for the conf file I thought maybe someone has done a how to and after much googling found this site. In my opinion this is the strength of open source in that when someone has spent a lot of there time working something out they can share it so others less endowed can benefit from there work. Personally I am very very appreciative - worked first go.

sieggie?13 April 2009, 00:30

hi,

thank you for this post, i really learned a lot. however what i would like to ask is how do turn on the quota for each user?

thanks!

Retrieved from http://www.campworld.net/thewiki/pmwiki.php/LinuxServersCentOS/Cent5VirtWebServer
Page last modified on August 16, 2010, at 07:57 AM