<chapter id="admin.install">
	<title>Installation</title>

	<para>This chapter explains how to install or upgrade MantisBT.
	</para>

	<section id="admin.install.overview">
		<title>Overview</title>

		<para>The table below contains a high-level overview of the processes.
			Refer to the corresponding sections for details.
		</para>

		<informaltable>
			<tgroup cols="2">
				<thead>
					<row>
						<entry>New Installation</entry>
						<entry>Upgrade</entry>
					</row>
				</thead>
				<tbody>
					<row>
						<entry>
			<orderedlist>
				<listitem><para>
					<link linkend="admin.install.requirements">Check system requirements</link>
				</para></listitem>
				<listitem><para>
					<link linkend="admin.install.preinstall">Download and deploy MantisBT</link>
				</para></listitem>
				<listitem><para>
					<link linkend="admin.install.new">Execute the Installation script</link>
				</para></listitem>
				<listitem><para>
					<link linkend="admin.install.config">Configure the system</link>
				</para></listitem>
				<listitem><para>
					<link linkend="admin.install.postcommon">Execute post-installation common tasks</link>
				</para></listitem>
				<listitem><para>
					<link linkend="admin.install.postinstall">Execute post-installation specific tasks</link>
				</para></listitem>
			</orderedlist>
						</entry>
						<entry>
			<orderedlist>
				<listitem><para>
					<link linkend="admin.install.preinstall">Download and deploy MantisBT</link>
				</para></listitem>
				<listitem><para>
					<link linkend="admin.install.backups">Backup your system</link>
				</para></listitem>
				<listitem><para>
					Put the site down for maintenance
				</para></listitem>
				<listitem><para>
					<link linkend="admin.install.upgrade">Execute the Upgrade script</link>
				</para></listitem>
				<listitem><para>
					<link linkend="admin.install.postcommon">Execute post-installation common tasks</link>
				</para></listitem>
				<listitem><para>
					<link linkend="admin.install.postupgrade">Execute post-upgrade specific tasks</link>
				</para></listitem>
			</orderedlist>
						</entry>
					</row>
				</tbody>
			</tgroup>
		</informaltable>
	</section>

	<section id="admin.install.requirements">
		<title>System Requirements</title>

		<section id="admin.install.requirements.hardware">
			<title>Server Hardware Requirements</title>

			<para>MantisBT has modest hardware requirements.
				It requires a computer that is able to run the
				<link linkend="admin.install.requirements.software">server software</link>.
			</para>

			<itemizedlist>
				<listitem>
					<para>Server type</para>
					<para>The server can be a shared public web server or
						a dedicated co-located box.
					</para>
				</listitem>

				<listitem>
					<para>CPU and Memory</para>
					<para>As for any web application, you should size your
						server based on the traffic on the site.
					</para>
				</listitem>

				<listitem>
					<para>Disk</para>
					<para>The application code is less than 20 MB
					</para>
					<para>The amount of disk space required for the database
						will vary depending on the RDBMS and the volume of
						data, the main driving factor being the expected number
						and size of attachments.
					</para>
				</listitem>
			</itemizedlist>
		</section>

		<section id="admin.install.requirements.software">
			<title>Server Software Requirements</title>

			<para>All of the required software is free for commercial and
				non-commercial use (open source). Please refer to the
				<link linkend="admin.install.requirements.software.versions">table below</link>
				for minimum and recommended versions.
			</para>

			<itemizedlist>
				<listitem>
					<para>Operating System</para>
					<para>MantisBT runs on Windows, MacOS, OS/2, Linux, Solaris,
						the BSDs, and just about anything that supports the
						required server software.
					</para>
				</listitem>

				<listitem>
					<para>Web Server</para>
					<para>MantisBT is mainly tested with
						<ulink url="http://www.microsoft.com/iis">Microsoft IIS</ulink> and
						<ulink url="http://www.apache.org/">Apache</ulink>.
						However, it is expected to work with any recent web
						server software.
					</para>
					<para>File Extensions:
						MantisBT uses only <emphasis>.php</emphasis> files.
						If your webserver is configured for other extensions
						(e.g. .PHP3, .PHTML) then you will have to request the
						administrator to add support for .PHP files. This should
						be a trivial modification. Further details can be found
						in the
						<ulink url="http://www.php.net/manual/en/installation.php">PHP documentation</ulink>
					</para>
				</listitem>

				<listitem>
					<para><ulink url="http://www.php.net/">PHP</ulink></para>
					<para>The web server must support PHP.  It can be installed
						as CGI or any other integration technology.
					</para>
				</listitem>

				<listitem>
					<para>PHP extensions</para>
					<para>MantisBT is designed to work in as many environments
						as possible. Hence the required extensions are minimal
						and many of them are optional affecting only one
						feature.
						<itemizedlist>
							<listitem><para><emphasis>mandatory</emphasis>:
								the extension for the RDBMS being used (
									mysqli,
									pgsql,
									oci8,
									mssql/sqlsrv,
									ibm-db2
								)
							</para></listitem>

							<listitem><para><emphasis>Curl</emphasis> -
								required for the Twitter integration feature
							</para></listitem>

							<listitem><para><emphasis>GD</emphasis> -
								required for the graphs feature
							</para></listitem>

							<listitem>
								<para><emphasis>fileinfo</emphasis> -
									Guesses the MIME type of attachments
								</para>
								<para>Without this extension, file attachment
									previews and downloads may not work
									correctly as MantisBT won't be able to send
									the Content-Type header to a browser
									requesting an attachment.
								</para>
								<para>This extension is included by default from
									PHP version 5.3.x and above. For older versions
									you will need to install the fileinfo PECL
									extension (this requires root access to the
									server you're using).
							</para></listitem>

							<listitem><para><emphasis>mbstring</emphasis> -
								Recommended for best performance with multibyte
								(UTF8) strings processing. Required if the admin
								needs to list the SQL queries generated by
								MantisBT (see <emphasis>$g_show_queries_list</emphasis>
								in <xref linkend="admin.config.misc">).
							</para></listitem>

						</itemizedlist>
					</para>
				</listitem>

				<listitem>
					<para>Database</para>
					<para>MantisBT requires a database to store its data.
						The supported RDBMS are:
							MySQL (recommended),
							PostgreSQL,
							DB2,
							Microsoft SQL Server and
							Oracle (experimental).
					</para>
					<para>Note: There are known issues with all of the above
						platforms except MySQL, and to a lesser extend PostgreSQL;
						moreover, you should be aware that support for DB2, SQL
						server and Oracle is limited.
					</para>
				</listitem>

			</itemizedlist>

			<section id="admin.install.requirements.software.versions">
				<title>Versions compatibility table</title>

				<informaltable>
					<tgroup cols="5">
						<thead>
							<row>
								<entry>Category</entry>
								<entry>Package</entry>
								<entry>Minimum Version</entry>
								<entry>Recommended</entry>
								<entry>Comments</entry>
							</row>
						</thead>
						<tbody>
							<row>
								<entry morerows='4' valign='middle'>RDBMS</entry>
								<entry>MySQL</entry>
								<entry>4.1.x</entry>
								<entry>5.0.x or above</entry>
								<entry>PHP extension: mysqli</entry>
							</row>
							<row>
								<entry>PostgreSQL</entry>
								<entry>7.0</entry>
								<entry>8.0 or above</entry>
								<entry>PHP extension: pgsql</entry>
							</row>
							<row>
								<entry>IBM DB2</entry>
								<entry></entry>
								<entry></entry>
								<entry>PHP extension: ibm-db2</entry>
							</row>
							<row>
								<entry>MS SQL Server</entry>
								<entry>2005</entry>
								<entry>2005 or above</entry>
								<entry>PHP extension: mssql or sqlsrv</entry>
							</row>
							<row>
								<entry>Oracle</entry>
								<entry>8i</entry>
								<entry>11gR2</entry>
								<entry>PHP extension: oci8</entry>
							</row>

							<row>
								<entry morerows='2' valign='middle'>Web Server</entry>
								<entry>Apache</entry>
								<entry>1.3.x</entry>
								<entry>2.2.x</entry>
								<entry></entry>
							</row>
							<row>
								<entry>lighttpd</entry>
								<entry>1.4.x</entry>
								<entry>1.4.x</entry>
								<entry></entry>
							</row>
							<row>
								<entry>IIS</entry>
								<entry>6.0</entry>
								<entry>6.0</entry>
								<entry></entry>
							</row>

							<row>
								<entry>PHP</entry>
								<entry>PHP</entry>
								<entry>5.1.x</entry>
								<entry>5.2.x or above</entry>
								<entry>See above for PHP extensions</entry>
							</row>
						</tbody>
					</tgroup>
				</informaltable>

			</section>
		</section>

		<section id="admin.install.requirements.client">
			<title>Client Requirements</title>

			<para>MantisBT should run on most recent browsers in
				the market, including but not limited to
			</para>

			<itemizedlist>
				<listitem><para>Firefox 3 and above</para></listitem>
				<listitem><para>Internet Explorer 6 and above</para></listitem>
				<listitem><para>Chrome</para></listitem>
				<listitem><para>Safari</para></listitem>
				<listitem><para>Opera</para></listitem>
			</itemizedlist>
		</section>
	</section>

	<section id="admin.install.preinstall">
		<title>Pre-installation / upgrade tasks</title>

		<para>These tasks cover the download and deployment of MantisBT, and
			should be performed prior to any new installation or upgrade.
		</para>

		<orderedlist>
			<listitem><para>
				<link linkend="admin.about.download">Download</link>
				MantisBT
				</para>
			</listitem>

			<listitem>
				<para>Transfer the downloaded file to your webserver
				</para>
				<para>This can be done using whatever method you like best
					(ftp, scp, etc). You will need to telnet/ssh into the
					server machine for the next steps.
				</para>
			</listitem>

			<listitem>
				<para>Extract the release
				</para>
				<para>It is highly recommended to maintain a separate
					directory for each release.
					This not only avoids mismatch between versions,
					(files may have been added or removed)
					but also provides an easy path to downgrade your installation,
					should you need to.
				</para>
				<para>
					The usual command is (1 step):
					<programlisting>tar -xzf <emphasis>filename.tar.gz</emphasis></programlisting>
					OR (2 steps):
					<programlisting>
gunzip <emphasis>filename.tar.gz</emphasis>
tar -xf <emphasis>filename.tar</emphasis>
</programlisting>
					Other file archiving tools such as
					<ulink url="http://www.7-zip.org/">7-Zip</ulink>
					should also be able to handle decompression of the archive.
				</para>
				<para>The extraction process should create a new directory like
					<emphasis>mantisbt-1.2.x</emphasis>
				</para>
			</listitem>

			<listitem>
				<para>Rename the directory
				</para>
				<para>For new installations, you may want to rename the
					directory just created to something simpler, e.g.
					<emphasis>mantisbt</emphasis>
					<programlisting>mv mantisbt-1.2.x mantisbt</programlisting>
				</para>
			</listitem>
		</orderedlist>
	</section>

	<section id="admin.install.new">
		<title>New Installation</title>

		<para>This chapter explains how to perform a new installation of
			MantisBT.
		</para>

		<para>Start by checking the <link linkend="admin.install.requirements">
			system requirements</link> and installing the appropriate version
			of required software.
		</para>

		<para>Once that is done, execute the installation script.
			From your web browser, access
			<programlisting>http://yoursite/mantisbt/admin/install.php</programlisting>
			The installation procedure will go through the following steps:
		</para>

		<orderedlist>
			<listitem>
				<para>The script checks basic parameters for the web server
				</para>
			</listitem>

			<listitem>
				<para>Provide required information for the installation</para>
				<itemizedlist>
					<listitem><para>database type</para></listitem>
					<listitem><para>database server hostname</para></listitem>
					<listitem>
						<para>user and password</para>
						<para>Required privileges:
							SELECT, INSERT, UPDATE, and DELETE
						</para>
					</listitem>
					<listitem>
						<para>high-privileged database account</para>
						<para>Additional privileges required:
							INDEX, CREATE, ALTER, and DROP
						</para>
						<para>If this account is not specified, the database
							user will be used.
						</para>
					</listitem>
				</itemizedlist>
			</listitem>

			<listitem>
				<para>Click the <emphasis>Install/Upgrade Database</emphasis>
					button
				</para>
			</listitem>

			<listitem>
				<para>The script creates the database and tables.
				</para>
				<para>The default Administrator user account is created
					at this stage, to allow the initial login
					and setup of MantisBT.
				</para>
			</listitem>

			<listitem>
				<para>The script attempts to write a basic
					<emphasis>config_inc.php</emphasis>
					file to define the database connection parameters.
				</para>
				<para>This operation may fail if the web server's user account
					does not have write permissions to the directory
					(which is recommended for obvious security reasons).
					In this case, you will have to manually create the
					file and copy/paste the contents from the page.
				</para>
			</listitem>

			<listitem>
				<para>The script perform post installation checks on the system.
				</para>
				<para>Review and correct any errors.
				</para>
			</listitem>
		</orderedlist>

	</section>

	<section id="admin.install.upgrade">
		<title>Upgrading</title>

		<para>This chapter explains how to upgrade an existing
			MantisBT installation.
		</para>

		<para>Start by Performing the steps described in
			<link linkend="admin.install.preinstall">Pre-installation tasks</link>
			above.
		</para>

		<orderedlist>
			<listitem>
				<para>Put the site down for maintenance
					<programlisting>cp mantis_offline.php.sample mantis_offline.php
</programlisting>
					This will prevent users from using the system while
					the upgrade is in progress.
				</para>
			</listitem>

			<listitem>
				<para>Always <emphasis>Backup your code, data and
					config files</emphasis> before upgrading !
				</para>
				<para>This includes your Mantis directory, your attachments,
					and your database. Refer to the
					<link linkend="admin.install.backups">Backups</link>
					section for details.
				</para>
			</listitem>

			<listitem>
				<para>Copy the configuration files
				</para>
				<para>To preserve your system settings, you should copy the
					files listed below to the new directory, as well as any other
					custom files such as logo, favicon, css, etc.
				</para>
				<para><emphasis>
					config_inc.php
					custom_strings_inc.php
					custom_constants_inc.php
					custom_functions_inc.php
					</emphasis>
				</para>
			</listitem>

			<listitem>
				<para>Execute the upgrade script.
					From your web browser, access
					<programlisting>http://yoursite/mantisbt-NEW/admin/install.php</programlisting>
					where <emphasis>mantisbt-NEW</emphasis> is the name of the
					directory where the new release was extracted
				</para>
			</listitem>

			<listitem>
				<para>Provide required information for the upgrade</para>
				<itemizedlist>
					<listitem>
						<para>high-privileged database account</para>
						<para>Additional privileges required:
							INDEX, CREATE, ALTER, and DROP
						</para>
						<para>If this account is not specified, the database
							user will be used.
						</para>
					</listitem>
				</itemizedlist>
			</listitem>

			<listitem>
				<para>Click the <emphasis>Install/Upgrade Database</emphasis>
					button
				</para>
			</listitem>

			<listitem>
				<para>At the end of the upgrade, review and correct any
					warnings or errors.
				</para>
			</listitem>

		</orderedlist>

		<note>
			<title>Upgrading large databases</title>

			<para>When processing large databases from versions older than 1.2,
				the upgrade script may fail during the conversion of date fields,
				leaving the system in an inconsistent (i.e. partially updated)
				state.
			</para>
			<para>In this case, you should simply restart the upgrade process,
				which will resume where it left off. Note that you may have to
				repeat this several times, until normal completion.
			</para>
			<para>Reference: MantisBT issue
				<ulink url="http://www.mantisbt.org/bugs/view.php?id=12735">12735</ulink>.
			</para>
		</note>
	</section>


	<section id="admin.install.config">
		<title>Configure your installation</title>

		<para>There are many settings that you can adjust to configure
			and customize MantisBT.
			Refer to the
			<link linkend="admin.config">Configuration</link>
			section, as well as the
			<emphasis>config_defaults_inc.php</emphasis> file
			for in depth explanations of the available options.
			Check out also the
			<link linkend="admin.customize">Customizing MantisBT</link>
			section for further options to personalize your installation.
		</para>

		<para>This step is normally only required for new installations, but
			when upgrading you may want to review and possibly customize any
			new configuration options.
		</para>

		<para>Open or create the file <emphasis>config_inc.php</emphasis> in an
			editor and add or modify any values as required. These will
			override the default values.
		</para>

		<para>You may want to use the provided
			<emphasis>config_inc.php.sample</emphasis> file
			as a starting point.
		</para>

		<para>WARNING: you should never edit the
			<emphasis>config_defaults_inc.php</emphasis> file
			directly, as it could cause issues with future upgrades.
		</para>

	</section>

	<section id="admin.install.postcommon">
		<title>Post-installation and upgrade tasks</title>

		<para>Instructions in this section are common to both new installations
			and upgrades, and should be applied after completing either process.
		</para>

		<orderedlist>
			<listitem>
				<para>Test your configuration
				</para>
				<para>Load up <emphasis>admin/check.php</emphasis>
					to validate if everything is setup correctly.
				</para>
				<para>NOTE (for PHP 5.2 only):
					check.php sometimes reports the value of
					<emphasis>register_globals</emphasis> incorrectly.
					To confirm the correct value,
					Create a page with this line in it:
					<programlisting>&lt;?php phpinfo(); ?&gt;</programlisting>
					save it with a .php extension and load it up in your
					web browser.
				</para>
			</listitem>

			<listitem>
				<para>Delete the <emphasis>admin</emphasis> folder
				</para>
				<para>For security reasons, the scripts within this directory
					should not be accessible on a live MantisBT site or on any
					installation that is accessible via the Internet.
				</para>
				<para>Once you have confirmed that the install/upgrade
					was successful, you should delete this directory
					<programlisting>rm -r admin</programlisting>
				</para>
			</listitem>
		</orderedlist>
	</section>


	<section id="admin.install.postinstall">
		<title>Post-installation tasks</title>

		<para>Instructions in this section should only be applied after a
			new installation
		</para>

		<orderedlist>
			<listitem>
				<para>Login to your bugtracker
				</para>
				<para>Use the default Administrator account.
					The id and password are <emphasis>administrator / root</emphasis>.
				</para>
			</listitem>

			<listitem>
				<para>Create a new Administrator account
				</para>
				<para>Go to <emphasis>Manage &gt; Manage Users</emphasis>
					and create a new account with 'administrator'
					access level.
				</para>
			</listitem>

			<listitem>
				<para>Disable or delete the default Administrator account
				</para>
			</listitem>

			<listitem>
				<para>Create a new Project
				</para>
				<para>Go to <emphasis>Manage &gt; Manage Projects</emphasis>
					and create a new project
				</para>
			</listitem>

		</orderedlist>
	</section>

	<section id="admin.install.postupgrade">
		<title>Post-upgrade tasks</title>

		<para>Instructions in this section should only be applied after
			upgrading an existing installation.
		</para>

		<orderedlist>
			<listitem>
				<para>Test the new release
				</para>
				<para>Perform any additional testing as appropriate to ensure
					the new version does not introduce any regressions.
				</para>
			</listitem>

			<listitem>
				<para>Switch the site to the new version
				</para>
				<para>The commands below should be executed from the web root
					(or wherever the mantisbt scripts are installed)
					and assume that the "live" directory (old version)
					is named <emphasis>mantisbt</emphasis> and the new release
					directory is <emphasis>mantisbt-1.2.x</emphasis>.
					<programlisting>
mv mantisbt mantisbt-old
mv mantisbt-1.2.x mantisbt
</programlisting>
				</para>
			</listitem>

			<listitem>
				<para>Put the site back on line
					<programlisting>rm mantis_offline.php</programlisting>
					This should be the final step in the upgrade process, as
					it will let users login again.
				</para>
			</listitem>
		</orderedlist>
	</section>

	<section id="admin.install.backups">
		<title>Backups</title>

		<para>It is strongly recommended to backup your MantisBT database on a
			regular basis. The method to perform this operation depends on
			which RDBMS you use.
		</para>

		<para>Backups are a complex subject, and the specificities of
			implementing and handling them for each RDBMS are beyond the scope
			of this document.
			For your convenience, the section below provides a simple method
			to backup MySQL databases.
		</para>

		<para>You should also consider implementing backups of your MantisBT
			code (which includes your configs and possibly customization),
			as well as issue attachments (if stored on disk) and project
			documents.
		</para>

		<para><emphasis>
				!!! Backups should always be performed before an upgrade !!!
			</emphasis>
		</para>

		<section id="admin.install.backups.mysql">
			<title>MySQL Backups</title>

			<para>MySQL databases are easy to backup using the
				<emphasis>mysqldump</emphasis> command:
				<programlisting>
mysqldump -u&lt;username&gt; -p&lt;password&gt; &lt;database name&gt; &gt; &lt;output file&gt;
</programlisting>
			</para>

			<para>To restore a backup you will need to have a clean database. Then
				run:
				<programlisting>
mysql -u&lt;username&gt; -p&lt;password&gt; &lt;database name&gt; &lt; &lt;input file&gt;
</programlisting>
			</para>

			<para>You can also perform both of these tasks using
				<ulink url="http://www.phpmyadmin.net/">phpMyAdmin</ulink>
			</para>

			<para>A good idea is to make a backup script and run it regularly
				through cron or a task scheduler (for Windows see
				<ulink url="http://www.wincron.com/">WinCron</ulink>
				).
				Using the current date in the filename can prevent overwriting and
				make cataloguing easier.
			</para>

			<para>References and useful links:
				<itemizedlist>
					<listitem><para>
						<ulink url="http://dev.mysql.com/doc/refman/5.1/en/mysqlhotcopy.html">
							mysqlhotcopy documentation
						</ulink></para>
					</listitem>
					<listitem><para>
						<ulink url="http://sourceforge.net/projects/automysqlbackup/">
							automysqlbackup script
						</ulink></para>
					</listitem>
				</itemizedlist>
			</para>
		</section>

	</section>

	<section id="admin.install.uninstall">
		<title>Uninstall</title>

		<para>It is recommended that you make a backup in case you wish to use
			your data in the future. See the
			<link linkend="admin.install.backups">Backups</link>
			page for details.
		</para>
		<para>
			To uninstall MantisBT:
			<itemizedlist>
				<listitem>
					<para>Delete the MantisBT directory and all files and
						subdirectories.
					</para>
				</listitem>
				<listitem>
					<para>Drop all MantisBT tables from the database, these can be
						identified by the configured prefix for the installation. The
						default prefix is 'mantis'.
					</para>
				</listitem>
				<listitem>
					<para>Remove any customizations or additions that you may have
						made.
					</para>
				</listitem>
			</itemizedlist>
			If you have the permissions to create/drop databases and you have a
			specific database for MantisBT that does not contain any other data,
			you can drop the whole database.
		</para>

	</section>
</chapter>
