Ubuntu Server – Configuring Exim4 to Send Email Via Gmail

I am in the midst of trying to get Kaltura to work on Ubuntu 10.4 but am experiencing an error that is a bit of a show stopper.

The good news is that I needed to configure Exim4 to send email via Gmail – and that is what this post is about.

First install Exim4:

sudo apt-get install exim4

Configure Exim with the following command:

sudo dpkg-reconfigure exim4-config

Press the down-arrow key to select mail sent by smarthost; received via SMTP or fetchmail then press Tab, followed by Enter:

Enter a system mail name – this might be your company-name.com or a dummy domain name like I used below:

Next we specify an IP address to listen for incoming SMTP connections. This field was already completed for me with the value 127.0.0.1 ; ::1

The next screen was auto-completed with my host-name (which I had previously edited in /etc/hosts). The guide that I followed said to leave this blank but I left it as it was:

I left the Machines to relay for blank:

Select No don’t Hide local mail name in outgoing mail:

Select No to Keep number of DNS-queries minimal (Dial on-Demand):

For Delivery method for local mail choose mbox format in /var/mail/:

For Split configuration into small files select No:

Now we need to make several changes to the configuration to Exim4 in the file etc/exim4/exim4.conf.template:

sudo nano etc/exim4/exim4.conf.template

Find the line .ifdef DCconfig_smarthost DCconfig_satellite and add the following in that section (you can press Ctrl + W to search in nano):

send_via_gmail:
    driver = manualroute
    domains = ! +local_domains
    transport = gmail_smtp
    route_list = * smtp.gmail.com

The guide that I followed said to remove any other smarthost defined with domains = ! +local_domains in /etc/exim4/exim4.conf.template but I did not find any.

Next find the comment begin authenticators section and add the following:

gmail_login:
    driver = plaintext
    public_name = LOGIN
    client_send = : yourname@gmail.com : YourGmailPassword

Find the comment transport/30_exim4-config_remote_smtp_smarthost and add the following:

gmail_smtp:
    driver = smtp
    port = 587
    hosts_require_auth = $host_address
    hosts_require_tls = $host_address

Finally comment out the login section of /etc/exim4/exim4.conf.template:

#Commented out so that Gmail’s Public_name can equal “LOGIN”
#login:
# driver = plaintext
# public_name = LOGIN
#.ifndef AUTH_CLIENT_ALLOW_NOTLS_PASSWORDS
# Return empty string if not non-TLS AND looking up $host in passwd-file
# yields a non-empty string; fail otherwise.
# client_send = “<; ${if and{\
# {!eq{$tls_cipher}{}}\
# {!eq{PASSWDLINE}{}}\
# }\
# {}fail}\
# ; ${extract{1}{::}{PASSWDLINE}}\
# ; ${sg{PASSWDLINE}{\\N([^:]+:)(.*)\\N}{\\$2}}”
#.else
# Return empty string if looking up $host in passwd-file yields a
# non-empty string; fail otherwise.
# client_send = “<; ${if !eq{PASSWDLINE}{}\
# {}fail}\
# ; ${extract{1}{::}{PASSWDLINE}}\
# ; ${sg{PASSWDLINE}{\\N([^:]+:)(.*)\\N}{\\$2}}”
#.endif
#####################################################
### end auth/30_exim4-config_examples
#####################################################

Press Ctrl + O and then Enter to save and then Ctrl + X to save the file and exit nano.

Update Exim4 with the following command:

Run update-exim4.conf

Restart Exim4:

 /etc/init.d/exim4 restart

Finally test your configuration by sending an email via the command line:

mail user@example.com

Type a Subject and then press Enter.

Type a message and then press Enter.

Type a single . (dot) and then press Enter.

Press Enter again for a blank CC address.

Within a few minutes you should receive an email at the specified email address.

Sources:

http://www.manu-j.com/blog/wordpress-exim4-ubuntu-gmail-smtp/75/

http://basskozz.wordpress.com/2008/12/07/how-to-setup-a-raid5-software-mdadm-array-w-email-notifications-via-gmail-the-easy-way/ 

Ubuntu Server 10.4 Lucid – add-apt-repository: command not found

Since Ubuntu 9.10 (Karmic Koala) users have been able to add PPAs (Personal Package Archives) to install packages via the command line as follows:

sudo add-apt-repository ppa:<repository name>

Typically this works out of the box, but not with a minimal Ubuntu Server installation (such as I use in my VMware vSphere environment) which produces the following error:

sudo: add-apt-repository: command not found

The solution is to install python-software-properties:

sudo apt-get install python-software-properties

Source: Ubuntu Forum

.

Ubuntu Server 10.4 Lucid – Upgrading Feng Office (Community Edition)

It turns out that upgrading Feng Office is actually very simple. I had installed Feng Office Community Edition version 1.7.4 recently and a few days ago found out that version 1.7.5 had been released.

It is advisable to backup your current installation before upgrading.

Log in to Feng Office as Admin and then click the Administration link:

Click the Upgrade button:

Click Start automatic upgrade:

Wait a couple of minutes and then log back in to your new version of Feng Office.

Ubuntu Server 10.4 Lucid – Installing and Configuring the Feng Office Backup v1.0 Plugin

In my previous post I configured Ubuntu Server with a set of scripts and cron jobs to backup (and restore) the Feng Office installation folder and the MySQL database to a Windows share.

The Feng Office wiki mentions an alternative backup method – in the form of a plugin that can be installed and configured from the Administration panel. The current version of the backup is v1.0 and it can be downloaded from here.

The plugin does include a basic readme.txt file but it does not clearly detail the steps that are needed to install the plugin.

First you will need to have wget and unzip installed on your server:

sudo apt-get update
sudo apt-get install wget unzip

You can either download the plugin (if the version has changed since this post was written) and upload it to your Feng Office server or use wget to download the file as follows:

wget http://sourceforge.net/projects/opengoo/files/plugins/backup/
backup_1.0.zip

Extract the plugin to your Feng Office installation folder – for me this is /var/www/feng_community:

sudo unzip backup_1.0.zip -d /var/www/feng_community/

Now open a browser and log in to Feng Office as the Administrative user.

Copy and paste the following URL to install the backup plugin (replace <server-ip> with the IP address of your Feng Office server):

http://<server-ip>/feng_community/index.php?c=backup&a=install

You should now see that the plugin is successfully installed:

Click the back to opengoo link to return to Feng Office and then click the Administration link:

In the Administration Panel click the Backup icon:

Click the Launch backup process link:

Once the backup is complete you can download it to your local machine and then delete the backup from the server:

If you check the Cron Events section of the Administration Panel you will see that the backup plugin can be scheduled and enabled quite simply.

The only problem that I see is that the backups are saved locally on the Feng Office server – this still requires the Admin user to download the backups to store them somewhere else.

Sadly as far as I can tell restoring the backup is a manual process. While it doesn’t look too taxing it would involve copying the backup to the Feng Office installation folder and then manually restoring the MySQL database backup.

While this backup process seemed to work quite nicely (and it is nice to be able to do from within the Feng Office interface) I plan to use the scripts and cron jobs that I already have set up to back up Feng Office.

Ubuntu Server 10.4 Lucid – Backing up Feng Office 1.7.4 (Community Edition)

The Feng Office Wiki has instructions for backing up the Feng Office installation folder and the MySQL database. This can either be done with scripts and a cron job or with a plugin that allows for configuration via the Administration web console and a cron job.

In this post I will look at the scripts and cron job – I intend to look at the plugin later on.

Backing up Feng Office for me this means backing up /var/www/feng_community as well as the fengdb database.

In my previous post I mounted a share on my Windows Home Server in Ubuntu Server using the following mount point /mnt/whs-backup.

Note: Your Feng Office installation folder, database variables and backup destination may differ so adjust them as required.

To run a nightly backup I need two brief scripts, a secure file that contains the MySQL username and password, and two cron entries to run the backups.

Update: In the comments potion pointed out that the cp command does not file owner/group or permissions. So I have added his suggested scripts for the tar command.

Here are the explanations of the tar switches used:

-c, --create               create a new archive
-f, --file=ARCHIVE         use archive file or device ARCHIVE
-x, --extract, --get       extract files from an archive

Note: the following two scripts are saved in my /home/username folder.

The first script will back up /var/www/feng_community:

Original script:

#!/bin/bash sudo cp -R /var/www/feng_community /mnt/whs-backup

Tar script:

#!/bin/bash
today=$(date '+%d_%m_%y')
sudo tar -cf /mnt/whs-backup/"$today"_feng_community.tar 
/var/www/feng_community

I saved this file as backup-feng-community.sh

The second script will backup the fengdb database and query a secured file /etc/fengdb.cnf for MySQL credentials:

#!/bin/bash
mysqldump --defaults-extra-file=/etc/fengdb.cnf fengdb >
/mnt/whs-backup/fengdb.sql

I saved this file as backup-fengdb.sh.

Now we need to make these two scripts executable:

chmod +x backup*.sh

Create a file called /etc/fengdb.cnf:

sudo nano /etc/fengdb.cnf

Add the following lines using your MySQL fengdb username and password:

[client]
host = localhost
user = fenguser
password = yourfengdbpassword

In nano press Ctrl + O and then Enter to save and then Ctrl + X to exit.

Secure /etc/fengdb.cnf as follows:

sudo chmod 600 /etc/fengdb.cnf

At this point we could execute the two scripts manually and backup Feng Office to our Windows share.

To automate the backup we use cron. This is what my cron settings look like (my two scripts are set to run everyday around 1am).

# m h  dom mon dow   command
15 1 * * * /home/username/backup-feng-community.sh
*  1 * * * /home/username/backup-fengdb.sh

Change username to your Ubuntu Server username.

To edit your cron settings use the following command:

sudo crontab -e

You can use my settings or you can easily generate your own cron settings using the online cron generator.

If you have configured Feng Office to communicate with email accounts such as Gmail be prepared for the backup of /var/www/feng_community to take a little while (depending of how many email and attachments have been downloaded).

As with any backup we also need to know how to restore the backups. For this we need two scripts. The first I named restore-feng-community.sh:

#!/bin/bash sudo cp -R /mnt/whs-backup/feng_community /var/www

Tar command:

sudo tar -xf /mnt/whs-backup/*_feng_community.tar 
var/www/feng_community

In the tar restore above the * refers to the date of the backup.

The second script (to restore the MySQL database) I named restore-fengdb.sh:

#!/bin/bash
mysql --defaults-extra-file=/etc/fengdb.cnf fengdb <
/mnt/whs-backup/fengdb.sql

Again, make both of these scripts executable:

chmod +x restore*.sh

For the record I did test the restore process before posting! Please take precautions when you test restoring your backups (and make sure that you change the appropriate variables in the scripts to match your environment).

Sources: Feng Office Wiki, serverfault.

Ubuntu Server – Mounting a Windows Share Using the Command Line

When I started writing this post I wanted to mount a Windows share in Ubuntu and backup files from Ubuntu  onto my Windows Home Server (WHS).

Since then I have begun looking at other options like TimeDicer and rdiff-backup – so I have not decided yet on which path I will take to backup /var/www directories and different MySQL databases.

Nevertheless I did succesfully get a share on my Windows Home Server (WHS) mounted, as follows.

First I chose to create a new user on WHS called vmbackup and this process created the vmbackup user share //WHS/Users/vmbackup.

Now on to the steps that we need to complete on Ubuntu Server.

I like to use nano to edit files on Ubuntu Server – and you can install nano as follows:

sudo apt-get update
sudo apt-get install nano

Because I want to backup to a Windows share I also need to install the Samba filesystem:

sudo apt-get install smbfs

The next step is to edit the /etc/hosts file and add a reference that points to my Windows PC:

sudo nano /etc/hosts

The IP address of my WHS is 192.168.0.50 so I added the following line to my /etc/hosts file:

192.168.0.50 whs

In nano press Ctrl + O and then Enter to save and then Ctrl + X to exit.

Now create a local directory that we will use to map our WHS share to:

sudo mkdir /mnt/whs-backup

To mount the Windows share we need to edit /etc/fstab with the path to the Windows share and the local mount point as follows:

sudo nano /etc/fstab

Add the following line to /etc/fstab:

//whs/users/vmbackup  /mnt/whs-backup  cifs exec,credentials=
/etc/cifspw,rw,uid=ubuntu-username 0 0

Note that the above line points to /etc/cifspw for credentials for mouting the Windows share. Also note that the uid refers to your Ubuntu Server username. If you do not include a uid and username then only the root user will have write permissions to the Windows share.

Create the /etc/cifspw file:

sudo nano /etc/cifspw

Enter your credentials to the Windows share:

username=vmbackup
password=password

Obviously you will need to specify your own username and password.

Secure /etc/cifspw as follows:

sudo chmod 600 /etc/cifspw

Mount the Windows share with the following command:

sudo mount -a

At this point reboot Ubuntu Server so that it can pick up permissions for the Windows share:

sudo reboot

Quickly check that you have write permissions as follows:

cd /mnt/whs-backup
touch text.txt

You should be able to create the test.txt file without any issues.

Hopefully this will help you is you are having issues mounting a Windows Share in Ubuntu.

Sources: industriousone and the Ubuntu Forum,

Configuring Feng Office 1.7.4 Community Edition To Send Email Via Gmail – Ubuntu Server 10.4 Lucid

In my previous post I installed Feng Office 1.7.4 Community Edition on Ubuntu Server 10.4 Lucid.

With the installation complete, I wanted to configure Feng Office to send and receive emails and found that the best option (for me) was to configure Feng Office to use Gmail.

I set up an additional Gmail account for the Feng Office Administrator to use as I already had a Gmail account for myself.

Note: I did also configure Feng Office to connect to my Hotmail / Windows Live account – but currently Feng Office only allows me to receive emails from this account.

The first step that you need to complete once you have a Gmail account is to enable IMAP. Log in to Gmail and then click Options cog at the top right of the screen – then click the Mail Settings link.

Click the Enable IMAP radio button and then click the Save Changes button.

That is all we need to do on the Gmail side of things so the next step is to configure the Feng Office Admin account to send emails via our Gmail account. This will enable users to receive reminders and other system generated emails.

Log in to Feng Office as the Administrator and then click the Administration link:

Click the Configuration button:

Click on the Mailing link:

Below you can see how I set the options to connect to my Gmail account. Obviously you will need to change the Gmail email address to the one that you want to use. Click Save.

Setting up a Gmail account for a user is a little different. If you need to add a user just click Administration followed by the Add user link:

Type in the User name and their Gmail address and then click Add user:

Click Administration again and then click Add Email account:

This is how I configured the incoming email settings for my user account (I have removed the first part of my gmail address). You will need to use an email address that is different from the Admin user Gmail address:

Below is my configuration for the SMTP settings:

Update: This seemed to be enough to get things working until I upgraded to Feng Office 1.7.5 – though I cannot be sure that upgrading was the trigger that prevented the Feng Office admin account from sending emails.

If we first look at the cron settings in the Admin panel in Feng Office (Log in as Admin and click Administration then Cron events) we can see that it is set to check for emails every ten minutes:

The solution was to create a cronjob that calls on the cron.php file which resides in the root of the Feng Office installation folder, as follows:

sudo crontab -e

I set my cron job to run every minute as signified by the five asterisks – followed by the script to call on cron.php.

* * * * * sudo wget -O - -q http://<server-ip>/feng_community/cron.php

You can change this to run the cron job as often as you would like – you will need to change the IP address to that of your server – and you may need to adjust the path to cron.php depending on your installation.

The frequency of this cron job can over-ride the settings that you specify within the Cron events page in the Feng Office admin panel. For example, if you configure a cron job to run every five minutes, and you configure the cron event to check for upgrades every one minute, it will only be able to check for upgrades every five minutes.

This setup was enough to get the Admin user to send notifications to Feng Office users and for me to be able to send and receive emails within Feng Office.

There are plenty of other options that can be set and so I would recommend that you read the Feng Office Wiki pages that deals with Setup and  Email here and here.

Support is also available from the Feng Office Forum.

Ubuntu Server 10.4 Lucid – Installing Feng Office 1.7.4 Community Edition

Feng Office is a web based suite of collaborative applications (groupware) that includes notes, email, contacts, calendar, documents, tasks and weblinks. As an administrator you can setup users and collaborative workspaces and users can work in their own workspace as well as the collaborative workspace(s) that they have access to. I will be installing the current stable version of Feng Office which is 1.7.4 (although you can download and install 1.7.5 if you want to).

Note: I had to look around for a solution for enabling innoDB on Ubuntu 10.4 Lucid and fortunately did find a work-around that enabled me to install Feng Office. Having said that InnoDB should be enabled by default – it appears that MySQL seems to disable it if your InnoDB log files get corrupted. When you remove the log files they are recreated, allowing InnoDB to start again. This will be covered during the tutorial below if you also encounter this issue.

I installed Feng Office in a VMware vSphere virtual machine on an existing Ubuntu 10.4 Lucid LAMP server.

If you do not have Ubuntu Server 10.4 already installed you just need to choose the LAMP and SSH roles during installation. On an existing server without these roles installed enter the following command at the terminal (and then select the LAMP and SSH roles and make a note of your MySQL password for later):

sudo tasksel

Assuming that we now have the LAMP and SSH roles installed we can now connect remotely to the server using Putty (Windows) or SSH (Linux).

First install php5-gd, php5-cli and nano:

sudo apt-get install php5-gd php5-cli nano

Next check the memory_limit setting in php.ini.

sudo nano /etc/php/apache2/php.ini

Make sure that the memory_limit setting is set to at least 32 MB.

Install Unzip (so that we can unzip Feng Office after we download it):

sudo apt-get install unzip

Now change directory to /var/www and download Feng Office:

cd /var/www/
sudo wget http://downloads.sourceforge.net/project/opengoo/
fengoffice/fengoffice_1.7.4/fengoffice_1.7.4.zip

Unzip Feng Office:

sudo unzip fengoffice_1.7.4.zip -d /var/www/feng_community

Feng Office will now be extracted to the folder feng_community in the /var/www directory.

Give ownership of the feng_community directory to Apache:

sudo chown -R www-data:www-data /var/www/feng_community

The next step is to create a MySQL database for Feng Office:

mysql -u root -p

Enter your MySQL password when prompted.

At the mysql> prompt type the following commands – make sure you change ‘fengsqlpassword‘ to a password of your own:

create database fengdb;
create user 'fenguser'@'localhost' identified by 'fengsqlpassword';
grant all on fengdb.* to 'fenguser'@'localhost';
quit;

Now restart Apache:

sudo /etc/init.d/apache2 restart

If you want to quickly check that InnoDB is running at this point you can do this as follows:

mysql -u root -p
mysql> show engines;

If InnoDB is not running then issue the following commands:

sudo /etc/init.d/mysql stop
sudo mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bak
sudo mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bak
sudo /etc/init.d/mysql start

For good measure I rebooted – and then found that InnoDB was running:

sudo reboot

To complete the installation open browser and goto http://<server-ip>/feng_community/ where <server-ip> is the IP address of your server.

Click Next:

You should pass the Environment checks – click Next:

Confirm the following details as per the screen-shot below.

Hostname: localhost
Username: fenguser
Password: The fengsqlpassword you defined earlier
Database name: fengdb

Click Next:

Click Finish to complete the installation:

Browse to http://<server-ip>/feng_community/

Define an Admin username, email address, password and Company name and then click Submit:

Welcome to your new Feng Office installation:

Sources: howtoforge, turnkeylinux forum, Feng Office Wiki and innodb forum.

Ubuntu Server – Upgrading VIMP (Community Edition) From 2.0.6 to 2.1.1

ViMP (a video & social media Content Management System) recently released version 2.1.1 (which includes support for mobile devices).

I had previously installed version 2.0.6 (as a virtual machine in VMware vSphere) and thought I would take a look at keeping my ViMP installation up-to-date.

The first step is of course to make a backup in-case the upgrade fails – I simply took a snapshot of my virtual machine as this was the quickest and simplest solution.

First download ViMP version 2.1.1 from here.

Upload ViMP 2.1.1 to your server using WinSCP (Windows) or SSH (Linux).

Now use Putty (Windows) or SSH (Linux) to access the command line interface on your ViMP server.

Copy vimp.framework-2.1.1-r19091-community.tar.gz to your installation folder, in my case this was /var/www/showvid/data:

sudo cp vimp.framework-2.1.1-r19091-community.tar.gz
/var/www/showvid/data

Change directory and extract ViMP 2.1.1 with the following commands:

cd /var/www/showvid/data
sudo tar xzf vimp.framework-2.1.1-r19091-community.tar.gz

Issue the following commands to upgrade*:

sudo ./symfony rebuild
sudo ./symfony cc

* Note that If you use languages other than English and update from a version < 2.0.7 to a version >= 2.0.7, the following symfony task must also be executed (in between the two commands above):

./symfony i18n:import --clear

You should now be able to log in as admin and see that your ViMP installation is running the new version (under the configuration link).

After the upgrade I found that then when I try to upload video I see an Error in the Admin portal:

+ Problem executing command FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1.1, Copyright (c) 2000-2009 Fabrice Bellard, et al. configuration: --extra-version=4:0.5.1-1ubuntu1.1 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enabl

I logged in as admin and clicked on Administration then Configuration and then Player and set Enable HTML5-player to False.

Then under the Media tab I clicked Restart Transcoding on the affected uploads and they converted successfully. After this I clicked on Transcode new formats and this appeared to work.

I checked /var/www/showvid/data/logs/framework.convert.log and did not see any errors.

So for now I have just left the HTML5 player disabled and my uploads are working without issue (even if they are not being transcoded to the new formats).

Additional support is available from the ViMP Forum if required.

Souces: ViMP Forum, ViMP Documentation, ViMP Forum

Ubuntu – How to Create and Host favicon.ico Files on Apache

I recently installed an web-based feed aggregator called Gregarius on Apache and found that there was no favicon displayed next to the URL or in the browser tab.

So I took this as an opportunity to learn two things – first how to create a favicon.ico file on Ubuntu and second how to configure Apache to display favicon files.

A favicon is typically 16×16 pixles. You can create an image yourself (as a.png file for now) or use your favorite search engine to find some free ones.

I found some great, hand drawn icon sets and decided to use one of the 16×16 .png files from them:



Click the above images to download the icon sets.

I extracted the downloaded icon sets and copied the icon of my choice (rss_16x16) to my home directory.

Now we just have to convert the .png icon file to an .ico file. To do this we will install a command line utility called icoutils.

Click Applications, Accessories and then Terminal and enter the following command:

sudo apt-get install icoutils

Convert the .png icon to an .ico file as follows:

icotool -o favicon.ico -c rss_16x16.png

Obviously you will need to change the filename of the .png file to the name of your chosen icon.

The final step is a little configuration on your Apache web-server. The following line of code is a basic template that we will adjust according to our environment. Typically this line of code just needs to be inserted into the site header between the <head> and </head> tags.

<link rel="shortcut icon" href="htttp://domain.com/favicon.ico" />

For my environment I had to adjust the href destination to the ip-address of my web-server followed by the path to my favicon.ico:

<link rel="shortcut icon" href="http://192.168.0.43/rss/favicon.ico"
 />

Gregarius is written in PHP and so I had to add the above line to /var/www/rss/themes/defaut/web/header.php. This location will vary depending on your application / environmrnent.

Then I restarted Apache:

sudo /etc/init.d/apache2 restart

All that was left to do was to refresh my Gregarius web-page and my favicon was there in all its glory!

Sources:

http://steve.kargs.net/hosting/create-a-website-faviconico-with-ubuntu-linux/

Many thanks to my brother for helping me figure out where the shortcut icon code belonged in my Gregarius installation.