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

PHPmotion installation

PHPmotion is a free video sharing software that also has support for other types of media such as audio/mp3 sharing. The Content Managent System or (media cms application) will allow you to create and run your very own Video Sharing website, Music Sharing Site, Picture Sharing Site.

Servers – Linux/Unix server
- PHP 4.3 and above (including support of CLI)
- MySQL database server
- LAME MP3 Encoder
- Libogg + Libvorbis
- Mencoder and also Mplayer
- FFMpeg-PHP
- GD Library 2 or higher
- Be able to run background processes

PHP Settings
- open_basedir = (no value)
- upload_max_filesize = 100M
- post_max_size = 100M
- max_execution_time = 1500
- session.gc_maxlifetime = 14000
- safe_mode = off
- Thread saftery = disabled
- enable_dl = On

Libraries installation
Follow the steps on this page.

phpSHIELD loader
With this error:
PHP script /var/www/*/classes/config.php is protected by phpSHIELD and requires the phpSHIELD loader phpshield.5.3.lin. The phpSHIELD loader has not been installed, or is not installed correctly. Please visit the phpSHIELD php encoder site to download required loader.
Follow the steps on this page.

With this error:
PHP Fatal error: SourceGuardian Loader - This protected script does not support version 5.3.2-1ubu of PHP. Please contact the script author about this problem. Error code [07] in /var/www/*/classes/config.php on line 2
Assuming you have old revision installed, you need to update / upload 4 files from the php5.3 release (or download here)

Other error infamous
White screen

  • The following files MUST be uploaded in Binary mode
    /phpshiled/all files in this folder
  • Set error_reporting to E_ALL or into apache configuration
    LogLevel debug
  • Set Thread Safety to disable (follow the steps on this page)
  • Your revision is too old that you must install last revision:
    • Backup your database and /upload and your /themes/*/templates directories
    • Install new release
    • Use old database during new intallation
    • Copy old /upload and your /themes/*/templates directories

Reference: PHPmotion System Requirements, PHPmotion Forum

qmail and simple configuration

qmail is a modern SMTP server and the second most popular MTA on the Internet. A number of large Internet sites are using qmail, Plesk is one. If you are on Plesk control panel, and need to change email account password then changing password from Plesk is a lengthy process.

qmail is installed into /var/qmail or similar. There are more directories, but four are important: bin, control, mailnames and users. bin directory contains all binary programs about manage qmail service. mailnames directory contains all mail divided by domain and user.

If you type this command:
man qmail-controlYou obtain info about files into /var/qmail/control directory.
We analize rejectnonexist, rcpthosts and virtualdomains.

File is the list of domains, one per line. qmail-smtpd will reject any envelope recipient address with a domain not listed in rejectnoexist.

File is the list of domains, one per line. Allowed RCPT domains. If rcpthosts is supplied, qmail-smtpd will reject any envelope recipient address with a domain not listed in rcpthosts. Any details with command line:
man qmail-smptdvirtualdomains
List of virtual users or domains, one per line. A virtual user has the form user@domain:prepend, without any extra spaces. When qmail-send sees the recipient address user@domain, it converts it to prepend-user@domain and treats it as local. Any details with command line:
man qmail-send

If you type this command:
man qmail-usersYou obtain info about files into /var/qmail/users directory: assign and cdb.

List of users addresses. File is a series of assignments, one per line. It ends with a line containing a single dot. Lines must not contain NUL.

It is a constant database (CDB). CDB is a binary format that can be accessed quickly by qmail-lspawn, even when there are thousands of assignments.

.qmail files
.qmail files contain a list of delivery instructions, one instruction per line. Delivery of a user’s mail is usually controlled by one or more “.qmail” (pronounced dot kyoo mail) files. The pseudo-user on all qmail systems whose home directory is usually /var/qmail/alias. About each user, home directory is usually /var/qmail/mailnames/domain/user/.qmail. Any details with command line:
man dot-qmail

You could use any programs to manage qmail service. Most popular is vpopmail. vpopmail is a set of API that manages virtual user accounts on a qmail system, and handles delivery for these virtual users. The command-line utilities, and Qmailadmin all use the vpopmail API, provided by the vpopmail library to manage the system. vpopmail does not work with Plesk. So that, you could run the Plesk or qmail commands. Options about Plesk commands line may differ from version to version: we are using v10.3. Any details, you could run each command with –help.

create a domain
If you want configure only domain mail into Plesk,
/usr/local/psa/bin/domain --create -dns false -mail_service true -notify false -ip
else if you have Plesk panel, you could add new domain out to Plesk and you could add mail into qmail service.
This configuration is available only user with forward because it is disable change password without Plesk or vpopmail.
You must modify five files (assign, cdb, rejectnonexist, rcpthosts and virtualdomains) and create new directory into /var/qmail/mailnames.
If the domain is, add domain into files:
echo "" >> /var/qmail/control/rejectnonexist
echo "" >> /var/qmail/control/rcpthosts
To add domain into virtualdomains, and you are using prefix, you must use new prefix. Plesk uses progressive number like id domain. Show last prefix:
tail -n 1 /var/qmail/control/virtualdomains | awk -F ':' '{print $2}'
If last prefix number is 35, you could use 100 so that you could use again Plesk:
echo "" >> /var/qmail/control/virtualdomains
mkdir /var/qmail/mailnames/
echo "|bouncesaying This\ address\ no\ longer\ accepts\ mail." > /var/qmail/mailnames/
chown -R popuser.popuser /var/qmail/mailnames/
chmod -R 700 /var/qmail/mailnames/

Show values about qmail user: popuser
grep popuser /etc/passwd
Output could be:
popuser:x:110:31:POP3 service user:/var/qmail/popuser:/bin/false
Add on the top domain line into /var/qmail/users/assign:
nano /var/qmail/users/assign

Now run qmail-newu: it processes the assign file and generates a new cdb:

create an user
If domain and mail are configured into Plesk and you must create new user,
/usr/local/psa/bin/mail --create -passwd mypassword -mailbox true
else if domain and mail are configured into Plesk and you must update only password,
/usr/local/psa/bin/mail -u -passwd mypassword
else if domain and mail are not configured into Plesk, commands are more than one. You must modify two files (assign and cdb) and create new directory into /var/qmail/mailnames/ If the user name is biliards, add on the top user line into /var/qmail/users/assign:
nano /var/qmail/users/assign

Now run qmail-newu: it processes the assign file and generates a new cdb:
Make the user home directory:
mkdir /var/qmail/mailnames/
mkdir /var/qmail/mailnames/\@attachments
mkdir /var/qmail/mailnames/
mkdir /var/qmail/mailnames/
mkdir /var/qmail/mailnames/
mkdir /var/qmail/mailnames/

Make two files:
cat /var/qmail/mailnames/
| true
| /usr/bin/deliverquota ./Maildir

cat /var/qmail/mailnames/
0 0

Modify the owner and permissions:
chown -R popuser.popuser /var/qmail/mailnames/
chmod -R 700 /var/qmail/mailnames/
chmod 600 /var/qmail/mailnames/
chmod 644 /var/qmail/mailnames/

User password is configurable only Plesk or vpopmail programs. So that, if you have other domains configured into Plesk, you must use Plesk commands or you add line to user .qmail file to forward mailing:
cat /var/qmail/mailnames/
| true
| /usr/bin/deliverquota ./Maildir

create an alias
If domain and mail are configured into Plesk and you must create new user alias,
for example, user biliards and alias bilardi and webmaster,
/usr/local/psa/bin/mail -u -aliases add:bilardi,webmaster
else if you want create only alias about mail already configured,
nano /var/qmail/users/assign

Now run qmail-newu: it processes the assign file and generates a new cdb:

To test mail that you created, follow the steps on this page.

Reference:, FAQ, vpopmail, pop account

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


Joomla and its customization

Joomla is fantastic because you could add or modify view or calculate intervening into particular events. It only needs to add or modify correct files. If you would like:

  1. modify template
    • creating your template in /templates/your-template-name and
    • overwriting css or html about modules or components
  2. modify modules
    • overwriting html from templates/your-template-name/html
    • from administration, copying module and add it with different parameters
    • copying module and install it as new module
    • changing module by your plugin
  3. add new plugins
  4. add new components

Zoo is a big component. It is so important that it has also more ways to add or modify view or calculate.
If you would like:

  1. modify template
    • from zoo administration interface
    • adding modules into zoo templates (full, related, item, teaser, ..)
  2. modify zoo component
    • from /media/zoo/applications with applications.php files
    • and all final files about full, related, item, teaser, .., templates

Joomla – Plugin load module into article

Load Module plugin
You will usually want to associate modules with articles in some way. The modules are allocated to module positions and the module positions appear somewhere on the Web page as determined by the template. However, it is sometimes useful to have a module actually embedded within the article.

To insert a module inside an article, use the {loadposition xx} command, as follows:

1. Create a module and set its position to any value that doesn’t conflict with an existing template position. You can type in the position value instead of selecting it from the drop-down list. For example, use the position myposition.
2. Assign the module to the Menu Items that contain the articles that you want the module to show in. You can also just assign the module to all Menu Items.
3. Edit the articles where you want this module to appear and insert the text
{loadposition myposition}
in the article at the place where you want the module.

Note that this only works when the Content – Load Module plugin is enabled. If this plugin is disabled, the text {loadposition myposition} shows unchanged in the article.

Load module into article
This plugin loads any module into an article.
Syntax in editor:
{module [27]}
where 27 is the modules id.

Modules Anywhere
With Modules Anywhere you can include a single module or complete module positions anywhere in your site, including inside 3rd party components and even inside other modules.

Why use Modules Anywhere, and not the {loadposition} plugin?
* It works anywhere, not only in articles. It even works in modules!
* You can load a single module, not only complete module positions.
* You can control the html display style from within the tag, not only one global setting.
* You have some security setting, so you can disable this feature for lower user types.
* It comes with a very easy to use editor button.

You can set Modules Anywhere to also handle the {loadposition} tags. In that case, you can safely disable the {loadposition} plugin all together.

Modules Anywhere does not show unpublished Modules by default. If you do want it to, you can change that behavior through the plugin parameters.

Load module into zoo
To load module into zoo content, you could use Modules Anywhere or modify template about zoo.
If you want load module into product catalog, then you could implement ProductApplication class as JPATH_BASE.DS.’plugins’.DS.’content’.DS.’loadmodule.php’ module (with function that return text modified) and use it into template file JPATH_BASE.DS.’media/zoo/applications/product/templates/default/renderer/item/full.php’ with
where your_function is public function that you implemented (as plgContentLoadModule about loadmodule.php) and $html_content is variable that contain your {loadposition xx}.

Reference:, Load module into article, Modules Anywhere


DNS lookup utility.
dig [@server] [-b address] [-c class] [-f filename] [-k filename] [-p port#] [-t type] [-x addr] [-y name:key] [-4] [-6] [name] [type] [class] [queryopt...]
dig [-h]
dig [global-queryopt...] [query...]


Set TimeZone on Centos

CentOS update breaks another thing – the logwatch perl timezone manipulation. The exact error message is:
ERROR: Date::Manip unable to determine TimeZone.

Execute the following command in a shell prompt:
perldoc Date::Manip
The section titled TIMEZONES describes valid TimeZones and where they can be defined.

You could fix it modify /etc/localtime. You could use tzconfig command line and follow its questions or:
cp /usr/share/zoneinfo/Europe/Rome /etc/localtime
If your localtime is different, you could choose your zoneinfo in /usr/share/zoneinfo/.



rdate – get the time via the network
rdate [-p] [-s] [-u] [-l] [-t sec] [host...]
rdate -s

If you want syncronize date, then you could add this line into crontab:
* * * * 0 rdate -s