You are here: Home / Debian GNU/Linux / Web applications / Files management / Install FileZ file sharing tool on Debian

Install FileZ file sharing tool on Debian

by Pierre-Yves Landuré last modified Nov 02, 2012 05:36

FileZ is a PHP software design to publish files on the Web for a limited time. It is well designed, and its main drawback is the impossibility to publish files for a unlimited time.

This howto is tested on :

  • Debian 6.0 Squeeze

This howto is tested with these versions of FileZ :

  • 2.1

Prerequisites

This howto needs :

This howto needs one of these tools, according to the installed HTTP server :

Parameters

Provide the domain name where will be available the software :

DOMAIN="files.example-domain.com"

Provide the admin email, notified of user registration :

ADMIN_EMAIL="root@example-domain.com"

Provide the from email :

FROM_EMAIL="filez@example-domain.com"

Profile the from name :

FROM_NAME="${DOMAIN}"

Provide the MySQL server host :

MYSQL_HOST="localhost"

If the MySQL server is not local, the mysql-tools script will try to connect with MySQL client, or in case of connection failure, through SSH.

Installation

Compute the installation path :

INSTALL_PATH="/opt/filez/${DOMAIN}"

Make sure that the parent folder exists :

PARENT_PATH="$(command dirname "${INSTALL_PATH}")"
if [ ! -e "${PARENT_PATH}" ]; then
command mkdir --parent "${PARENT_PATH}"
fi

Environment preparation

Install the needed software :

command apt-get install php5-mysql php5-curl php5-ldap git

Adjust PHP configuration to the application needs :

command php-tools --for="filez" --set "upload_max_filesize" "750M"
command php-tools --for="filez" --set "post_max_size" "750M"
command php-tools --for="filez" --set "max_execution_time" "1200"

Reload PHP configuration :

test -x /etc/init.d/php5-fpm && /etc/init.d/php5-fpm force-reload
test -x /etc/init.d/apache2 && /etc/init.d/apache2 force-reload
test -x /etc/init.d/lighttpd && /etc/init.d/lighttpd force-reload
test -x /etc/init.d/nginx && /etc/init.d/nginx force-reload

Application installation

Fetch the latest sources using git :

command git clone "git://github.com/FileZ/FileZ.git" "${INSTALL_PATH}"

Database creation

Create the database with mysql-tools :

MYSQL_PARAMS="$(command mysql-tools --server="${MYSQL_HOST}" --with-ssh \
--auto-hosts --db-prefix="filez" --create "${DOMAIN}")"

Parse the database connection parameters :

MYSQL_DB="$(echo "${MYSQL_PARAMS}" | command grep -e "^MYSQL_DB" \
    | cut --delimiter="=" --fields="2-")"
MYSQL_USER="$(echo "${MYSQL_PARAMS}" | command grep -e "^MYSQL_USER" \
    | cut --delimiter="=" --fields="2-")"
MYSQL_PASSWORD="$(echo "${MYSQL_PARAMS}" | command grep -e "^MYSQL_PASSWORD" \
    | cut --delimiter="=" --fields="2-")"
echo "${MYSQL_PARAMS}"

Initialize database contents :

command mysql --user="${MYSQL_USER}" --password="${MYSQL_PASSWORD}" \
    --host="${MYSQL_HOST}" "${MYSQL_DB}" \
      < "${INSTALL_PATH}/config/db/schema.sql"

Conformity with LSB

Adjust the software data folders to fit Linux Standard Base :

command mkdir --parent "/var//lib/filez/${DOMAIN}/uploads"
command chown -R www-data:www-data "/var/lib/filez/${DOMAIN}/uploads"
command mkdir --parent "/var/log/filez/${DOMAIN}"
command chown -R www-data:www-data "/var/log/filez/${DOMAIN}"

Configuration

Create the configuration file :

echo "[app]
log_dir = \"/var/log/filez/${DOMAIN}\"
upload_dir = \"/var/lib/filez/${DOMAIN}/uploads\"
default_locale = \"fr\"
progress_monitor = \"Fz_UploadMonitor_Apc\"
sharing_destinations[] = \"email\"
admin_email = \"${ADMIN_EMAIL}\"

[db]
dsn = \"mysql:host=${MYSQL_HOST};dbname=${MYSQL_DB}\"
user = \"${MYSQL_USER}\"
password = \"${MYSQL_PASSWORD}\"

[email]
from_name = \"${FROM_NAME}\"
from_email = \"${FROM_EMAIL}\"
host = \"localhost\"
name = \"filez\"" \
  > "${INSTALL_PATH}/config/filez.ini"

If possible, force HTTPS use :

command sed -i -e '/[app]/a\
https = "always"' "${INSTALL_PATH}/config/filez.ini"

The configuration options are described in config/filez.default.ini and config/filez.ini.example files.

Virtual host setup

Setup the HTTP server for the application :

if [ -x "/usr/bin/a2tools" ]; then
  command a2tools --overrides="All" "${DOMAIN}" "${INSTALL_PATH}"
fi
if [ -x "/usr/bin/lighty-tools" ]; then
  command lighty-tools add-vhost "${DOMAIN}" "${INSTALL_PATH}"
fi

The software should now be available on the domain name. Connect with:

  • username : admin
  • Password : filez

Do not forget to change default password.

Automatic deletion of expired files

Setup a script to automaticaly delete expired files :

command cp "${INSTALL_PATH}/scripts/cron.sh" "/etc/cron.hourly/filez-${DOMAIN}"
command chmod +x "/etc/cron.hourly/filez-${DOMAIN}"
command sed -i \
    -e "s|^LOG_DIR=.*\$|LOG_DIR=/var/log/filez/${DOMAIN}|" \
    -e "s|^URL=.*\$|URL=http://${DOMAIN}|" \
  "/etc/cron.hourly/filez-${DOMAIN}"

Automatic upgrade

Setup a script to daily upgrade the software from git :

echo "#"'!'"/bin/bash
# Update ${PROTOCOL}://${DOMAIN}/ source code from Git.
test -x '/usr/bin/git' -a -d '${INSTALL_PATH}' && {
pushd '${INSTALL_PATH}' > '/dev/null'
/usr/bin/git pull --quiet > '/dev/null'
popd > '/dev/null'
}" \
  > "/etc/cron.daily/${DOMAIN}-update"
command chmod +x "/etc/cron.daily/${DOMAIN}-update"

Backup

Backup the installation with Backup Manager (see Install and setup Backup Manager on Debian) :

command backup-manager-tools add "${INSTALL_PATH}"
command backup-manager-tools add "/var/lib/filez/${DOMAIN}"

Don't forget to backup the database (see Install and setup MySQL on Debian)

Thanks