How to install FFMPEG support with PHP and Apache on Fedora 10

June 30th, 2009 2 Comments »

The FFMPEG is a great tool which converts video and audio from one format to another and it does the job great ! This is often used in conjunction with Apache and PHP to convert video files on the fly to another format when they are uploaded.

Install the following pre-requisites which will install most of the codecs and stuff that you’ll ever need:

yum -y install ffmpeg mplayer mencoder flvtool2 libogg libvorbis lame

By default the libraries go to another directory, here is a work-around (copy the files to appropriate directories):

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

then install:

yum -y install ffmpeg-devel php-devel

You will have all the headers and stuff that are needed and at this point you are good to compile ffmpeg-php from source, which is the PHP module that allows the use of FFMEG on web servers. Download ffmpeg-php from the developer’s site and extract the source files and then:

cd ffmpeg-php/
./configure
make
make install

Once the installation is done:

echo 'extension = "ffmpeg.so"' > /etc/php.d/ffmpeg.ini

You can verify you installation with:

php -r 'phpinfo();' |grep ffmpeg

Which should print out the presence of FFMPEG-PHP module. If it does, enjoy!

Connect to MSSQL with PHP on Fedora 10

May 30th, 2009 No Comments »

Connecting to MSSQL datbase from Linux is a pretty much straight forward process when done right. During my first setup I spent hours compiling, configuring, removing blah blah…freetds with php. At the end of the day it turned out that I was connecting a wrong port, not the actual MSSQL port.

In Linux Freetds provide libraries to connect to the MSSQL database, which can be installed with a yum command:

# yum install php-mssql

the above command asks to install MSSQL extension for PHP, but yum will take care of all the dependencies including Freetds.

Once installed you can use a low level tool like tsql which comes with Freetds to check you setup, but before that edit the Freetds config file (/etc/freetds.conf):

[MSSQL]
host = 192.168.1.1
port = 1433
tds version = 8.0

above is a simple configuration that I use to connect to SQL2005/2000 databases. The braces contain a name (any name you like) to refer to the connection from Linux, and host is the IP of the MSSQL Server, port is the port MSSQL is listening on and the tds version is the TDS Protocol Version to use when connecting with database. Now regarding the port, MAKE SURE that you are connecting to the correct MSSQL port. OK, Lets check with tsql now:

# tsql -S MSSQL -U user -P pass

that should give u a prompt like “1>”. Otherwise go back and check your MSSQL server, things like port,ecnryption blah blah.

Now check whether PHP can connect:

# php -r 'echo mssql_connect("MSSQL","user","pass");'

this should print a rsource ID. That’s all to it. Get happy with coding now.

Enable Plymouth on Fedora 10

April 9th, 2009 3 Comments »

Fedora 10 introduces a totally new Graphical Bootloader called Plymouth. Which is better simple and looks good for the eyes. However on some systems Plymouth cannot be seen by default due to modsetting driver issues. This is because kernel modsetting drivers are not yet available for all Display Adapters. So instead of seeing the Plymouth bootloader, Fedora 10 drops back to a text-based DULL bootloader.

f10-bars
Text-Base Bootloader of Fedora 10

With little modification, one can enable Plymouth.

plymouth-solar

Edit /boot/grub/grub.conf:

title Fedora (2.6.27.5-117.fc10.i686)
        root (hd0,9)
        kernel /boot/vmlinuz-2.6.27.5-117.fc10.i686 ro root=UUID=bb061789-157b-4cb2-85c8-633026e8df1e rhgb quiet vga=0x318
        initrd /boot/initrd-2.6.27.5-117.fc10.i686.img

note that I have added the parameter “vga=0×318″ which stands for 1024×768 reolution with 32MB video memory. This works typically on most systems. However if it fails, set “vga=ask” instead, so that the bootloader provides you with available options. Once you figure out a good setting remember the value and make it permanent in the grub.conf file.

In case you want some new Plymouth themes there are very few (as of this writing). To install them do:

# yum install plymouth-plugin-*

Then to change to a new plugin do:

# plymouth-set-default-plugin <pluginname>
# /usr/libexec/plymouth/plymouth-update-initrd

where you can replace <pluginname> with anything from fade-in, pulser, spinfinity or solar whichi is the default.

Setup Oracle Database 11g on Fedora 10 64-bit

January 7th, 2009 No Comments »

First of all start by download the Oracle Database 11g 64-bit from Oracle Technology Network. While you wait for the download, finish some of the pre-install tasks:

1. Insert the following lines to /etc/sysctl.conf

kernel.shmall = 15032385536
kernel.shmmax = 4294967296
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 6553600
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=4194304
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=262144

Most of these parameters are set by default to the correct parameters, however we can include them just to be sure or if you are feeling a little lazy to check their values one by one. It is also important to note that kernel.shmmax & kernel.shmall are in bytes. kernel.shmmax is the maximum size of any shared memory chunk  (the amount of memory a process can allocate at a time). kernel.shmall determines the maximum amount of memory that all shared memory can take. So it is often good practice to set kernel.shmmax to half the size of physical RAM and to set kernel.shmmax to about 75%-85% of physical RAM available on server.

type sysctl -p as root to apply the settings without a reboot.

2. Open /etc/security/limits.conf and insert the following lines:

oracle              soft    nproc   2047
oracle              hard    nproc   16384
oracle              soft    nofile  1024
oracle              hard    nofile  65536

3. Open /etc/pam.d/login and add the following lines:

session    required     /lib/security/pam_limits.so
session    required     pam_limits.so

4. Disable SELinux:

Open /etc/selinux/config and set the parameter SELINUX=disabled

Reboot the system for the new changes to take effect.

5. Install the necessary packages to install oracle:

[root@linux ~]# yum -y install binutils
[root@linux ~]# yum install glibc glibc-common libgcc libstdc++
[root@linux ~]# yum install make
[root@linux ~]# yum install elfutils-libelf elfutils-libelf-devel
[root@linux ~]# yum install glibc-devel gcc gcc-c++ libstdc++-devel
[root@linux ~]# yum install unixODBC unixODBC-devel
[root@linux ~]# yum install libaio libaio-devel
[root@linux ~]# yum install sysstat
[root@linux ~]# yum install php-devel
[root@linux ~]# yum install php-pear

I had some trouble with Oracle Universal Installer reagarding the 64-bit architecture. In order to successfully pass Oracle Installer pre-checks I had to install some of the 32-bit binaries and libraries too. I searched for the latest version of these binaries from rpmfind.net and downloaded them. And used yum to install them locally.

[root@linux ~]# wget ftp://rpmfind.net/linux/fedora/development/i386/os/Packages/compat-libstdc++-33-3.2.3-64.i386.rpm
[root@linux ~]# wget ftp://rpmfind.net/linux/fedora/releases/10/Everything/x86_64/os/Packages/compat-libstdc++-33-3.2.3-64.x86_64.rpm
[root@linux ~]# wget ftp://rpmfind.net/linux/fedora/releases/10/Everything/i386/os/Packages/libaio-0.3.107-4.fc10.i386.rpm
[root@linux ~]# wget ftp://rpmfind.net/linux/fedora/releases/10/Everything/i386/os/Packages/libstdc++-4.3.2-7.i386.rpm
[root@linux ~]# wget ftp://rpmfind.net/linux/fedora/updates/10/x86_64/glibc-devel-2.9-3.i386.rpm

[root@linux ~]# yum –localinstall *

6. Change the /etc/redhat-release file to include the following:

Red Hat Enterprise Linux Server release 5 (Tikanga)

7. Create the necessary users and groups for oracle:

[root@linux ~]# groupadd oinstall
[root@linux ~]# groupadd dba
[root@linux ~]# groupadd oper
[root@linux ~]# groupadd asmadmin
[root@linux ~]# useradd -g oinstall -G dba,oper,asmadmin oracle

Change the password for oracle user account:

[root@linux ~]# passwd oracle

8. Create the necessary directories and give the permissions:

[root@linux ~]# mkdir -p /u01/app/oracle/product/11.1.0/db_1
[root@linux ~]# chown -R oracle:oinstall /u01
[root@linux ~]# chmod -R 775 /u01

9. Set the environment variables for the oracle user in file /home/oracle/.bash_profile:

# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_HOSTNAME=localhost; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_1; export ORACLE_HOME
ORACLE_SID=ORCL; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi

Save the file.

10. Login to Oracle user and start the Oracle Installation:

[oracle@linux ~]$ unzip linux.x64_11gR1_database_1013.zip
[oracle@linux ~]$ cd database
[oracle@linux ~]$ ./runInstaller

Continue the step-by-step wizard to install Oracle 11g. After installation, open a web browser and visit https://localhost:1158/em/. Confirm the security excemption for SSL certificate and if you see the Oracle Enterprise Manager Interface; the installation went well.

11. Auto starting and stopping Oracle 11g:

First edit /u01/app/oracle/product/11.1.0/db_1/bin/dbstart script:

Change the line reading ORACLE_HOME_LISTNER=$1 to ORACLE_HOME_LISTNER=$ORACLE_HOME
then do the same for /u01/app/oracle/product/11.1.0/db_1/bin/dbshut script.

Now create a file /etc/init.d/oratab with the following contents:

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

ORA_HOME=/u01/app/oracle/product/11.1.0/db_1
ORA_OWNER=oracle

#if [ ! -f $ORA_HOME/bin/dbstart ]
#then
#    echo “Oracle startup: cannot start”
#    exit
#fi

case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
#        su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole"
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut"
#        su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
;;
esac

then do:

[root@linux ~]#chmod 750 /etc/init.d/oratab
[root@linux ~]# chkconfig oratab on
[root@linux ~]# ln -s /etc/init.d/oradb /etc/rc.d/rc3.d/K01oradb
[root@linux ~]# ln -s /etc/init.d/oradb /etc/rc.d/rc5.d/K01oradb

That will start and stop oracle on system reboot. Oracle can also be started and stopped using the service command of Fedora once this is done. If you want Oracle 11g itself on the server then the chapter is closed. However I need to run Apache along with Oracle 11g on this server. Therefore I should run Apache and PHP along with OCI8 extension which will call the internal Oracle Database 11g.

12. Set the environment variables for OCI8:

Edit /etc/profile and /etc/init.d/httpd files to include the following line:

export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1

13. Install OCI8:

[root@linux ~]# pecl install oci8

when the script asks for oracle path, simply press Enter. The module will compile and install automatically. Then edit /etc/php.ini to include:

extension=oci8.so

14. Start Apache and test connection:

[root@linux ~]# service httpd start

create a file called index.php with the following content in /var/ww/html :

echo $conn1 = oci_connect('username', 'password', '//localhost/SID');

change the appropriate values to suit your installation. Visit http://localhost/ from a browser and the output should print a resourceID. That’s all, enjoy!

Sript to Query Elections website for listed Party

November 26th, 2008 2 Comments »

This is a quick-dirty script that I wrote on request from a friend. It accepts names of files as arguments which should contain a list of National ID numbers. Then it would check each ID from Elections website to see which party the person is listed. Then gives the corresponding party names as a list. Here is a sample run:

[root@linux ~]# ./elections.pl test.txt
A000001 DHIVEHI RAYYITHUNGE PARTY
A000002 DHIVEHI RAYYITHUNGE PARTY
A000003 DHIVEHI RAYYITHUNGE PARTY
A000004 DHIVEHI RAYYITHUNGE PARTY
A000005 DHIVEHI RAYYITHUNGE PARTY
A092892 NOT REGISTERED
A113642 NOT REGISTERED
A103476 NOT REGISTERED
A068120 PEOPLES PARTY
A019583 NOT REGISTERED
A024360 NOT REGISTERED
A064775 NOT REGISTERED

thought this might be handy to someone else too…download