Tag Archives: configure

How to create Master Master replication between two MySQL instances

MySQL Master Master replication is a double MySQL Master Slave replication between two MySQL instances: one MySQL instance (Mi1) is Master and the other MySQL instance (Mi2) is Slave and vice versa.

Minimal configuration file (/etc/my.cnf) of each mysql instance is similar:

[mysqld]
log-bin=/var/log/mysql/binlog.log
expire_logs_days=10
max_binlog_size=100M
datadir=/var/lib/mysql/data
socket=/var/lib/mysql/mysql.sock
innodb_flush_log_at_trx_commit=1
sync_binlog=1
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin

There is few difference.
Mi1
server-id = 1
Mi2
server-id = 2

If the servers are not alternative, and both writes into database, then it is important to be alert to the schema of the tables and it could be important add different auto increment configuration.
Mi1
auto_increment_increment = 2
auto_increment_offset = 1

Mi2
auto_increment_increment = 2
auto_increment_offset = 2

The initializing and starting replication is even to MySQL Master Slave replication between two MySQL instances.

It is important to assess the risks of a desynchronization between two MySQL instances. The errors can arise in the retrieval of information from the slave. If both instance writes into database, the reasons can be many:

  1. MySQL instances create a record considered as identical to the schema of a table (error 1062, duplicate entry)
  2. MySQL instances can not communicate due to lack of network for a time sufficient to change log file
  3. SQL syntax could be contain an error (error 1064, sql syntax)
  4. and the list is endless

It may need to add the slave skip errors configuration into /etc/my.cnf:
slave_skip_errors = 1062,1064

It may need to delete error on the fly with MySQL commands:
stop slave; set global SQL_SLAVE_SKIP_COUNTER=1; start slave;

Reference: mysql.com

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.

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

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

rcpthosts
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

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

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

cdb
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

Usage
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 pandle.net -dns false -mail_service true -notify false -ip 192.168.1.11
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.
/var/qmail/control
If the domain is pandle.net, add domain into files:
echo "pandle.net" >> /var/qmail/control/rejectnonexist
echo "pandle.net" >> /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 "pandle.net:100" >> /var/qmail/control/virtualdomains
/var/qmail/mailnames
mkdir /var/qmail/mailnames/pandle.net
echo "|bouncesaying This\ address\ no\ longer\ accepts\ mail." > /var/qmail/mailnames/pandle.net/.qmail-default
chown -R popuser.popuser /var/qmail/mailnames/pandle.net
chmod -R 700 /var/qmail/mailnames/pandle.net

/var/qmail/users
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
+100:popuser:110:31:/var/qmail/mailnames/pandle.net:::

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

create an user
If domain and mail are configured into Plesk and you must create new user,
/usr/local/psa/bin/mail --create biliards@pandle.net -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 biliards@pandle.net -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/pandle.net. If the user name is biliards, add on the top user line into /var/qmail/users/assign:
nano /var/qmail/users/assign
=100-biliards:popuser:110:31:/var/qmail/mailnames/pandle.net/biliards:::

Now run qmail-newu: it processes the assign file and generates a new cdb:
/var/qmail/bin/qmail-newu
Make the user home directory:
mkdir /var/qmail/mailnames/pandle.net/biliards
mkdir /var/qmail/mailnames/pandle.net/biliards/\@attachments
mkdir /var/qmail/mailnames/pandle.net/biliards/Maildir
mkdir /var/qmail/mailnames/pandle.net/biliards/Maildir/cur
mkdir /var/qmail/mailnames/pandle.net/biliards/Maildir/new
mkdir /var/qmail/mailnames/pandle.net/biliards/Maildir/tmp

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

cat /var/qmail/mailnames/pandle.net/biliards/Maildir/maildirsize
0S,0C
0 0

Modify the owner and permissions:
chown -R popuser.popuser /var/qmail/mailnames/pandle.net/biliards
chmod -R 700 /var/qmail/mailnames/pandle.net/biliards
chmod 600 /var/qmail/mailnames/pandle.net/biliards/.qmail
chmod 644 /var/qmail/mailnames/pandle.net/biliards/Maildir/maildirsize

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/pandle.net/biliards/.qmail
| true
| /usr/bin/deliverquota ./Maildir
&ittips@pandle.net

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 biliards@pandle.net -aliases add:bilardi,webmaster
else if you want create only alias about mail already configured,
nano /var/qmail/users/assign
=100-biliards:popuser:110:31:/var/qmail/mailnames/pandle.net/biliards:::

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

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

Reference: lifewithqmail.org, FAQ, vpopmail, pop account

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

Debian/Ubuntu
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
wget http://sourceforge.net/projects/lame/files/lame/3.99/lame-3.99.5.tar.gz
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
wget http://ftp.penguin.cz/pub/users/utx/amr/amrnb-10.0.0.0.tar.bz2
wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-10.0.0.0.tar.bz2
wget http://downloads.xiph.org/releases/theora/libtheora-1.1beta3.tar.gz
wget http://www8.mplayerhq.hu/MPlayer/releases/codecs/essential-amd64-20071007.tar.bz2
wget http://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
wget http://sourceforge.net/projects/ffmpeg-php/files/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk 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-10.0.0.0.tar.bz2 | tar xvf -
bzip2 -cd amrwb-10.0.0.0.tar.bz2 | 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-10.0.0.0
./configure && make && make install
cd /usr/local/src/amrwb-10.0.0.0
./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
make install
ln -s /usr/local/lib/libavdevice.so.52 /usr/lib/libavdevice.so.52
ln -s /usr/local/lib/libavformat.so.52 /usr/lib/libavformat.so.52
ln -s /usr/local/lib/libavcodec.so.52 /usr/lib/libavcodec.so.52
ln -s /usr/local/lib/libavutil.so.49 /usr/lib/libavutil.so.49
ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib/libmp3lame.so.0
ln -s /usr/local/lib/libavformat.so.51 /usr/lib/libavformat.so.51
ln -s /usr/local/lib/libamrnb.so.3 /usr/lib/libamrnb.so.3
ln -s /usr/local/lib/libamrwb.so.3 /usr/lib/libamrwb.so.3

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/
phpize
./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
extension=ffmpeg.so (add this line to the end of the file)

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

Reference: linux.justinhartman.com

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
ProductApplication::your_function($html_content)
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: docs.joomla.org, Load module into article, Modules Anywhere

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

Referece: fullo.net

How to create replication between two MySQL instances

It is important create a mysql user into each instance that it could exec only replication actions, in mysql shell:
create user replica@localhost;
grant replication slave on *.* to replica@localhost identified by 'replicapassword';

Minimal configuration file (/etc/my.cnf) of each mysql instance is:
master
[mysqld]
server-id=1
log-bin=/var/log/mysql/binlog.log
expire_logs_days=10
max_binlog_size=100M
datadir=/var/lib/mysql/data
socket=/var/lib/mysql/mysql.sock
innodb_flush_log_at_trx_commit=1
sync_binlog=1

slave
[mysqld]
server-id=2
master-host=ip.server.master
master-port=3306
master-user=replica
master-password=replicapassword
log-bin=/var/log/mysql/binlog.log
expire_logs_days=10
max_binlog_size=100M
datadir=/var/lib/mysql/data
socket=/var/lib/mysql/mysql.sock
innodb_flush_log_at_trx_commit=1
sync_binlog=1
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin

Last step is initializing and starting replication. In mysql shell:
master
reset master;
slave
change master to master_host='ip.server.master',
master_user='replica',
master_password='replicapassword',
master_port=3306;

If you want resetting replication:
master
reset master;
slave
stop slave;
reset slave;
start slave;

If you want show which it is binary file and position:
show master status;
show slave status;

Reference: mysql.com

How to install multiple MySQL instances on the same machine

There are various methods to run multiple instances of mysql (on different ports) on the same machine. We can either compile the mysql binary with different defaults and paths, use mysqld_multi or the MySQL Sandbox project. Still the simplest solution I’ve used in the past for such situations is to use the same binary and use a separate configuration file (with separate port, pid, socket and data directory). This post will explain this method.

Create separate data and log directories
We need to create new directories for our datadir and log folder (if used). Also we need to assign proper permissions on those folders:
mkdir /var/lib/mysql2
chown -R mysql:mysql /var/lib/mysql2/
mkdir /var/log/mysql2
chown -R mysql:mysql /var/log/mysql2

Create a new mysql configuration file
Next we need a separate configuration file. We can start by copying the existing one and changing the needed values. This example was taken on a debian machine that holds the mysql configurations under /etc/mysql/my.cnf. We just copy this folder and modify it from there:
cp -R /etc/mysql/ /etc/mysql2
if you use a redhat variant package then your configuration file is under /etc/my.cnf by default and you can just copy it directly:
cp /etc/my.cnf /etc/my2.cnf
(or change the path appropriately for your configuration file is in a different place).
Next, we need to edit our new configuration file and at least update the mysql port (default to 3306), the pid and socket to be different than the default ones, and also point the data and log folders to the ones created before.
cd /etc/mysql2/
sed -i 's/3306/3307/g' my.cnf
sed -i 's/mysqld.sock/mysqld2.sock/g' my.cnf
sed -i 's/mysqld.pid/mysqld2.pid/g' my.cnf
sed -i 's/var\/lib\/mysql/var\/lib\/mysql2/g' my.cnf
sed -i 's/var\/log\/mysql/var\/log\/mysql2/g' my.cnf

Initializing and starting
Finally we need to initialize the default dbs:
mysql_install_db --user=mysql --datadir=/var/lib/mysql2/
Alternatively we can copy the existing /var/lib/mysql if this is needed (shut down mysql prior to do this).
Finally we can start our new mysql instance with:
mysqld_safe --defaults-file=/etc/mysql2/my.cnf &
We can connect to our new instance using:
mysql -S /var/run/mysqld/mysqld2.sock
or
mysql -h 127.0.0.1 -P 3307
and if we no longer need it, stop it with:
mysqladmin -S /var/run/mysqld/mysqld2.sock shutdown

Other solution
Create a unique mysql configuration file
You could create unique mysql configuration file /etc/my.cnf. You could label each instance with a number and define same parameters into unique file.
If you have got two instances, 1 and 2, your minimal mysql congifuration file could be this:

[mysqld1]
set-variable=local-infile=0
datadir=/var/lib/mysql1
socket=/var/lib/mysql1/mysql.sock
user=mysql
old_passwords=1
bind-address=127.0.0.1
[mysqld_safe1]
log-error=/var/log/mysql1/mysqld.log
pid-file=/var/run/mysqld/mysqld1.pid

[mysqld2]
set-variable=local-infile=0
datadir=/var/lib/mysql2
socket=/var/lib/mysql2/mysql.sock
user=mysql
old_passwords=1
bind-address=127.0.0.1
[mysqld_safe2]
log-error=/var/log/mysql2/mysqld.log
pid-file=/var/run/mysqld/mysqld2.pid

Each directory had owner mysql user:
chown -R mysql:mysql /path/directory

Initializing and starting
As above. Or you could use mysqld_multi command line to start mysql instances together:
mysqld_multi --verbose --log=/var/log/mysqld.log start 1,2

About stop instances, you could use mysqladmin command line as above. If you
need a particular mysql user about shutdown particular mysql instance, you could use:

mysqladmin --defaults-file=/etc/myuser.cnf shutdown

where /etc/myuser.cnf is:

[client]
user=myuser
password=myuserpassword
socket=/var/lib/mysql1/mysql.sock

and you must add in mysql shell:
GRANT SHUTDOWN ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'myuserpassword'

Check port of MySQL instances
If you have worked well, then you have got two MySQL instances that they listen on different ports:
netstat -ntl
My output is:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:3307 0.0.0.0:* LISTEN

Reference: ducea.com

How to configure an IP Tunnel

An IP tunnel is an Internet Protocol (IP) network communications channel between two networks. It is used to transport another network protocol by encapsulation of its packets.

IP tunnels are often used for connecting two disjoint IP networks that don’t have a native routing path to each other, via an underlying routable protocol across an intermediate transport network. In conjunction with the IPsec protocol they may be used to create a virtual private network between two or more private networks across a public network such as the Internet. Another prominent use is to connect islands of IPv6 installations across the IPv4 Internet.

You could try by two ways.
On-the-fly way
In the first (192.168.0.18) endpoint:
ip tunnel add mytun mode ipip local 192.168.0.18 remote 192.168.0.118
ip addr add 10.168.0.18/24 dev mytun
ip link mytun up

In the second (192.168.0.118) endpoint:
ip tunnel add mytun mode ipip local 192.168.0.118 remote 192.168.0.18
ip addr add 10.168.0.118/24 dev mytun
ip link mytun up

Permanent way
Host 192.168.0.18:
DEVICE=mytun
TYPE=IPIP
MY_OUTER_IPADDR=192.168.0.18
PEER_OUTER_IPADDR=192.168.0.118
MY_INNER_IPADDR=10.168.0.18/24
PEER_INNER_IPADDR=10.168.0.118/24
ONBOOT=yes

Host 192.168.0.118:
DEVICE=mytun
TYPE=IPIP
MY_OUTER_IPADDR=192.168.0.118
PEER_OUTER_IPADDR=192.168.0.18
MY_INNER_IPADDR=10.168.0.118/24
PEER_INNER_IPADDR=10.168.0.18/24
ONBOOT=yes

To starting tunnel is simple. On host 192.168.0.18 and on host 192.168.0.118:
ifup mytun

If you want check up tunnel:
ip addr ls

Reference: wikipedia.org, daverdave.com

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

Installation
There is not important what it is your OS: you could download http://pear.php.net/go-pear to begin installation.
wget http://pear.php.net/go-pear
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:
/usr/local/php/pear/
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:
include_path="."
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
include_path=".:/usr/local/php/pear/"

or
; Windows
include_path=".;C:\php\pear\"

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';
var_dump(class_exists('System'));
?>

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
bool(true)
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://pear.php.net/Foo-1.2.3
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://pear.php.net/foo-0.1.2" to install
Cannot initialize 'channel://pear.php.net/foo', invalid or missing package file
Package "channel://pear.php.net/foo" 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/domain.my/httpdocs:/usr/local/php/pear/:/tmp"
php_admin_value include_path ".:/usr/local/php/pear/"

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

open_basedir restriction in effect

PHP open_basedir protection tweak is a Safe Mode security measure that prevents users from opening files or scripts located outside of their home directory with PHP, unless the folder has specifically excluded. PHP open_basedir setting if enabled, will ensure that all file operations to be limited to files under certain directory, and thus prevent php scripts for a particular user from accessing files in unauthorized user’s account. When a script tries to open a file with, for example, fopen() or gzopen(), the location of the file is checked. When the file is outside the specified or permissible directory-tree, PHP will refuse to open it and the following errors may occur:
Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File ...
The above error message appears on a Apache httpd web server error log (error_log). However, the problem may happen to all system or websites that use PHP as scripting language.
The solution or workaround to open_basedir restriction problem is that disable the PHP open_basedir protection altogether, or to exclude the protection for certain privileged user accounts, or to allow access to the additional directory for PHP scripts.

If you’re using cPanel WebHost Manager (WHM), you can easily disable PHP open_basedir protection or exclude certain users from the protection with WHM. Simply go to “Tweak Security” under the “Security” section, then select “Configure” link for “Php open_basedir Tweak”. Inside it, you can enable or disable php open_basedir Protection, or exclude and include hosts from the protection.

If you’re using Plesk hosting control panel, you may need to manually edit Apache configuration file of vhost.conf and vhost_ssl.conf, and add in or edit the following php_admin_value open_basedir lines to the following:

php_admin_value open_basedir none


php_admin_value open_basedir /full/path/to/dir:/full/path/to/directory/httpdocs:/tmp

Note: For SSL hosts in the vhost_ssl.conf file, the Directory path will end with “httpsdocs” instead of “httpdocs”.

The paths (above is example only and to be replaced with real path) that behind open_basedir are the directories that specifically allowed for the PHP scripts in the vhost domain account to access, so you can add in more directories that files are been stored and needed to be opened by PHP, each seperated by color “:”. But be careful as it might expose your system to security fraud.

Once done, restart Apache httpd web server (apache2ctl restart or httpd restart). If you have to manually edit the Apache configuration file to disable PHP open_basedir protection, simply open up the httpd.conf file, and search for the lines that starts with the following characters:
php_admin_value open_basedir …..
Replace the whole line under the virtual host for the domain user account that you want to disable protection with the following line to disable it:
php_admin_value open_basedir none
You can also opt to allow your PHP scripts to access additional directory instead without disabling the protection. Additional directory can be added to the line, separated with color “:”. For example, to add /new_directory to the allow list:
php_admin_value open_basedir “/home/user_account/:/usr/lib/php:/usr/local/lib/php:/tmp”
php_admin_value open_basedir “/home/user_account/:/usr/lib/php:/usr/local/lib/php:/tmp:/new_directory”

Restart the Apache after finished editing. Note that the directory allowed list restriction above is actually a prefix, not a directory name. This means that “open_basedir = /dir/incl” also allows access to “/dir/include” and “/dir/incls” if they exist. When you want to restrict access to only the specified directory, end with a slash. For example: “open_basedir = /dir/incl/”.

Reference: mydigitallife.info