- For any functionality at all
  - Unix.  Ubuntu and Solaris work.
  - Apache
  - MySQL
  - PHP, including PEAR
  - php5-mysql
  - Spreadsheet_Excel_Writer and OLE.  Can be installed with:
    % sudo pear install OLE-1.0.0RC2
    % sudo pear install Spreadsheet_Excel_Writer-0.9.2
  - PHPExcel read, write Excel including .xlsx
    copy source files into lib/PHPExcel/Classes
  - R, version at least 2.15.2
    - additional packages: rrBLUP, multicore, rpart, lme4, pheatmap, agricolae, lsmeans
  - PHPIDS web application security
    - Edit lib/phpids-0.7/lib/IDS/Config/Config.ini.php to specify filter_path and tmp_path
- For some functions
  - GBrowse
  - pclzip.lib.php
  - libzzip
  - for ViroBLAST
    - DBD::CSV and XML::DOM. Can be installed with these commands:
      % sudo cpan DBD::CSV
      % sudo cpan XML::DOM
    - NCBI BLAST+,
      Edit viroblast/viroblast.ini to use the path to these executables.
    - BLAST databases of the markers:
      - Edit curator_data/format-fasta.php to specify species
	e.g. viroblast/db/nucleotide/oat-markers
	e.g. viroblast/db/nucleotide/oat-index.csv
      - Create a symbolic link to the BLAST databases in the viroblast directory
	e.g. cd viroblast/db
	e.g. ln -s ../../gbs_files/blast/ nucleotide

Setting up the MySQL databases

Load the schema and some initializing data from the .sql files in this
docs/ directory:
mysql> create database T3wheat;
mysql> use T3wheat;
mysql> source T3wheat_schema.sql;
mysql> source T3wheat_skeleton.sql;

The skeleton file T3wheat_skeleton.sql loads some initializing data in
several housekeeping tables.  You will want to modify some of these
values for your installation, especially in table 'settings'.

Grant read-permission (only) to a user such as "publicuser".
mysql> grant select on T3wheat.* to publicuser@localhost identified by '<password>';
mysql> grant execute on T3wheat.* to publicuser@localhost;
mysql> grant update, insert, delete on T3wheat.session_variables to publicuser@localhost;

To help prevent table T3wheat.users from being read by hackers, revoke
the SELECT permission on that table by running the script publicuser.php
in this docs/ directory.  If you add more tables to the database later,
you will have to grant SELECT on them individually.

Grant write permission to another user such as "curator":
mysql> grant all on T3wheat.* to curator@localhost identified by '<password>';

If you have more than one instance of T3 on the same host machine, add
an entry to table 'settings' with name = "database", value = "<unique
name>". The code checks this entry to prevent transfer of session
variables (cookies) between instances.  This is important because the
session variables include the user's login status and privileges, which
otherwise can be transferred simply by opening a new tab in the browser.

If using GBrowse, create the GBrowse database "gtht" and grant
mysql> create database gtht;
mysql> grant select on gtht.* to publicuser@localhost;

Database connection scripts

For security, the password information to connect to the MySQL database
is not stored within the T3 source code repository or even within the
Apache directory.  For example ours is in
/data/tht_data/mysql_connections/.  The file permissions need only allow
read access for the Apache user, e.g.  www-data:

-r-------- 1 www-data www-data 196 2011-01-31 11:56
-r-------- 1 www-data www-data 141 2011-01-31 11:56

Create these files with the contents shown below, and edit your files
includes/ and includes/ to point to the
correct pathname for your system.
  $db_config = array('db_name' => 'T3wheat',
                     'db_user' => 'publicuser',
                     'db_pass' => '<password>',
                     'db_host' => 'localhost');
  $db_config = array('db_name' => 'T3wheat',
                     'db_user' => 'curator',
                     'db_pass' => '<password>',
                     'db_host' => 'localhost');

command line scripts

Some pages use "materialized view" tables of allele data rather than the
source table 'alleles' itself. These tables are normally updated after 
importing new data. If database data is deleted then the materialized view
tables can be updated using scripts in the scripts\ directory.

For GBS import files with over 100K markers it is necessary to use command line
scripts to format and import the data. The scripts for doing these imports are
located in the scripts/ directory.

Directories for uploaded and output files

Uploaded data files are stored in the curator_data/uploads/ directory,
which must be writable by the Apache user, e.g. www-data.  

% cd curator_data
% mkdir uploads
% sudo chown www-data uploads

Likewise, certain raw data files that are not parsed into the database
are archived in the "raw/" directory, so this must be writable by the
Apache user too.  In the Git distribution, "raw/" is a symbolic link to
a directory outside the repository, with the writable permission.

All output and temporary files are stored in directory /tmp/tht/, where
write-access for the scripts isn't a problem and they're all in one
place to be purged daily or hourly with a cron() job.  In order for this
to work there must be a symbolic link from somewhere in the webserver's
documents directory to /tmp/tht.  For example if your T3 repositories
are in a subdirectory "t3" of the webserver's top directory
"/www/htdocs", this would make the link:

% cd /www/htdocs/t3; mkdir tmp; ln -s /tmp/tht tmp/tht


The built-in BLAST interface, ViroBLAST, is not included in the GitHub
repository but is available for academic and nonprofit 
use at no charge.  It should be installed in directory 'viroblast/' at the
top level of the T3 distribution.

If you have installed ViroBLAST, the sequences of the markers will be
maintained in a BLAST database in the directory 'viroblast/db/nucleotide/'.
This directory must be writable by Apache user.

PHP configuration

Some helpful modifications for the php.ini file, such as 

max_input_time = 600
memory_limit = 512M
post_max_size = 100M
upload_max_filesize = 100M
max_input_vars = 10000
error_log = /var/log/php-scripts.log

For logging from PHP, set the owner of the log file to the Apache user,
e.g. www-data
# touch /var/log/php-scripts.log
# chown www-data /var/log/php-scripts.log

Then restart the Apache server to read the new php.ini configuration.


Installing GBrowse should have created a gbrowse.conf/ directory in the
Apache configuration directory, e.g. in /etc/apache2/.  Edit the
tht.conf file in the repository's gbrowse-generated/ directory to
replace "<password>" with the publicuser password you assigned for
the gtht database above, and move tht.conf to the gbrowse.conf/

Add the following stanza to your Apache configuration file, e.g.
/etc/apache2/sites-available/default, and restart Apache.

Alias /perl/ "/cgi-bin/"
<Location /perl/>
     SetHandler perl-script
     PerlResponseHandler ModPerl::Registry
     PerlOptions +ParseHeaders
     Options +ExecCGI
     Order allow,deny
     Allow from all