Saturday, November 7, 2009

How to change your Exim outgoing mail IP, A Quick setup



1. Open the file /etc/mailips


[root@server ~]# vi /etc/mailips


enter the following and save the file

*: IP 

example:  *: 192.168.0.10

assuming 192.168.0.10 is your secondary IP.

IP - the IP you wish to send emails from. The * symbol specifies all domains to send emails from this IP

2. Now edit /etc/mail_reverse_dns

Enter the reverse DNS aka rDNS for the above IP and save the file

IP rdns

Example: 192.168.0.10 server.mail.com

3. Now change the attributes to immutable

[root@server ~]#  chattr +i  /etc/mail_reverse_dns
[root@server ~]#  chattr +i  /etc/mailips


4. Restart exim and thats it!


[root@server ~]# /etc/init.d/exim restart


Send a test email as root and check the headers to confirm.




Hope this helps :)

Wednesday, August 5, 2009

Useful Exim Commands continued...

[1] Removing Bad Mail

for i in `exiqgrep -i -f nobody`; do exim -Mrm $i; done >> Removes Nobody Mail

for i in `exiqgrep -i -o 259200`; do exim -Mrm $i; done >> Removes Mail Older than 3 Days

for i in `exiqgrep -i -f "^<>$"`; do exim -Mrm $i; done >> Removes Mail with Weird Characters (Spam)

[2] Delete Mail by a Domain

for i in `exiqgrep -i -f domain.com`; do exim -Mrm $i; done

[3] Delete Mail for a Domain

for i in `exiqgrep -i -r domain.com`; do exim -Mrm $i; done

[4] Remove Whole Mail Queue

for i in `exiqgrep -i -f `; do exim -Mrm $i; done

[5] Run Mail Queue

runq -qqff&

Useful Exim Commands continued...(copied from net)

Here are some useful things to know for managing an Exim 4 server. This assumes a prior working knowledge of SMTP, MTAs, and a UNIX shell prompt.

Message-IDs and spool files

The message-IDs that Exim uses to refer to messages in its queue are mixed-case alpha-numeric, and take the form of: XXXXXX-YYYYYY-ZZ. Most commands related to managing the queue and logging use these message-ids.

There are three -- count 'em, THREE -- files for each message in the spool directory. If you're dealing with these files by hand, instead of using the appropriate exim commands as detailed below, make sure you get them all, and don't leave Exim with remnants of messages in the queue. I used to mess directly with these files when I first started running Exim machines, but thanks to the utilities described below, I haven't needed to do that in many months.

Files in /var/spool/exim/msglog contain logging information for each message and are named the same as the message-id.

Files in /var/spool/exim/input are named after the message-id, plus a suffix denoting whether it is the envelope header (-H) or message data (-D).

These directories may contain further hashed subdirectories to deal with larger mail queues, so don't expect everything to always appear directly in the top /var/spool/exim/input or /var/spool/exim/msglog directories; any searches or greps will need to be recursive. See if there is a proper way to do what you're doing before working directly on the spool files.

Basic information

Print a count of the messages in the queue:

root@localhost# exim -bpc

Print a listing of the messages in the queue (time queued, size, message-id, sender, recipient):

root@localhost# exim -bp

Print a summary of messages in the queue (count, volume, oldest, newest, domain, and totals):

root@localhost# exim -bp | exiqsumm

Print what Exim is doing right now:

root@localhost# exiwhat

Test how exim will route a given address:

root@localhost# exim -bt alias@localdomain.com
user@thishost.com
<-- alias@localdomain.com
router = localuser, transport = local_delivery
root@localhost# exim -bt user@thishost.com
user@thishost.com
router = localuser, transport = local_delivery
root@localhost# exim -bt user@remotehost.com
router = lookuphost, transport = remote_smtp
host mail.remotehost.com [1.2.3.4] MX=0

Run a pretend SMTP transaction from the command line, as if it were coming from the given IP address. This will display Exim's checks, ACLs, and filters as they are applied. The message will NOT actually be delivered.

root@localhost# exim -bh 192.168.11.22

Display all of Exim's configuration settings:

root@localhost# exim -bP

Searching the queue with exiqgrep

Exim includes a utility that is quite nice for grepping through the queue, called exiqgrep. Learn it. Know it. Live it. If you're not using this, and if you're not familiar with the various flags it uses, you're probably doing things the hard way, like piping `exim -bp` into awk, grep, cut, or `wc -l`. Don't make life harder than it already is.

First, various flags that control what messages are matched. These can be combined to come up with a very particular search.

Use -f to search the queue for messages from a specific sender:

root@localhost# exiqgrep -f [luser]@domain

Use -r to search the queue for messages for a specific recipient/domain:

root@localhost# exiqgrep -r [luser]@domain

Use -o to print messages older than the specified number of seconds. For example, messages older than 1 day:

root@localhost# exiqgrep -o 86400 [...]

Use -y to print messages that are younger than the specified number of seconds. For example, messages less than an hour old:

root@localhost# exiqgrep -y 3600 [...]

Use -s to match the size of a message with a regex. For example, 700-799 bytes:

root@localhost# exiqgrep -s '^7..$' [...]

Use -z to match only frozen messages, or -x to match only unfrozen messages.

There are also a few flags that control the display of the output.

Use -i to print just the message-id as a result of one of the above two searches:

root@localhost# exiqgrep -i [ -r | -f ] ...

Use -c to print a count of messages matching one of the above searches:

root@localhost# exiqgrep -c ...

Print just the message-id of the entire queue:

root@localhost# exiqgrep -i

Managing the queue

The main exim binary (/usr/sbin/exim) is used with various flags to make things happen to messages in the queue. Most of these require one or more message-IDs to be specified in the command line, which is where `exiqgrep -i` as described above really comes in handy.

Start a queue run:

root@localhost# exim -q -v

Start a queue run for just local deliveries:

root@localhost# exim -ql -v

Remove a message from the queue:

root@localhost# exim -Mrm  [  ... ]

Freeze a message:

root@localhost# exim -Mf  [  ... ]

Thaw a message:

root@localhost# exim -Mt  [  ... ]

Deliver a message, whether it's frozen or not, whether the retry time has been reached or not:

root@localhost# exim -M  [  ... ]

Deliver a message, but only if the retry time has been reached:

root@localhost# exim -Mc  [  ... ]

Force a message to fail and bounce as "cancelled by administrator":

root@localhost# exim -Mg  [  ... ]

Remove all frozen messages:

root@localhost# exiqgrep -z -i | xargs exim -Mrm

Remove all messages older than five days (86400 * 5 = 432000 seconds):

root@localhost# exiqgrep -o 432000 -i | xargs exim -Mrm

Freeze all queued mail from a given sender:

root@localhost# exiqgrep -i -f luser@example.tld | xargs exim -Mf

View a message's headers:

root@localhost# exim -Mvh 

View a message's body:

root@localhost# exim -Mvb 

View a message's logs:

root@localhost# exim -Mvl 

Add a recipient to a message:

root@localhost# exim -Mar  
[
... ]

Edit the sender of a message:

root@localhost# exim -Mes  

Access control

Exim allows you to apply access control lists at various points of the SMTP transaction by specifying an ACL to use and defining its conditions in exim.conf. You could start with the HELO string.

# Specify the ACL to use after HELO
acl_smtp_helo = check_helo

# Conditions for the check_helo ACL:
check_helo:

deny message = Gave HELO/EHLO as "friend"
log_message = HELO/EHLO friend
condition = ${if eq {$sender_helo_name}{friend} {yes}{no}}

deny message = Gave HELO/EHLO as our IP address
log_message = HELO/EHLO our IP address
condition = ${if eq {$sender_helo_name}{$interface_address} {yes}{no}}

accept

NOTE: Pursue HELO checking at your own peril. The HELO is fairly unimportant in the grand scheme of SMTP these days, so don't put too much faith in whatever it contains. Some spam might seem to use a telltale HELO string, but you might be surprised at how many legitimate messages start off with a questionable HELO as well. Anyway, it's just as easy for a spammer to send a proper HELO than it is to send HELO im.a.spammer, so consider yourself lucky if you're able to stop much spam this way.

Next, you can perform a check on the sender address or remote host. This shows how to do that after the RCPT TO command; if you reject here, as opposed to rejecting after the MAIL FROM, you'll have better data to log, such as who the message was intended for.

# Specify the ACL to use after RCPT TO
acl_smtp_rcpt = check_recipient

# Conditions for the check_recipient ACL
check_recipient:

# [...]

drop hosts = /etc/exim_reject_hosts
drop senders = /etc/exim_reject_senders

# [ Probably a whole lot more... ]

This example uses two plain text files as blacklists. Add appropriate entries to these files - hostnames/IP addresses to /etc/exim_reject_hosts, addresses to /etc/exim_reject_senders, one entry per line.

It is also possible to perform content scanning using a regex against the body of a message, though obviously this can cause Exim to use more CPU than it otherwise would need to, especially on large messages.

# Specify the ACL to use after DATA
acl_smtp_data = check_message

# Conditions for the check_messages ACL
check_message:

deny message = "Sorry, Charlie: $regex_match_string"
regex = ^Subject:: .*Lower your self-esteem by becoming a sysadmin

accept

Fix SMTP-Auth for Pine

If pine can't use SMTP authentication on an Exim host and just returns an "unable to authenticate" message without even asking for a password, add the following line to exim.conf:

  begin authenticators

fixed_plain:
driver = plaintext
public_name = PLAIN
server_condition = "${perl{checkuserpass}{$1}{$2}{$3}}"
server_set_id = $2
> server_prompts = :

This was a problem on CPanel Exim builds awhile ago, but they seem to have added this line to their current stock configuration.

Log the subject line

This is one of the most useful configuration tweaks I've ever found for Exim. Add this to exim.conf, and you can log the subject lines of messages that pass through your server. This is great for troubleshooting, and for getting a very rough idea of what messages may be spam.

log_selector = +subject

Reducing or increasing what is logged.

Disable identd lookups

Frankly, I don't think identd has been useful for a long time, if ever. Identd relies on the connecting host to confirm the identity (system UID) of the remote user who owns the process that is making the network connection. This may be of some use in the world of shell accounts and IRC users, but it really has no place on a high-volume SMTP server, where the UID is often simply "mail" or whatever the remote MTA runs as, which is useless to know. It's overhead, and results in nothing but delays while the identd query is refused or times out. You can stop your Exim server from making these queries by setting the timeout to zero seconds in exim.conf:

rfc1413_query_timeout = 0s

Disable Attachment Blocking

To disable the executable-attachment blocking that many Cpanel servers do by default but don't provide any controls for on a per-domain basis, add the following block to the beginning of the /etc/antivirus.exim file:

if $header_to: matches "example\.com|example2\.com"
then
finish
endif

It is probably possible to use a separate file to list these domains, but I haven't had to do this enough times to warrant setting such a thing up.

Searching the logs with exigrep

The exigrep utility (not to be confused with exiqgrep) is used to search an exim log for a string or pattern. It will print all log entries with the same internal message-id as those that matched the pattern, which is very handy since any message will take up at least three lines in the log. exigrep will search the entire content of a log entry, not just particular fields.

One can search for messages sent from a particular IP address:

root@localhost# exigrep '<= .* \[12.34.56.78\] ' /path/to/exim_log

Search for messages sent to a particular IP address:

root@localhost# exigrep '=> .* \[12.34.56.78\]' /path/to/exim_log

This example searches for outgoing messages, which have the "=>" symbol, sent to "user@domain.tld". The pipe to grep for the "<=" symbol will match only the lines with information on the sender - the From address, the sender's IP address, the message size, the message ID, and the subject line if you have enabled logging the subject. The purpose of doing such a search is that the desired information is not on the same log line as the string being searched for.

root@localhost# exigrep '=> .*user@domain.tld' /path/to/exim_log | fgrep '<='

Generate and display Exim stats from a logfile:

root@localhost# eximstats /path/to/exim_mainlog

Same as above, with less verbose output:

root@localhost# eximstats -ne -nr -nt /path/to/exim_mainlog

Same as above, for one particular day:

root@localhost# fgrep YYYY-MM-DD /path/to/exim_mainlog | eximstats

Bonus!

To delete all queued messages containing a certain string in the body:

root@localhost# grep -lr 'a certain string' /var/spool/exim/input/ | \
sed -e 's/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g' | xargs exim -Mrm

Note that the above only delves into /var/spool/exim in order to grep for queue files with the given string, and that's just because exiqgrep doesn't have a feature to grep the actual bodies of messages. If you are deleting these files directly, YOU ARE DOING IT WRONG! Use the appropriate exim command to properly deal with the queue.

If you have to feed many, many message-ids (such as the output of an `exiqgrep -i` command that returns a lot of matches) to an exim command, you may exhaust the limit of your shell's command line arguments. In that case, pipe the listing of message-ids into xargs to run only a limited number of them at once. For example, to remove thousands of messages sent from joe@example.com:

root@localhost# exiqgrep -i -f '' | xargs exim -Mrm

Speaking of "DOING IT WRONG" -- Attention, CPanel forum readers

I get a number of hits to this page from a link in this post at the CPanel forums. The question is:

Due to spamming, spoofing from fields, etc., etc., etc., I am finding it necessary to spend more time to clear the exim queue from time to time. [...] what command would I use to delete the queue

The answer is: Just turn exim off, because your customers are better off knowing that email simply isn't running on your server, than having their queued messages deleted without notice.

Or, figure out what is happening. The examples given in that post pay no regard to the legitimacy of any message, they simply delete everything, making the presumption that if a message is in the queue, it's junk. That is total fallacy. There are a number of reasons legitimate mail can end up in the queue. Maybe your backups or CPanel's "upcp" process are running, and your load average is high -- exim goes into a queue-only mode at a certain threshold, where it stops trying to deliver messages as they come in and just queues them until the load goes back down. Or, maybe it's an outgoing message, and the DNS lookup failed, or the connection to the domain's MX failed, or maybe the remote MX is busy or greylisting you with a 4xx deferral. These are all temporary failures, not permanent ones, and the whole point of having temporary failures in SMTP and a mail queue in your MTA is to be able to try again after awhile.

Exim already purges messages from the queue after the period of time specified in exim.conf. If you have this value set appropriately, there is absolutely no point in removing everything from your queue every day with a cron job. You will lose legitimate mail, and the sender and recipient will never know if or why it happened. Do not do this!

If you regularly have a large number of messages in your queue, find out why they are there. If they are outbound messages, see who is sending them, where they're addressed to, and why they aren't getting there. If they are inbound messages, find out why they aren't getting delivered to your user's account. If you need to delete some, use exiqgrep to pick out just the ones that should be deleted.

Reload the configuration

After making changes to exim.conf, you need to give the main exim pid a SIGHUP to re-exec it and have the configuration re-read. Sure, you could stop and start the service, but that's overkill and causes a few seconds of unnecessary downtime. Just do this:

root@localhost# kill -HUP `cat /var/spool/exim/exim-daemon.pid`

You should then see something resembling the following in exim_mainlog:

pid 1079: SIGHUP received: re-exec daemon
exim 4.52 daemon started: pid=1079, -q1h, listening for SMTP on port 25 (IPv4)

Wednesday, July 22, 2009

Securing /tmp and /dev/shm

The first step is to check if /tmp is already secure. Some data centers do not create a /tmp partition while others do.

#df -h |grep tmp


If that displays nothing then go below to create a tmp partition. If you do have a tmp partition you need to see if it mounted with noexec.

#cat /etc/fstab |grep tmp

If there is a line that includes /tmp and noexec then it is already mounted as non-executable. If not follow the instructions below to create one without having to physically format your disk. Idealy you would make a real partition when the disk was originally formated, that being said I have not had any trouble create a /tmp partition using the following method.

Create a ~1000Mb partition

#cd /dev/; dd if=/dev/zero of=tmpMnt bs=1024 count=1000000

Format the partion

#mkfs.ext2 /dev/tmpMnt

When it asks about not being a block special device press Y


Make a backup of the old data

#cp -Rp /tmp /tmp_backup

Mount the temp filesystem

#mount -o loop,noexec,nosuid,rw /dev/tmpMnt /tmp

Set the permissions

#chmod 0777 /tmp

Copy the old files back

#cp -Rp /tmp_backup/* /tmp/

Once you do that go ahead and restart mysql and make sure it works ok. We do this because mysql places the mysql.sock in /tmp which neeeds to be moved. If not it migth have trouble starting. If it does you can add this line to the bottom of the /etc/fstab to automatically have it mounted:

Open the file in vi:

#vi /etc/fstab

Now add this single line at the bottom:

/dev/tmpMnt /tmp ext2 loop,noexec,nosuid,rw 0 0

While we are at it we are going to secure /dev/shm. Look for the mount line for /dev/shm and change it to the following:

none /dev/shm tmpfs noexec,nosuid 0 0

Umount and remount /dev/shm for the changes to take effect.

#umount /dev/shm
#mount /dev/shm


Next delete the old /var/tmp and create a link to /tmp

#rm -rf /var/tmp/
#ln -s /tmp/ /var/


If everything still works fine you can go ahead and delete the /tmp_backup directory.

#rm -rf /tmp_backup

You /tmp, /var/tmp, and /dev/shm are now mounted in a way that no program can be directly run from these directories. Like I have said in other articles there are still ways in but this is one of the many layers of security you should have on your system.

Change mysql data directory

The default location is /var/lib/mysql

You can change mysql data directory by adding the following entries in /etc/my.cnf file

datadir=newlocation/path

save the file, move the necessary database files from /var/lib/mysql to the new location and restart mysql.

To check if the new location is added correctly, login to mysql as root and create a test database and check the new location if the new database files are added or not.

If mysql doesnt start after restarting then check the logs for an error

# tail -f /var/log/mysqld.log

If there are no specific errors mentioned check if selinux is enabled or not. If its enabled then you may disable it and try starting mysql.

commands to check if selinux is enabled

#getenforce

the result will be like enabled, permissive or targeted You can disable it by editing the configuration file /etc/selinux/config (RHEL/centos)

How to add a range of IP's

For a small range of IPs, you can manually add each IP to a file called ifcfg-eth0:x, which resides in /etc/sysconfig/network-scripts/.
For instance, if you want to add 10 IP addresses, you'll have to create 10 files in that directory, starting with ifcfg-eth0:0 and ending
with ifcfg-eth0:10. Each file will contain:

CODE

DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.2
NETMASK=255.255.255.0
NETWORK=192.168.0.0
BROADCAST=192.168.0.255
TYPE=Ethernet

The IPADDR will increase from 192.168.0.2 to 192.168.0.12.

But what if you have to add 100 IP addresses? It could be physically possible to manually add a file for each of them. But how about
1000 IP addresses? Or 10,000? Fortunately, RedHat based systems offer a quick and easy way to bind a range of IPs, eliminating the
need to create a lot of files and saving a lot of your time.

Create a file called ifcfg-eth0-range0 in the /etc/sysconfig/network-scripts directory. This file must contain the following strings:

CODE

IPADDR_START=192.168.0.10
IPADDR_END=192.168.0.110
CLONENUM_START=0

Let's see what each of them does:

IPADDR_START: This is the first IP from the address range you want to bind to your ethernet device.
IPADDR_END: This is, of course, the last IP from that address range.
CLONENUM_START: This is the number that will be assigned to the first IP alias interface. For instance, if your Internet interface is eth0 and CLONENUM_START is 0, then this config file will create 100 interfaces starting with eth0:0 (eth0:0, eth0:1, eth0:2 etc) and ending with eth0:100.

NOTE! Be careful if you need to add more ranges of IPs. You'll have to use a proper value for CLONENUM_START. For instance, if you need to add a second range with 100 IPs besides the one above, create a new file called ifcfg-eth0-range1 and set the CLONENUM_START to 101 so an overwrite will be avoided.

After making any changes to any of the files created in the network-scripts directory, you have to run the following command so the changes are applied and the address range is activated:

# service network restart

Thursday, July 2, 2009

Adding New repositories to YUM

to add new repos in yum follow the steps below.

cd /etc/yum.repos.d/
vi dag.repo
// the add the following lines in that file//

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

//save and quit//

for remi repo visit the url below

http://blog.famillecollet.com/pages/Config-en



Thursday, June 4, 2009

Yum

Useful Yum Commands

yum install package_name download and install a rpm package

yum localinstall package_name.rpm That will install an RPM, and try to resolve all the dependencies for you using your repositories.

yum update update all rpm packages installed on the system

yum update package_name upgrade a rpm package

yum remove package_name remove a rpm package

yum list list all packages installed on the system

yum search package_name find a package on rpm repository

yum clean packages clean up rpm cache erasing downloaded packages

yum clean headers remove all files headers that the system uses to resolve dependency

yum clean all remove from the cache packages and headers files

Monday, May 25, 2009

Installing FFmpeg and FFmpeg-php

System Configuration/Prerequisites

The server that I had to install on was running:

  • Centos 5.x
  • cPanel 11 (but of course, you don’t need cPanel to install FFmpeg and ffmpeg-php)
  • Yum (or anything of the likes would do)
  • And I presume you have root access

Getting the required Files

Firstly, we would have to download all the required files to a folder. For me, I picked /usr/local/src, but it could be just any other folder you’d like.

Move into the directory that you’d like to download the source files to and run the following commands:

wget http://www3.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2
wget http://www4.mplayerhq.hu/MPlayer/releases/MPlayer-1.0rc2.tar.bz2
wget http://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
wget http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.1.2.tar.gz
wget http://easynews.dl.sourceforge.net/sourceforge/lame/lame-3.97.tar.gz
wget http://easynews.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.3.1.tbz2

This is what I used in my setup. Additional libraries should be downloaded if you need them. Also, I wouldn’t say that these are the latest binaries, but they work for me for now - you should check for updates if you wish. You may also want to change the location of the SourceForge downloads.

Now extract all the files you’ve downloaded:

bunzip2 essential-20061022.tar.bz2; tar xvf essential-20061022.tar
bunzip2 MPlayer-1.0rc2.tar.bz2 ; tar -xvf MPlayer-1.0rc2.tar
tar zxvf flvtool2-1.0.6.tgz
tar zxvf libogg-1.1.3.tar.gz
tar zxvf libvorbis-1.1.2.tar.gz
tar zxvf lame-3.97.tar.gz
bunzip2 ffmpeg-php-0.5.3.1.tbz2; tar xvf ffmpeg-php-0.5.3.1.tar

Along with the additional libraries you could have possibly downloaded.

Installation

Now that we’re done downloading the files we need, it’s time to start the installation.

Codecs

Create a folder to store the Codecs that ffmpeg will need:

mkdir /usr/local/lib/codecs/
mv essential-20061022/* /usr/local/lib/codecs/
chmod -Rf 755 /usr/local/lib/codecs/

Subversion/Ruby/

yum install subversion
yum install ruby
yum install ncurses-devel

LAME

cd lame-3.97
export LD_LIBRARY_PATH=/usr/local/lib
./configure
make
make install

libogg

cd libogg-1.1.3
./configure
make
make install

libvorbis

cd libvorbis-1.1.2
./configure
make
make install

flvtool2

cd flvtool2-1.0.6
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

MPlayer

cd MPlayer-1.0rc2
./configure
make
make install

Now for the big one, ffmpeg.

Installing FFmpeg

Generally, we would install the latest version of ffmpeg. But as of the date of this post, the latest version of ffmpeg does not wok with ffmpeg-php. We will need to checkout a previous version from the SVN.

Inside your src folder, run the following to checkout this version of ffmpeg which works.

svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk/ ffmpeg -r15261

Once it is done downloading, go into the ffmpeg folder

Note: If a version of ffmpeg was previously installed, run the following command in the ffmpeg folder first:

make uninstall
make clean

Start the installation. You may need to add/enable additional libraries into ./configure.

cd ffmpeg
./configure --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared
make
make install

During installation, you may get an error like:

Unable to create and execute files in /tmp. Set the TMPDIR environment
variable to another directory and make sure that /tmp is not mounted
noexec.
Sanity test failed.

To fix this, run the following commands to create a temporary tmp directory:

mkdir tmp
chmod 777 tmp
export TMPDIR=./tmp

After installation, remember to change the tmp directory back to your server’s tmp disk by doing the following:

export TMPDIR=/tmp

Check if ffmpeg is working by running the following:

ffmpeg -version

It should return something similar to:

FFmpeg version SVN-r15261, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared
libavutil 49.10. 0 / 49.10. 0
libavcodec 51.71. 0 / 51.71. 0
libavformat 52.22. 1 / 52.22. 1
libavdevice 52. 1. 0 / 52. 1. 0

If the version isn’t “SVN-r15261″, then there is something wrong and you may need to reinstall ffmpeg.

If something like the following is returned:

ffmpeg: error while loading shared libraries: libavdevice.so.52: cannot open shared object file: No such file or directory

Search for the missing library (in this case libaddevice.so.52) with the following:

find / -name 'libavdevice.so.*'

The returned results may look something like this. The one that we want is the one in the lib folder and not the src folder.

/usr/local/src/ffmpeg/libavdevice/libavdevice.so.52
/usr/local/lib/libavdevice.so.52
/usr/local/lib/libavdevice.so.52.1.0

With that, since the libraries are in the /usr/local/lib/ folder, we run the following:

export LD_LIBRARY_PATH=/usr/local/lib/

Otherwise, simply change the stuff after “=” to the path where the library is.

Sweet! Now that we’ve got FFmpeg working successfully, time to install ffmpeg-php.

Installing ffmpeg-php

Start the installation by running the following (again, run make clean as necessary):

cd ffmpeg-php-0.5.3.1
phpize
./configure
make
make install

You may meet the following errors during installation:

checking for ffmpeg headers… configure: error: ffmpeg headers not found. Make sure you’ve built ffmpeg as shared libs using the –enable-shared option

Solution: Simply create a ffmpeg folder in /usr/local/include/ and run the following to copy all the header files:

cp /usr/local/include/libavcodec/* /usr/local/include/ffmpeg
cp /usr/local/include/libavdevice/* /usr/local/include/ffmpeg
cp /usr/local/include/libavformat/* /usr/local/include/ffmpeg
cp /usr/local/include/libavutil/* /usr/local/include/ffmpeg
cp /usr/local/include/libswscale/* /usr/local/include/ffmpeg

make: *** [ffmpeg_frame.lo] Error 1

Solution: Execute the following in the ffmpeg-php folder. I’ve no idea why the files are named wrongly too.

cp ffmpeg_frame.loT ffmpeg_frame.lo

Upon successful installation, the installer will give you a very long sting to tell you where the extension was installed to. This is a unique string. The following is what I got:

Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/

This has to be added to into php.ini.
In cPanel Servers, the php.ini file is located in /usr/local/lib. Otherwise, it should be in etc/php.ini.

Add the following line into php.ini (at the bottom or wherever you want):

extension=ffmpeg.so

Finalizing Installation

Restart Apache on the server.

service httpd restart

Check that ffmpeg is running on the server:

php -i | grep ffmpeg

The following should be returned:

ffmpeg
ffmpeg support (ffmpeg-php) => enabled
ffmpeg-php version => 0.5.3.1
ffmpeg-php gd support => enabled
ffmpeg.allow_persistent => 0 => 0

If an error like the following appears:

php: symbol lookup error: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so: undefined symbol: av_free_static

Simply rebuild ffmpeg-php and it should work again.

And you’re done!

You have just successfully installed FFmpeg and ffmpeg-php on your server!

Tuesday, May 12, 2009

SSH key- passwordless login

On the source server do the following

ssh-keygen -t dsa -f filename

It will prompt for a passphrace, it is desirable to leave it empty.
Two files will be created

filename
filename.pub

copy the filename.pub file to the destination server to the location /root/.ssh add the public key entry into authorized_keys as follows

cat filename.pub >> authorized_keys

/etc/init.d/sshd restart