Using Doctrine with Zend framework

Copy Doctrine.php and Doctrine folder to library folder.

Now add following function to your Bootstrap.php file.

public function _initDoctrine(){
require_once 'Doctrine.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$manager = Doctrine_Manager::getInstance();
$options = $this->getOptions(); // zf application config array
$dsn = $options['dsn'];
$conn = Doctrine_Manager::connection($dsn, 'defaultConn');
'generateBaseClasses' => true,
'generateTableClasses'=> true,
'classPrefixFiles'=> false,
'baseClassesDirectory'=> '.'

The above code creates your Doctrine connection, so else where in your code you can use $conn = Doctrine_Manager::connection($dsn, ‘defaultConn’); to get a connections to database.

Also the above code gets DSN setting for you database which looks like dsn = “mysql://username:password@host/database_name” in your application.ini file.

The function Doctrine_Core::generateModelsFromDb with above settings will generate table and record classes for all the tables in your database and would save them to your application/models folder.

As all the classes generated by Doctrine would be prefixed with “Model_” you can would be able to use them anywhere in your Zend framework application because of ZF autoloader. As the above generated class would follow ZF convention for models.

How to fix Warning: is_readable(): open_basedir restriction in effect in Zend Framework => 1.10

If you are getting load of this error after upgrading to Zend framework 1.10 and greater, you can fix it by changing Zend/Loader.php file

Change method isReadable() to following
Also make sure anything in your include path should be in your basedir option too.
Waring!!! use the code at your own risk as I have not done extensive tests.

     * Returns TRUE if the $filename is readable, or FALSE otherwise.
     * This function uses the PHP include_path, where PHP's is_readable()
     * does not.
     * Note from ZF-2900:
     * If you use custom error handler, please check whether return value
     *  from error_reporting() is zero or not.
     * At mark of fopen() can not suppress warning if the handler is used.
     * @param string   $filename
     * @return boolean
    public static function isReadable($filename)
        if (is_readable($filename)) {
            // Return early if the filename is readable without needing the 
            // include_path
            return true;

        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'
            && preg_match('/^[a-z]:/i', $filename)
        ) {
            // If on windows, and path provided is clearly an absolute path, 
            // return false immediately
            return false;

        if(strpos($filename, '/')==0) return false; //if absolute path skip

        foreach (self::explodeIncludePath() as $path) {
            if ($path == '.') {
                if (is_readable($filename)) {
                    return true;
            $file = $path . '/' . $filename;
            if (is_readable(realpath($file))) {
                return true;
        return false;

How to make firefox search rather by default

1. First install google toolbar from

2. Restart firefox

3. right click on Google toolbar, select “Toolbar options”.

4. Click on Search from the top icons, now on this page change “Use Google site” option to

5. Click on Layout from the top options, now select option “Replace firefox search box and hide Google toolbar”.

6. Click save, done.

How to Find & replace recursively in Linux from command line script

Following is the script to find any phrase and replace it with another.

for i in `grep –include=”*\.include” -rl ‘phrase to search’ /var/www/`; do

sed –in-place=bak -e ‘s/phrase to search/phrase to replace with/g’ “$i”


The above script searches folder /var/www and all of its sub folders with any file with extension .include for phrase “phrase to search” and will replace all the found phrases with phrase “phrase to replace with

How to auto start Red 5 on Ubuntu or any linux distro

Following script monitors RMTP port, which indicates if Red5 is running or not

if (netstat -na | grep -q :1935) ; then
echo “Red5 running.”
bash /usr/local/red5/
If RMTP is open for connection nothing is done, else the script tries to start Red5 server by executing the startup script.
so save the above script in red5 folder say /usr/local/red5/
now we need to add a cron job to run the at specified intervals, e.g. we will run it every 2 mins.
edit cron jobs with following command
crontab -e
now add following line to the cron jobs
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,59 * * * * /usr/local/red5/ & >/dev/null 2>&1
The above setup will monitor red5 every two minute , if server is not running it will start the server.

The script whose uid is 33 is not allowed to access /tmp owned by uid 0

If SAFE MODE is on in PHP, the owner ID of the PHP file needs to be same to any folder or file it tries to access. So if you try to use sessions and if your PHP is configured to use /tmp folder for saving session data it can cause error shown in title of this blog post.

To fix it check following directive is set as follows

session.save_path = /tmp

If yes create folder


change owner of the above folder to same as that of the web server, so for e.g. you would say

chown www-data:www-data /var/lib/php5/session

now change /etc/php.ini  or /etc/php5/apache2/php.ini

to use following setting

session.save_path = /var/lib/php5/session

now reload web server e.g.

service apache2 reload


/etc/init.d/apache reload

This should fix the problem

Problems faced configuring LAMP

1. All the virtual host need to use the private IP address in the virtual host directive rather the elastic IP or it will not work.





<VirtualHost *:80>



2. Access denied for user ‘www-data’@’localhost’ shows up if the first attempt to connect to database has failed and application has used mysql_query after that, so php won’t find any active connections so it would try default settings to connect to database, quite hard to fix.

Mysql Replication Settings

On Mysql Server

1. Turn binary logging on and add server id

CAUTION ! DO NOT USE “log-bin=/var/log/mysql/mysql-bin.log’


2. Create replication account on the server

GRANT REPLICATION SLAVE ON *.* TO ‘repl’@’slave-ip-address’ IDENTIFIED BY ‘password-here’;

3. Keep the above mysql console open, start new terminal and connect to server via new terminal

cd /var/lib/mysql

now use dir, you should see all the database folders

4. Time to lock all the databases on server.


now on the new console enter

root@server:/var/lib/mysql#tar -cvf /tmp/mysql-snapshot.tar ./ –exclude mysql &

enter following in mysql console, this will show the position of server in log file, keep this window open and note file and position column


now enter following in mysql console


5. Copy the tar file from master to slave server

scp -i permission-file.pem /tmp/mysql-snapshot.tar root@slave-server-ip:/root/

6. Extract the tar file on slave server

cd /var/lib/mysql

mv /root/mysql-snapshot.tar .

tar –extract –file=mysql-snapshot.tar

7. Change server id on slave mysql server, add following to config file /etc/my.cnf or /etc/mysql/my.cnf



8. Start or restart Slave mysql server with

service mysql restart

9. Login to mysql console and enter

mysql>stop slave;


mysql>start slave;

If every thing is done correctly the slave should start replicating.

Once master has been set on and slave started on Slave, after restart the slave will auto start.

If something is not right on slave, login to slave mysql console

use following

stop slave;

reset slave;

now from the new bash console, reextract the tar file replacing existing file with following command

root@slave-server:/var/lib/mysql# tar –overwrite –extract –file=mysql-snapshot.tar

now repeat step 9.

Quick Tips

Question: SSH idle connection time out issue?

Answer: On client machine add following

ServerAliveInterval 5

to /etc/ssh/ssh_config

Taken from

Error in Ubuntu:

perl: warning: Setting locale failed.

perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = “en_GB.UTF-8”
are supported and installed on your system.

perl: warning: Setting locale failed.perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = “en_GB.UTF-8”    are supported and installed on your system.


On bash console enter following

locale-gen en_GB.UTF-8

How to install red5 on Fedora 8

Goto download most recent jdk for linux with jdk-rpm.bin

chmod o+x jdk-rpm.bin


java is now installed

test commands

javac -version

java -version

now follow step 2,3,4 and 5 from

Following content are taken from on 6th august 2010

2) Download and Install Ant (Apache Project)

Ant will need to compile RED5 server code. Ant comes in binary form, so just download and install it in /usr/local directory.

cd /usr/src
tar jxvf apache-ant-1.8.0-bin.tar.bz2
mv apache-ant-1.8.0 /usr/local/ant

3) Export Variables for Ant and Java

export ANT_HOME=/usr/local/ant
export JAVA_HOME=/usr/lib/jvm/java
export PATH=$PATH:/usr/local/ant/bin
export CLASSPATH=.:$JAVA_HOME/lib/

Also export these variables in /etc/bashrc to become available for every user login or for any terminal opens.

echo ‘export ANT_HOME=/usr/local/ant’ >> /etc/bashrc
echo ‘export JAVA_HOME=/usr/lib/jvm/java’ >> /etc/bashrc
echo ‘export PATH=$PATH:/usr/local/ant/bin’ >> /etc/bashrc
echo ‘export CLASSPATH=.:$JAVA_HOME/lib/’ >> /etc/bashrc

4) Download and Install RED5 Server

Here the latest version available for RED5 is 0.7 on site but download from google code using svn as the tarball of 0.7 on site is missing some of the files.

cd /usr/src
svn checkout red5
mv red5 /usr/local/
cd /usr/local/red5
ant prepare
ant dist

you will see a ton of lines, but you should get at last


that’s mean its install and now copy the conf directory from dist/ and test the red5 installation.

cp -r dist/conf .

If it shows Installer service created in the last then everything is fine here, press ctrl+c and move to next step to create init script.

5) Init Script

Now we will create init script for red5 to start, stop and restart easily.

vi /etc/init.d/red5

The init script code also be viewed below. following script on works with fedora or redhats, for ubuntu edit cron with command ‘crontab -e’ and add  ‘@reboot cd /usr/local/red5/ ; ./ & >/dev/null 2>&1’ and now reboot

# For RedHat and cousins:
# chkconfig: 2345 85 85
# description: Red5 flash streaming server
# processname: red5


# Source function library
. /etc/rc.d/init.d/functions

[ -r /etc/sysconfig/red5 ] && . /etc/sysconfig/red5


case “$1″ in
echo -n $”Starting $PROG: ”
$DAEMON >/dev/null 2>/dev/null &
if [ $RETVAL -eq 0 ]; then
echo $! > $PIDFILE
touch /var/lock/subsys/$PROG

[ $RETVAL -eq 0 ] && success $”$PROG startup” || failure $”$PROG startup”
echo -n $”Shutting down $PROG: ”
killproc -p $PIDFILE
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROG
$0 stop
$0 start
status $PROG -p $PIDFILE
echo $”Usage: $0 {start|stop|restart|status}”

exit $RETVAL

chmod a+x /etc/init.d/red5

Now start the service

/etc/init.d/red5 start

check status

/etc/init.d/red5 status
red5 (pid  XXXXX) is running…

again you can do stop, restart.