# How To: Install OTRS 4.0.2 from Source on FreeBSD 10.1 (with ZFS, MySQL56, Apache24)



## TzunTzai (Dec 7, 2014)

After dealing with OTRS Help Desk on Ubuntu Server for a couple of years (which actually worked quite well for our small IT firm!), I've finally decided to migrate this great Help Desk platform over to FreeBSD, simply because I love it! I'm no FreeBSD master, but I've figured out just enough to get this working. So here we go...

~Alex

Step 1: Pre Installation Tasks

(Assuming you have a new FreeBSD 10.1 installation with ZFS. Which I've installed on MS Hyper-V Server 2012 R2.)

Edit /etc/rc.conf and verify the hostname of your FreeBSD/OTRS server as well as the static IP address. Which may look something like this:

```
# Networking
hostname="OTRS"
ifconfig_de0="inet 192.168.1.20 netmask 255.255.255.0"
defaultrouter="192.168.1.1"
sshd_enable="YES"
zfs_enable="YES"
apache24_enable="YES"
mysql_enable="YES"
```

Don't forget to visit /etc/resolv.conf and enter your DNS

Fetch the ports tree:

```
> portsnap fetch && portsnap extract
```

Install the port pkg:

```
> cd /usr/ports/ports-mgmt/pkg/ && make install clean
> pkg2ng
```

Install applications needed to run OTRS:

```
> pkg install apache24
> pkg install mysql56-server
```

Step 2. Let's prepare the MySQL56-Server

Start MySQL Server:

```
> service mysql-server start
```

Set the root password for MySQL:

```
> mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('rootpass');
mysql> quit
```
That was easy!

Step 3. Prepare the OTRS Directory and Download/Extract the Source

Remember, we are using ZFS which is great for snapshots/backups. Create a ZFS partition for OTRS:

```
> zfs create zroot/opt
> zfs set mountpoint=/opt zroot/opt
```
(I use the default OTRS directory because I do not want to go through the headache of modifying the OTRS script files.)

Fetch the OTRS source using wget and rename the OTRS directory:

```
> cd /opt
> fetch ftp://ftp.otrs.org/pub/otrs/otrs-4.0.2.tar.gz
> tar -xf otrs-4.0.2.tar.gz
> mv otrs-4.0.2 otrs
```

Add the OTRS user to the system:

```
> adduser
UserName = otrs
FullName = otrs
Home Directory = /opt/otrs
Password = otrs
```

Now let's copy some configuration files:

```
> cd /opt/otrs/Kernel
> cp Config.pm.dist Config.pm
> cp Config/GenericAgent.pm.dist Config/GenericAgent.pm
```

Set OTRS permissions/access rights:

```
> perl /opt/otrs/bin/otrs.SetPermissions.pl --otrs-user=otrs --web-group=www --admin-group=otrs
```

If the obove doesn't work, your can temporarily set permissions ... 


```
> chown -R otrs /opt/otrs/
> chgrp -R otrs /opt/otrs/
> chmod -R 777 /opt/otrs/
```

Step 4. Perl

See which Perl Modules are needed to run OTRS on FreeBSD: `# perl /opt/otrs/bin/otrs.CheckModules.pl`.

Use the following commands to install the missing required modules:

```
> cpan Archive::Zip
> cpan Date::Format
> cpan DBI
> cpan DBD::mysql
> cpan Net::DNS
> cpan Template (Enable Stash and XS during install.)
> cpan Template::Stash::XS
> cpan YAML::XS
```

Double check the installed Perl Modules to verify installation:

```
>perl /opt/otrs/bin/otrs.CheckModules.pl
```
If you didn't miss anything, all required modules should show "OK".

Verify Perl has been properly set up:

```
> perl -cw /opt/otrs/bin/cgi-bin/index.pl
/opt/otrs/bin/cgi-bin/installer.pl syntax OK
> perl -cw /opt/otrs/bin/cgi-bin/customer.pl
/opt/otrs/bin/cgi-bin/customer.pl syntax OK
> perl -cw /opt/otrs/bin/otrs.PostMaster.pl
/opt/otrs/bin/otrs.PostMaster.pl syntax OK
```

Step 5. Configure Apache24

Start the Apache24 service to verify if the base install is working


```
> service apache24 start
```

Open a browser window to the IP address of your FreeBSD server.  In my case http://192.168.1.20/ If you see "It works!" in the browser, your Apache24 pkg install went well.

Copy the OTRS configuration file to the Apache24 directory:

```
> cp /opt/otrs/scripts/apache2-httpd.include.conf /usr/local/etc/apache24/otrs.conf
```

Create an alias within the Apache24 configuration file. Add the following line to the bottom of the Apache24 configuration file httpd.conf:

```
> vi /usr/local/etc/apache24/httpd.conf
Include etc/apache24/otrs.conf
```

Also, verify that the CGI module is loaded. Locate

```
#LoadModule cgi_module libexec/apache22/mod_cgi.so
```
within httpd.conf and uncomment the line (remove the #). Save and exit.

Restart the Apache24 service:

```
> service apache24 restart
```

Step 6. Copy/Rename OTRS cron .dist files


```
> cd /opt/otrs/var/cron
> mv aaa_base.dist aaa_base
> mv cache.dist cache
> mv fetchmail.dist fetchmail
> mv generate_dashboard_stats.dist generate_dashboard_stats
> mv generic_agent-database.dist generic_agent-database
> mv generic_agent.dist generic_agent
> mv pending_jobs.dist pending_jobs
> mv postmaster.dist postmaster
> mv postmaster_mailbox.dist postmaster_mailbox
> mv rebuild_ticket_index.dist rebuild_ticket_index
> mv scheduler_watchdog.dist scheduler_watchdog
> mv session.dist session
> mv unlock.dist unlock
```

Make sure OTRS cron jobs are running as the OTRS user:

```
> su otrs
> /opt/otrs/bin/Cron.sh start
```

Step 7. You're ready to launch! Configure the MySQL database for OTRS 4.x

Open your web browser and navigate to the URL http://ServerIPAddress/otrs/installer.pl.


Step 8. Once the OTRS MySQL database has been configured, lets create a script to automate the ZFS snapshot for /opt

Create a script called "SnapshotOTRS.sh" and placed it into the /root directory

```
#!/bin/sh
zfs snapshot -r zroot/opt@otrs_`date +%Y%m%d_%H%M%S`
```

My script also includes the ability to backup a MySQL dump as well as export the entire OTRS folder & snapshots to an smb share (or external drive if needed).

Make script executable

```
> chmod +x /root/SnapShotOTRS.sh
```

Create a cronjob to run this script daily at 6pm

```
> crontab -e

*    18    *    *    * /root/SnapshotOTRS.sh
```


This should get OTRS up and running in FreeBSD. Hope this was helpful.


----------



## lme@ (Dec 10, 2014)

Thank you! As I can see the FreeBSD port of OTRS is at version 3.3.7 while you install the newer version 4.x. You might contact the port's maintainer and could help him upgrading the port to the latest version.


----------



## TzunTzai (Dec 10, 2014)

lme@ said:


> Thank you! As I can see the FreeBSD port of OTRS is at version 3.3.7 while you install the newer version 4.x. You might contact the port's maintainer and could help him upgrading the port to the latest version.



Sure, I'd be glad to help with that.


----------



## David Dunlap (Aug 6, 2015)

I hate to bump this old thread but I'm killing myself trying to get OTRS running in a jail on my FreeNAS box.

I've followed this guide very closely however I went ahead and installed otrs-4.0.9.tar.gz

My issue is that upon trying to access the server, xxx.xxx.xxx.xxx/otrs/installer.pl I get this



> Internal Server Error
> The server encountered an internal error or misconfiguration and was unable to complete your request.
> 
> Please contact the server administrator at you@example.com to inform them of the time this error occurred, and the actions you performed just before this error.
> ...




And my httpd-error.log shows this


```
[client 192.168.11.95:50459] AH01215: (2)No such file or directory: exec of '/opt/otrs/bin/cgi-bin/installer.pl' failed: /opt/otrs/bin/cgi-bin/installer.pl
[Wed Aug 05 16:29:50.953114 2015] [cgi:error] [pid 44061] [client 192.168.11.95:50459] End of script output before headers: installer.pl
```

I've done a lot of searching and tried several things but no luck.

Anyone have ideas?


----------



## Langschlaefer (Aug 11, 2015)

For Jails (here sysutils/ezjail):

/etc/sysctl.conf

```
security.jail.allow_raw_sockets=1
```

Ezjail config for the jail:

```
export jail_otrs_parameters="allow.raw_sockets=1 allow.sysvipc=1"
security.jail.allow_raw_sockets=1
```

Not sure if both options are needed or just the sysvipc

This should also solve the FreeNAS problem above. AFAIK every application/server is a separate jail in FreeNAS.


----------



## TzunTzai (Aug 14, 2015)

David Dunlap said:


> I hate to bump this old thread but I'm killing myself trying to get OTRS running in a jail on my FreeNAS box.
> 
> I've followed this guide very closely however I went ahead and installed otrs-4.0.9.tar.gz
> 
> ...



Hi David,

Did Langschlaefer solution help? I haven't worked much with jails, therefore I wouldn't know where to start.


----------



## dR3b (Sep 10, 2015)

TzunTzai said:


> Install applications needed to run OTRS:
> 
> ```
> > pkg install apache24
> ...


Thank you!

You don't need ftp/wget. Use the fetch(1) command. It's in "base".


----------



## TzunTzai (Sep 10, 2015)

dR3b said:


> Thank you!
> 
> You don't need ftp/wget. Use the fetch(1) command. It's in "base".



You are correct sir =)

I originally did this install on ubuntu server a while back and stuck to the notes I kept for Ubuntu. However, on FreeBSD fetch(1) is the way to go! I'll update my original post.


----------



## TzunTzai (Sep 18, 2015)

David Dunlap said:


> I hate to bump this old thread but I'm killing myself trying to get OTRS running in a jail on my FreeNAS box.
> 
> I've followed this guide very closely however I went ahead and installed otrs-4.0.9.tar.gz
> 
> ...



I ran into the same error when updating my OTRS server. I think this will fix the problem.

`# cd /usr/bin/perl
# ln /usr/local/bin/perl`

The OTRS config files are looking for perl in /usr/bin. In FreeBSD 10.2, it seems to be in /usr/local/bin. So I created a link which solved the problem.


----------



## junovitch@ (Sep 19, 2015)

TzunTzai said:


> I ran into the same error when updating my OTRS server. I think this will fix the problem.
> 
> `# cd /usr/bin/perl
> # ln /usr/local/bin/perl`
> ...



It should be `ln -s /usr/local/bin/perl /usr/bin/perl`

This was a change from the way Perl is installed, see /usr/ports/UPDATING (`less -p 20150513 /usr/ports/UPDATING` to get right to it)


----------

