Web-cp howto

forFreeBSD 5.x using Apache 2

by Wouter de Vries (wouter -at- afilas -dot- nl)

This is a work in progress.
Final writting will be revised when this walkthrough is considered done.
Please check the forums (http://www.web-cp.net/forums/viewtopic.php?t=216) for the latest version
of this walkthrough and to discussit or ask for help.

Please run all commands as root.

### GETTING WEB-CP ###

# cd /usr/local/
# fetch http://www.web-cp.net/releases/webcp-0.5.6.tar.gz
# tar zxvf webcp-0.5.6.tar.gz
# rm -rf webcp-0.5.6.tar.gz

### ADD WEB-CP USER ###

# pw adduser -n webcp -u 81 -d /usr/local/webcp -s /sbin/nologin

### CREATE SOME FILES AND CHANGE FILE PERMISSIONS ###

# touch /var/log/webcp
# chown webcp:webcp /var/log/webcp
# chmod 600 /var/log/webcp
# mkdir /var/run/webcp
# chown webcp:webcp /var/run/webcp/
# chmod 755 /var/run/webcp
# mkdir /usr/local/webcp/httpd/conf
# chown -R root:webcp /usr/local/webcp
# chmod 755 /usr/local/webcp
# cd /usr/local/webcp
# chmod -R 755 httpd suspended imap named
# chmod -R 750 headers web server
# chmod 755 server
# chmod -R 700 skel
# chmod -R 770 tag
# chmod 755 server/autoreply.php
# chmod 777 autoresponder
# mkdir /var/log/httpd
# touch /var/log/httpd/access
# chown -R webcp:webcp /var/log/httpd

### WEB-CP CONFIGURATION ###

# cp /usr/local/webcp/web/config-freebsd.inc.php /usr/local/webcp/web/config.inc.php
# echo '<?php $cfg["apache"]["port"] = 80; ?>' >> /usr/local/webcp/web/config.inc.php

Edit /usr/local/webcp/web/config.inc.php to suit your needs.

At least edit these variables:
$cfg['adminmail']
$cfg['sysname']
$cfg['key']
$cfg['webcp'] => I advise you to change it to something else than a version number (your company name for example). It makes it harder for crackers to find out which web-cp version you're running.
$cfg['dbpass']

### MAKE BIND WORK ###

# rm -rf /usr/local/webcp/named/include
# cd /usr/local/webcp/named
# ln -s /var/named/etc/namedb/ include
# touch include/include.named
# chmod 755 include include/include.named
# chown root:webcp include include/include.named
# echo 'include "/usr/local/webcp/named/include/include.named";' >> /var/named/etc/namedb/named.conf

### INSTALLING APACHE ###

# cd /usr/ports/www/apache2
# make install clean
# echo 'Include /usr/local/webcp/httpd/include/include.httpd' >> /usr/local/etc/apache2/httpd.conf


### INSTALLING MYSQL ###

# cd /usr/ports/databases/mysql41-server
# make install clean
# mysql_install_db
# chown -R mysql:mysql /var/db/mysql
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
# mysqladmin -u root password "newpassword"
# mysql -u root -p
> create database webcp;
> exit;
# mysql -u root -p --database=webcp < /usr/local/webcp/webcp.sql

### INSTALLING PHP ###

# cd /usr/ports/lang/php4
# make install clean

Use apache 2.x instead of apache 1.3.x

# echo 'AddType application/x-httpd-php .php' >> /usr/local/etc/apache2/httpd.conf
# echo 'AddType application/x-httpd-php-source .phps' >> /usr/local/etc/apache2/httpd.conf

# cd /usr/ports/lang/php4-extensions
# make install clean

Be sure to check (besides the things which are already checked):
FTP
MCRYPT
MHASH
PCNTL
SOCKETS

### INSTALLING PROFTPD ###

# cd /usr/ports/ftp/proftpd
# make install clean
# echo 'ScoreboardFile /var/run/proftpd.scoreboard' >> /usr/local/etc/proftpd.conf
# echo 'RequireValidShell off' >> /usr/local/etc/proftpd.conf
# echo 'DefaultRoot ~' >> /usr/local/etc/proftpd.conf

### CREATE SENDMAIL FILES ###

# touch /etc/mail/local-host-names
# touch /etc/mail/virtusertable
# touch /etc/mail/access
# touch /etc/mail/aliases

# touch /etc/mail/mailertable

### CREATE WEB-CP STARTUP SCRIPTS ###

Create the file /usr/local/etc/rc.d/webcp with this content:

<code>
#!/bin/sh -
WEBCP_DIR=/usr/local/webcp
WEBCP_PIDFILE=/var/run/webcp.pid

case "$1" in
start)
   # test for running proc:
   if test -r ${WEBCP_PIDFILE}
   then
      pid=`cat ${WEBCP_PIDFILE}`
      # test if process is running:
      if `kill -CHLD ${pid} > /dev/null 2>&1`
      then
         echo "$0[$$] process already running, cowardly refusing to start new process."
         exit 0
      fi

      # if we got here, pid file is stale:
      echo "Stale ${WEBCP_PIDFILE}, deleting..."
      rm -f ${WEBCP_PIDFILE}
   fi

   # start the server:
   cd ${WEBCP_DIR}/server
   ./webcp.php -d >/dev/null 2>&1 && echo -n ' webcp'
   ;;
stop)
   kill `cat $WEBCP_PIDFILE` && echo -n ' webcp'
   rm -f ${WEBCP_PIDFILE}
   ;;
*)
   echo "unknown option: $1 - should be 'start' or 'stop'" >&2
   ;;
esac
</code>

Also create the file /usr/local/etc/rc.d/webcp-httpd with this content:

<code>
#!/bin/sh -
WEBCP_DIR=/usr/local/webcp
WEBCP_PIDFILE=/var/run/webcp/webcp-httpd.pid

case "$1" in
start)
   # test for running proc:
   if test -r ${WEBCP_PIDFILE}
   then
      pid=`cat ${WEBCP_PIDFILE}`
      # test if process is running:
      if `kill -CHLD ${pid} > /dev/null 2>&1`
      then
         echo "$0[$$] process already running, cowardly refusing to start new process."
         exit 0
      fi

      # if we got here, pid file is stale:
      echo "Stale ${WEBCP_PIDFILE}, deleting..."
      rm -f ${WEBCP_PIDFILE}
   fi

   # start the server:
   cd ${WEBCP_DIR}/server
   ./webcp-httpd.php -d >/dev/null 2>&1 && echo -n ' webcp-httpd'
   ;;
stop)
   kill `cat $WEBCP_PIDFILE` && echo -n ' webcp-httpd'
   rm -f ${WEBCP_PIDFILE}
   ;;
*)
   echo "unknown option: $1 - should be 'start' or 'stop'" >&2
   ;;
esac
</code>

# chmod 755 /usr/local/etc/rc.d/webcp /usr/local/etc/rc.d/webcp-httpd

### STARTING UP ###

# echo 'apache2_enable="YES"' >> /etc/rc.conf
# echo 'mysql_enable="YES"' >> /etc/rc.conf
# echo 'proftpd_enable="YES"' >> /etc/rc.conf
# echo 'named_enable="YES"' >> /etc/rc.conf

# /usr/local/etc/rc.d/apache2.sh start
# /usr/local/etc/rc.d/mysql-server.sh start
# /usr/local/etc/rc.d/proftpd.sh start
# /etc/rc.d/named start

Edit /usr/local/webcp/server/webcp.php and /usr/local/webcp/server/webcp-httpd.php and change the first line to:
#!/usr/local/bin/php

# /usr/local/etc/rc.d/webcp-httpd start
# /usr/local/etc/rc.d/webcp start

### ENABLING QUOTA's IN THE KERNEL ###

This is beyond the scope of this document, please check http://www.freebsd.org/doc/handbook/quotas.html

### SETTING UP WEB-CP ###

Go to http://<your_box>:81/
Fill in the setup form.

You're done.
Smile!
Log in at http://<your_box>:81/