Category Archives: ubuntu

Thread Safety in php

Thread safety is a computer programming concept applicable in the context of multi-threaded programs. A piece of code is thread-safe if it only manipulates shared data structures in a manner that guarantees safe execution by multiple threads at the same time.

There have been a few options available for a while to get PHP performing well on linux or IIS.
One solution is to configure web service to use PHP in FastCGI mode which allows PHP processes to be recycled rather than killed off after each PHP request and also allows you to run several PHP processes at once, making PHP much much faster with the added bonus that as it is using the CGI interface there is little or no incompatibility issues with PHP extensions.

The utilization of non thread safe binaries does not allow to use FastCGI mode!

On debian/ubuntu
Thread Safety enable.
# aptitude install apache2-mpm-worker libapache2-mod-fcgid php5-cgi && a2enmod fcgid && /etc/init.d/apache2 restartThread Safety disable.
# aptitude install apache2-mpm-prefork libapache2-mod-php5 && a2dismod fcgid && /etc/init.d/apache2 restart

If your non thread safe binaries software not works, it was because installing apache2-dev package on my system automatically installs apache2-thread-dev whose apxs2 tells the PHP build system to build with thread-safety on. Therefore, the solution was to directly install apache2-prefork-dev package.

Reference: Wikipedia, Tnread Safety dis/able, Install/Purge package

phpSHIELD Loader

phpSHIELD is a premier php Encoder product. Loaders for phpSHIELD encoded scripts are free to download and install.

Check your servers PHP version. You do this by typing the command:
php -vCheck your system architecture. You do this by typing the command:
uname -i
The result will either be i386 or x86_64. You will need this information to download the correct PHPshield loaders.

Check your PHP extensions_directory. You do this by typing the command:
php -i|grep extension_dirMy path is
extension_dir => /usr/lib/php5/20090626 => /usr/lib/php5/20090626
You must first delete any loaders that may already be in your extensions directory
cd /usr/lib/php5/20090626
rm phpshield.*

Download PHPshield Loaders. You must now download the appropriate PHPshield loader, based on your system architecture. below is a list of the files we have available for download

  • Linux, i386, v5.2.x wget
  • Linux, x86_64, v5.2.x wget
  • Linux, i386, v5.3.x wget
  • Linux, x86_64, v5.3.x wget

mv phpshield.5.2.lin /usr/lib/php5/20090626/
mv ixed.5.3 /usr/lib/php5/20090626/
First you need to find out the location of your main php.ini file. This file is the main configuration file for PHP on your server.
You do this by typing the command belowphp -i|grep php.iniYou should get a result that shows something like thisLoaded Configuration File => /etc/php.ini
In the case of our example above, the path we want it /etc/php.ini (others, /etc/php5/apache2/php.ini)
Now run the command below. Remember to use your own php.ini directoy path in the command above
echo "extension=ixed.5.3" >> /etc/php.ini

Restart your web server
/etc/init.d/apache restart
/etc/init.d/apache2 restart

Reference: phpSHIELD PHP encoder, Loaders

FFmpeg, FFmpeg-PHP, Lame, Libogg, Libvorbis, FLVtool2, Mplayer, Mencoder, AMR Installation

apt-get update
apt-get upgrade
apt-get install libjpeg-progs libjpeg62 libjpeg62-dev libsdl1.2-dev php5-dev build-essential subversion ruby libcurses-ruby git-core yasm unzip

Download all the files needed
cd /opt/phpmotion
svn checkout svn:// ffmpeg
svn checkout svn:// mplayer

Extract all the files
tar zxvf lame-3.99.5.tar.gz
tar zxvf libogg-1.3.0.tar.gz
tar zxvf libvorbis-1.3.3.tar.gz
bzip2 -cd amrnb- | tar xvf -
bzip2 -cd amrwb- | tar xvf -
tar zxvf libtheora-1.1beta3.tar.gz
tar jxvf ffmpeg-php-0.6.0.tbz2
tar zxvf flvtool2-1.0.6.tgz
tar jxvf essential-amd64-20071007.tar.bz2

Install lame
cd /opt/phpmotion/lame-3.99.5
./configure && make && make install

Install libogg
cd /opt/phpmotion/libogg-1.3.0
./configure && make && make install

Install libvorbis
cd /opt/phpmotion/libvorbis-1.3.3
./configure && make && make install

Install flvtool2
cd /opt/phpmotion/flvtool2-1.0.6/
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

Copy Codecs for mplayer
mkdir /usr/local/lib/codecs
mv /opt/phpmotion/essential-amd64-20071007/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/
We also need to secure the tmp directory
mkdir /usr/local/src/tmp
chmod 777 /usr/local/src/tmp
export TMPDIR=/usr/local/src/tmp

Install mplayer & mencoder
cd /opt/phpmotion/mplayer
svn update
./configure --enable-jpeg
make && make install

Install AMR (for 3gp conversion)
Debian Lenny and Ubuntu 10.04 users, not install AMR packages
cd /opt/phpmotion/amrnb-
./configure && make && make install
cd /usr/local/src/amrwb-
./configure && make && make install

Install libtheora (for ogg video encoding)
cd /opt/phpmotion/libtheora-1.1beta3
./configure && make && make install

Install ffmpeg
cd /opt/phpmotion/ffmpeg/
svn update
Debian Lenny and Ubuntu 10.04 users please use the following configure command:
./configure --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared --enable-nonfree --enable-libtheora
Debian Etch and Ubuntu 8.04 users please use the following configure command:
./configure --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared --enable-libamr-nb --enable-libamr-wb --enable-nonfree --enable-libtheoraUbuntu 7.06 users please use the following configure command:
./configure --enable-libmp3lame --enable-libogg --enable-libvorbis --disable-mmx --enable-shared --enable-libamr-nb --enable-libtheora
Now run these commands:
make install
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/

Install ffmpeg-php
Debian Lenny and Ubuntu 10.04 users please use the following configure command:
aptitude install php5-ffmpegOthers Debian and Ubuntu users please use the following configure command:cd /opt/phpmotion/ffmpeg-php-0.6.0/
./configure && make && make install
You now check if there is ffmpeg-php module:
grep -R ffmpeg /etc/php5/*
If there is not, then you now need to add the new ffmpeg-php module to the php.ini file
nano /etc/php5/apache2/php.ini (add this line to the end of the file)

Restart & done
/etc/init.d/apache2 force-reload


PHP PEAR installation and configuration

PEAR is short for “PHP Extension and Application Repository” and is pronounced just like the fruit. The purpose of PEAR is to provide:

  • A structured library of open-source code for PHP users
  • A system for code distribution and package maintenance
  • A standard style for code written in PHP, specified here
  • The PHP Extension Community Library (PECL), see more below
  • A web site, mailing lists and download mirrors to support the PHP/PEAR community

There is not important what it is your OS: you could download to begin installation.
mv go-pear go-pear.php
php go-pear.php

or simply:
aptitude install php-pear (Debian / Ubuntu)
yum install php-pear (Fedora / Centos)

Verifying the include path
To use PEAR and PEAR compatible packages in your applications, you normally include them into your PHP scripts using require_once(). For this to work, PEAR’s php_dir must be a part of PHP’s include path.
1. First, check where PEAR installs .php files:
pear config-get php_dir
mine output is:
This directory will contain System.php.
2. Now it’s time to find which configuration file is used by your PHP installation. On command line, execute:
php --ini | grep Loaded
mine output is:
Loaded Configuration File: /etc/php.ini
To see which php.ini is used by PHP on your web server, create a file with only as the contents, and save it in your local web root as check_php.php. Open the file in your browser as http://localhost/check_php.php, to find the path to the php.ini file your web server is using.
3. include_path about php.ini must include php pear directory:
grep include_path /etc/php.ini | egrep "^[^;]"
mine output is:
include_path = ".:/usr/local/php/pear/"
If your include_path does not contain php pear directory, then you must add it modifying php.ini.
Modifying php.ini
To get PEAR working properly, you need to adjust PHP’s include_path. After you found php.ini, open it in an editor.
Search for the line include_path.
Now that you found it, you probably will see a semicolon ; at the beginning. This means the line is a comment. Add a new line below it.
In this line, write:
Depending on your operating system, add a : (Unix/Linux/FreeBSD/Mac OS X) or a ; (Windows) after the dot. Add PEAR’s php_dir after it. (The directory System.php is located in!)
The result should look like that:
; Unix

; Windows

Checking if PEAR works
Now that this is done, try including a file. Create a new check_pear.php file with the following contents:

require_once 'System.php';

System.php is shipped with every PEAR installation and thus should be on your computer, too. Open the file with the browser from your web server, and also try it on command line:
php check_pear.php
The only output should be
A message like:
Warning: require_once(System.php): failed to open stream:
No such file or directory in /path/to/check_pear.php on line 2

means that your include path is not correct. (So go and fix it!)
Installing packages
After getting PEAR working on your machine you most likely want to install some packages. This guide shows people new to the PEAR command line installer how to get started. The general command to install a PEAR package named “foo” is
pear install foo
Typing this and pressing return, the package will be downloaded and installed on your computer. It does not matter if you write the package name in lowercase, UPPERCASE or MixedCase – the installer will find the package by lowercasing the name.
When a package is already installed, you will get the following message:
pear install foo
Output is:
Ignoring installed package pear/foo
Nothing to install

This happens even if there is a newer version of the package! The correct command to upgrade to the lastest version is
pear upgrade foo
Output is:
upgrade ok: channel://
If the package already has the lastest version, you will get a message similar to the following:
Ignoring installed package pear/Foo
Nothing to upgrade

In the case you deleted some file and really really want to re-install the package, you have two choices:

  • Uninstall the package, and reinstall it afterwards
  • Force the installation

Forcing an command should only be done when you absolutely know what you are doing – you might in some circumstances break PEAR otherwise. Forcing something should always be the last option.
pear install -f foo
pear upgrade -f foo

Unstable alpha/beta packages
Now and then, you will get error messages like

Failed to download pear/foo within preferred state "stable",
latest release is version 0.1.2, stability "beta",
use "channel://" to install
Cannot initialize 'channel://', invalid or missing package file
Package "channel://" is not valid
install failed

Reason for this is that PEAR by default installs stable packages only. When a package is in state devel, alpha or beta it will refuse to install them. You can easily persuade it by adding either the version number or the stability you are willing to accept:
pear install Foo-beta
pear install Foo-alpha

You can also install a specific version, or upgrade to a specific version regardless of the state:
pear install Foo-1.2.3
pear upgrade Foo-1.2.3

Verifying the open basedir
It may happen that from the command line php pear works and via browser no. In the apache configuration file of domain may need to add:

php_admin_value open_basedir "/var/www/"
php_admin_value include_path ".:/usr/local/php/pear/"

Reference: about PEAR, getting started, installing packages, checking if PEAR works,

Installing msttcorefonts

If you need MS fonts installed in our Linux Operating System, in order to look at the documents in the same way they are looking at it.
on Debian / Ubuntu
sudo aptitude install msttcorefonts
on Fedora / Centos
Install the software needed
sudo yum install rpm-build cabextract
download cabextract package here
Download the specs to build the RPM
Build the RPM
rpmbuild -ba msttcorefonts-2.0-1.spec
Install the RPM
rpm -ivh msttcorefonts-2.0-1.noarch.rpm
Reload xfs
/sbin/service xfs reload
Now the msttcorefonts are installed and available. Look:
yum list msttcorefonts


Red5 installation


  • Download and Install Java. RED5 server depends on Java. CentOS 5.3 comes with OpenJDK 1.6 and install it using yum.
    yum -y install java-1.6.0-openjdk java-1.6.0-openjdk-devel
  • 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
  • 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.

    export ANT_HOME=/usr/local/ >> /etc/bashrc
    export JAVA_HOME=/usr/lib/jvm/ >> /etc/bashrc
    export PATH=$PATH:/usr/local/ant/ >> /etc/bashrc
    export CLASSPATH=.:$JAVA_HOME/lib/classes. >> /etc/bashrc
  • 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


    this 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.


  • Before beginning this make sure you are running these commands as root. Install Subversion:
    apt-get install subversion
  • Install tools to build your own Debian packages:

    apt-get install dpkg-dev
    apt-get install debhelper
    apt-get install dh-make
    apt-get install devscripts
    apt-get install fakeroot
  • Install Java (see this tutorial for more info):
    apt-get install java-package
  • Install Apache Ant 1.7:

    gzip -d xf apache-ant-1.7.0-bin.tar.gz
    tar -xf apache-ant-1.7.0-bin.tar
    cd apache-ant-1.7.0
    mv apache-ant-1.7.0 /usr/local/ant
    export ANT_HOME=/usr/local/ant
  • Once Java and Ant are all set up you simply download the latest development version of Red5 to your box.
    svn co red5-trunk

    That will create a folder in your current directory called red5-trunk.
  • Navigate to the red5-trunk directory and run
    That will build the project on your machine.
  • At this point you will need to create a red5 directory in the /usr/local/red5 directory.

    mkdir /usr/local/red5
  • Then you will want to copy the contents of the dist(distribution) folder to /usr/local/red5 like so
    cp -R red5-trunk/dist/* /usr/local/red5/
  • We need need to fix the permissions on the file:
    cd /usr/local/red5
    chmod 755
  • To run the server you have a few options using the file. Run the server by either running
    sh &
    ./ &

    This will start the Red5 service manually.
  • Verify the correct ports are being bound to:
    netstat -ant


sudo apt-get update
sudo apt-get install subversion
sudo apt-get install java-package
sudo apt-get install sun-java6-jdk
sudo apt-get install ant
mkdir -p ~/svn/red5
cd ~/svn/red5
svn checkout red5-read-only
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export ANT_HOME=/usr/share/ant/
cd ~/svn/red5/red5-read-only
sudo mkdir /usr/share/red5
cd ~/svn/red5/red5-read-only/dist
sudo cp -R * /usr/share/red5/
cd /usr/share/red5
sudo chmod 755
/usr/share/red5/ &

Digit on browser: http://localhost:5080 and good luck!

Init Script
Now we will create init script for red5 to start, stop and restart easily.
cp red5.txt /etc/init.d/red5
chmod 755 /etc/init.d/red5