Category Archives: linux distro

How to change default editor

Each works well with your favorite text editor. It is important that there is a default editor known. In debian and in other linux distro, default editor is vi.

You could change default editor:

  1. during distro installation
  2. custom each user into .bashrc or .profile file with line:
    export EDITOR=/usr/bin/emacs
  3. custom locally in a shell session and/or particular program:
    env EDITOR=nano crontab -e

yum segmentation fault in centos

After an upgrading with yum program, yum will end with segmentation fault.

Last link about libz is the cause:
-rwxr-xr-x 1 root root  75028  9 gen  2007
-rwxr-xr-x 1 root bin   96572  8 nov  2010
-rw-r--r-- 1 root bin  101462  8 nov  2010 libz.a
lrwxrwxrwx 1 root root     13  8 apr  2011 ->
lrwxrwxrwx 1 root root     13  8 apr  2011 -> need a different link:
lrwxrwxrwx 1 root root     13  8 apr  2011 ->

Reference: yum fails with segfault after source zlib upgrade

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


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


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,


mytop – display MySQL server performance info like ‘top’

mytop [options]

mytop -u mysqluser -p mysqlpassword -d database

Mytop has started to break on RHEL or CentOS. It appears that some of the perl modules have change.d
There error is:
Error in option spec: "long|!"

The fix for this is to edit the mytop script and comment out the line containing long|!
nano /usr/bin/mytop
Run a search for long|! and comment out the following line:
"long|!" => \$config{long_nums},
Start mytop and you should be fine!


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


Mirroring files on remote servers

Linux File Transfer Methods
When we need to download or copy a file from a remote machine to our local one or vice-versa, most of us use a plain, simple to use, FTP client. There are actually a wealth of tools available for transferring files, and some of them perform automation functions that can easily assist your business in building site mirrors, synchronizing directory contents, and more.

These lower security tools include lftp, rsync, and wget. Many of these programs can handle more than just FTP connections, and some even have their own shell-like syntax for sophisticated use.

The high security tools include scp and sftp are specially built for using in a secure manner. These are the tools you’ll want to develop a habit of using when transferring information you need to keep private. You’ll need to have ssh configured between the two machines in question before you can use either of these secure tools.

If scp and sftp are high security tools because they use ssh method.. why could we be not power lftp or rsync by ssh?

Suppose you want or need to transfer files using the venerable FTP protocol. If you haven’t already discovered lftp, then it’s time to investigate. When you connect to a remote machine using lftp it’s rather like having a shell session open on that machine: you can navigate using tab completion and the usual shell tools relating to file and directory operations are there, as well as extra goodies like mirror and a decent help system.
lftp -c 'open -e "set ftp:list-options -a; mirror -a --parallel=10 -v fromdir/ ./todir" -u user,pass host'
lftp -c 'open -e "set ftp:passive-mode false; set ftp:list-options -a; mirror -a --parallel=1 --reverse -v fromdir/ ./todir" -u user,pass host'
lftp -u user,pass -e "mirror --delete --only-newer --verbose fromdir/ ./todir" host
lftp -u user,pass -e "mirror --reverse --delete --only-newer --verbose fromdir/ ./todir" host

rsync is another great command-line file-system shifter. It’s designed to keep two directory structures in sync, and to do so efficiently by just transmitting deltas between the two. Typically the source and destination directories reside on separate machines, and rsync is often invoked automatically as a scheduled job. Rsync forms the backbone of many a backup system.
rsync -avrzogtp user@hostname:/fromdir/ ./todir

to be continued..