Fedora iTOps Tube

Tuesday, February 14, 2012

Instruction Guide to Install PHP5 from Source on Linux


 

All Linux distributions comes with PHP. However, it is recommended to download latest PHP source code, compile and install on Linux. This will make it easier to upgrade PHP on an ongoing basis immediately after a new patch or release is available for download from PHP. This article explains how to install PHP5 from source on Linux.

1. Prerequisites

Apache web server should already be installed. Refer to my previous post on How to install Apache 2 on Linux. If you are planning to use PHP with MySQL, you should have My SQL already installed. I wrote about How to install MySQL on Linux.

2. Download PHP

Download the latest source code from PHP Download page. Current stable release is 5.2.6. Move the source to /usr/local/src and extract is as shown below.

# bzip2 -d php-5.2.6.tar.bz2
# tar xvf php-5.2.6.tar

3. Install PHP

View all configuration options available for PHP using ./configure –-help (two hyphen in front of help). The most commonly used option is –-prefix={install-dir-name} to install PHP on a user defined directory.

# cd php-5.2.6
# ./configure --help

In the following example, PHP will be compiled and installed under the default location /usr/local/lib with Apache configuration and MySQL support.

# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
# make
# make install
# cp php.ini-dist /usr/local/lib/php.ini

4. Configure httpd.conf for PHP

Modify the /usr/local/apache2/conf/httpd.conf to add the following:

<FilesMatch "\.ph(p[2-6]?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>

Make sure the httpd.conf has the following line that will get automatically inserted during the PHP installation process.

 

LoadModule php5_module modules/libphp5.so

Restart the apache as shown below:

# /usr/local/bin/apache2/apachectl restart

5. Verify PHP Installation

Create a test.php under /usr/local/apache2/htdocs with the following content

# vi test.php
<?php phpinfo(); ?>

Go to http://local-host/test.php , which will show a detailed information about all the PHP configuration options and PHP modules installed on the system.

6. Trouble shooting during installation

Error 1: configure: error: xml2-config not found:
While performing the ./configure during PHP installation, you may get the following error:

# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
Configuring extensions
checking whether to enable LIBXML support... yes
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.

Install thelibxml2-devel and zlib-devel as shown below to the fix this issue.

# rpm -ivh /home/downloads/linux-iso/libxml2-devel-2.6.26-2.1.2.0.1.i386.rpm /home/downloads/linux-iso/zlib-devel-1.2.3-3.i386.rpm
Preparing...                ########################################### [100%]
1:zlib-devel             ########################################### [ 50%]
2:libxml2-devel          ########################################### [100%]

Error 2: configure: error: Cannot find MySQL header files.
While performing the ./configure during PHP installation, you may get the following error:

# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
checking for MySQL UNIX socket location... /var/lib/mysql/mysql.sock
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!

Install the MySQL-devel-community package as shown below to fix this issue.

# rpm -ivh /home/downloads/MySQL-devel-community-5.1.25-0.rhel5.i386.rpm
Preparing...                ########################################### [100%]
1:MySQL-devel-community  ########################################### [100%]

 

SSH Key based authentication setup from openSSH to SSH2


 

The previous articles (openSSH to openSSH setup, SSH2 to SSH2 setup) explains about how to setup key based authentication on the same version of ssh to perform ssh and scp without entering password. This article explains how to setup SSH key based authentication between different version of SSH (from openSSH to SSH2) to perform ssh and scp without entering password.

1. Verify the local-host and remote-host SSH version.

In this example, local-host is running on openSSH and remote-host is running on SSH2.

[local-host]$ ssh -V
OpenSSH_5.0p1, OpenSSL 0.9.8g 19 Oct 2007
 
[remote-host]$ ssh -V
ssh: SSH Secure Shell 3.2.9.1 (non-commercial version) on i686-pc-linux-gnu
[remote-host]$ ls -l /usr/local/bin/ssh
lrwxrwxrwx  1 root root 4 Mar 10 22:04 /usr/local/bin/ssh -> ssh2

2. Generate key-pair on the local-host using ssh-keygen

[local-host]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):<Hit enter>
Enter passphrase (empty for no passphrase): <Enter your passphrase here>
Enter same passphrase again:<Enter your passphrase again>
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
3b:2a:d2:ac:8c:71:81:7e:b7:31:21:11:b8:e8:31:ad jsmith@local-host

The public key and private key are typically stored in .ssh folder under your home directory. In this example, it is under /home/jsmith/.sshd. You should not share the private key with anybody.

By default the ssh-keygen on openSSH generates RSA key pair. You can also generate DSA key pair using: ssh-keygen -t dsa command.

3.  Convert openSSH public key to SSH2 public key.

On local-host that is running openSSH, convert the openSSH public key to SSH2 public key using ssh-keygen as shown below.

[local-host]$ ssh-keygen -e -f ~/.ssh/id_rsa.pub > ~/.ssh/id_rsa_ssh2.pub

4. Install the public-key on the remote-host that is running SSH2.

Create a new public key file on remote-host and copy paste the converted SSH2 key from the local-host.

[remote-host]$ vi ~/.ssh2/local-host_ssh2_key.pub 
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "2048-bit RSA, converted from OpenSSH by jsmith@local-host"
DDDDB3NzaC1yc2EAAAABDmbrdomPh9rWfjZ1+7Q369zsBEa7wS1RxzWRQ0Bmr9FSplI
3ADBEBC/6cbdf/v0r6Cp5y5kusP07AOzo2F7MBDSZBtS/MbYJiIxvocoaxG2bQyz3yYjU
YcpzGMD182bnA8kRxmGg+R5pVXM34lx3iSSgd8r3RzZKnDpEvEInnI7pQvUBoEbYCXPUeZ
LQvQAkz6+Pb6SsNp-dop/qgv9qyfbyMz1iKUZGadG146GtanL5QtRwyAeD187gMzzrGzMFP
LWjdzWpGILdZ5gq7wwRpbcXFUskVrS2ZjDe676XlTN1k5QSZmSYUuttDdrjB5SFiMpsre8
a7cQuMS178i9eDBEC==
---- END SSH2 PUBLIC KEY ----

Add the above public key file name to the authorization file on the remote-host as shown below.

[remote-host]$ vi ~/.ssh2/authorization
Key local-host_ssh2_key.pub

5. Verify the Login from the local-host to remote-host using the SSH2 key authentication.

[local-host]$ ssh -l jsmith remote-host <You are on local-host here>

The authenticity of host 'local-host' can't be established.

DSA key fingerprint is a5:f6:2e:e6:a9:b2:7b:0e:e7:ae:cb:6c:7b:f5:6d:06.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'local-host' (DSA) to the list of known hosts.

Enter passphrase for key '/home/jsmith/.ssh/id_rsa': <Enter your passphrase here>

Last login: Sat Jun 21 2008 23:13:00 -0700 from 192.168.1.102

No mail.

[remote-host]$ <You are on remote-host here>

There are two ways to perform ssh and scp without entering the password:

1.    No passphrase. While creating key pair, leave the passphrase empty. Use this option for the automated batch processing. for e.g. if you are running a cron job to copy files between machines this is suitable option. You can skip the next step steps for this method.

2.    Use passphrase and SSH Agent. If you are using ssh and scp interactively from the command-line and you don’t want to use the password everytime you perform ssh or scp, I don’t recommend the previous option (no passphrase), as you’ve eliminated one level of security in the ssh key based authentication. Instead, use the passphrase while creating the key pair and use SSH Agent to perform ssh and scp without having to enter the password everytime as explained in the steps below.

6. Start the SSH Agent on local-host

The SSH Agent will be running in the background to hold the private keys and perform ssh and scp without having to enter the passphrase several times.

[local-host]$ ssh-agent $SHELL

7. Load the private key to the SSH agent on the local-host.

[local-host]$ ssh-add

Enter passphrase for /home/jsmith/.ssh/id_rsa:<Enter your passphrase here>

Identity added: /home/jsmith/.ssh/id_rsa (/home/jsmith/.ssh/id_rsa)

8. Perform SSH or SCP to remote-home from local-host without entering the password.

[local-host]$<You are on local-host here>

 

[local-host]$ ssh -l jsmith remote-host

Last login: Sat Jun 07 2008 23:03:04 -0700 from 192.168.1.102

No mail.

<ssh did not ask for passphrase this time>

[remote-host]$ <You are on remote-host here>

 

Install Apache 2 from Source on Linux


All Linux distributions comes with Apache. However, it is recommended to download latest Apache source code, compile and install on Linux. This will make it easier to upgrade Apache on a ongoing basis immediately after a new patch or release is available for download from Apache. This article explains how to install Apache2 from source on Linux.

1. Download Apache

Download the latest version from Apache HTTP Server Project . Current stable release of Apache is 2.2.9. Move the source to /usr/local/src and extract it as shown below.

# cd /usr/local/src
# gzip -d httpd-2.2.9.tar.gz
# tar xvf httpd-2.2.9.tar

2. Install Apache

View all configuration options available for Apache using ./configure –help (two hyphen in front of help). The most commonly used option is –prefix={install-dir-name} to install Apache on a user defined directory.

# cd httpd-2.2.9
# ./configure --help

In the following example, Apache will be compiled and installed to the default location /usr/local/apache2 with the DSO capability. Using the –enable-so option, you can load modules to Apache at runtime via the Dynamic Shared Object (DSO) mechanism, rather than requiring a recompilation.

# ./configure --enable-so
# make
# make install

Note: During the ./configure, you may get the following error message.

# ./configure --enable-so
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
configure failed for srclib/apr

Install the gcc and the dependent modules as shown below and try ./configure again to fix the above issue.

# rpm -ivh gcc-4.1.2-14.el5.i386.rpm glibc-devel-2.5-18.i386.rpm glibc-headers-2.5-18.i38
6.rpm kernel-headers-2.6.18-53.el5.i386.rpm
Preparing...                ########################################### [100%]
1:kernel-headers         ########################################### [ 25%]
2:glibc-headers          ########################################### [ 50%]
3:glibc-devel            ########################################### [ 75%]
4:gcc                    ########################################### [100%]

3. Start Apache and verify installation

# cd /usr/local/apache2/bin
# ./apachectl start

Go to http://local-host, which should display the default message “It Works!”

4. Start Apache automatically during system startup

Modify the /etc/rc.d/init.d/httpd script and change apachectl and httpd variable to point to the appropriate new location as shown below. Please note that this httpd script was originally installed as part of the default Apache from the Linux distribution.

apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}

Now, you can perform the following to stop and start the Apache

# service httpd stop
# service httpd start

Setup the Apache to automatically startup during reboot as shown below.

# chkconfig --list httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
# chkconfig --level 2345 httpd on
# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

Reduce Keystrokes using AutoHotKey for Windows- Productivity Tip



For geeks to be more productive, using keyboards as much as possible is a must. AutoHotKey for windows is an excellent tool that can automate repetitive typing. Using scripting in AutoHotKey, you can pretty much perform any activities on Windows. This is a jumpstart guide to get you started on the AutoHotKey.

Install and Configure

1.    Download the AutoHotKey and install using the default options.

2.    Launch the AutoHotKey, which will display a dialog confirming that a sample script file will be created.  Click on “Yes” to create the sample AutoHotkey.ahk in the My Documents folder. Later if you want to create a script file under a different directory, from the Windows Explore menu click on File -> New -> AutoHotKey Script.

3.    Make sure AutoHotKey is running in the windows task bar. You can also open the AutHotKey.ahk script by right-mouse click on the AutoHotKey icon from the system tray and select “Edit this script”.

4.    Anytime you make changes to the AutoHotkey.ahk, you need to Reload the script by right-mouse click on the AutoHotKey icon on the system tray and select “Reload this script”.

Basic Usage of AutoHotKey

(1)  Email Signature. Add the following two lines to the AutoHotKey.ahk and reload the script as explained above. For testing, open notepad and type -rn, which will be automatically replaced with the full name “Ramesh Natarajan” as defined in the *.ahk file.  Comments in the AutoHotkey.ahk begins with semi-colon.

; tip#1 - Type long names quickly
::-rn::Ramesh Natarajan

(2) Email Signature with multiple lines. In this example, typing “rtgs” from my email message will add the multiple-line content located within the parenthesis ( ). It is important to choose a keyword that you can easily remember and not common words that could potentially be replaced automatically by mistake.

; tip#2 - My personal email signature with the URL
::rtgs::
(
Ramesh
<a href="http://www.thegeekstuff.com">The Geek Stuff</a>
)

(3) Current Date and Time: When you are taking notes in a textpad, sometimes it may be a good idea to put the current date and time before you start taking notes. In the following example, when you type “ndate” from the notepad, it will add the current date and time in the format mentioned below.

; tip#3 - Adding the timestamp quickly while taking notes
:*:ndate::
FormatTime, CurrentDateTime,, M/d/yyyy h:mm tt  ; It will look like 6/29/2008 10:35 AM
SendInput %CurrentDateTime%
return

(4) Open a website in a browser: Sometime it may be necessary to open your frequently used website with a single key stroke. In the following example, typing “Windows” key + “t” will open the default web browser and launch www.thegeekstuff.com. Please note that “#” in the following line represents the “Windows” key in the keyboard.

; tip#4 - Open frequently used website
#t::Run www.thegeekstuff.com

(5) Open frequently used folder by pressing “Windows” key + “p”.

; tip#5 - Open frequently used folder
#p::Run "C:\my-project\projectplan"

(6) Open frequently used document by pressing “Windows” key + “c”

; tip#6 - Open frequently used document
#c::Run open "C:\my-project\documents\codedesign.doc"

(7) Advanced scripting. In the following example, you can select any text from any application and press “Control+Alt+w”, which will open the Notepad++ application and paste the selected text.

; tip#7 - Advanced scripting
^!w::
Send, ^c
SetWorkingDir, %ProgramFiles%\WordNet\Notepad++\
Run, notepad++.exe
WinWait, Notepad++
WinActivate
Send, ^v{Enter}
return

 

Backup and Restore MySQL Database using mysqlhotcopy



mysqlhotcopy is a perl script that comes with MySQL installation. This locks the table, flush the table and then performs a copy of the database. You can also use the mysqlhotcopy to automatically copy the backup directly to another server using scp
.

1. mysqlhotcopy command:

[local-host]# /usr/bin/mysqlhotcopy -u root -p My2Secure$Password sugarcrm /home/backup/database --allowold --keepold

The above example, performs a backup of sugarcrm, a MySQL database to the /home/backup/database directory.

§  –allowold: This options renames the old backup to {datbase-name}_old before taking a new backup. In this example, if sugarcrm backup already existing under /home/backup/database, it will move the old backup to /home/backup/database/sugarcrm_old before creating /home/backup/database/sugarcrm.

§  –keepold: This option instructs the mysqlhotcopy to keep the old backup (i.e the renamed _old) after the backup is completed.

View the mysqlhotcopy documentation using perldoc as shown below.

[local-host]# perldoc mysqlhotcopy

Following are the available options that can be passed to mysqlhotcopy command.

Option

Description

–addtodest

Do not rename target directory (if it exists); merely add files to it

–allowold

Do not abort if a target exists; rename it by adding an _old suffix

–checkpoint=db_name.tbl_name

Insert checkpoint entries

–chroot=path

Base directory of the chroot jail in which mysqld operates

–debug

Write a debugging log

–dryrun

Report actions without performing them

–flushlogs

Flush logs after all tables are locked

–help

Display help message and exit

–host=host_name

Connect to the MySQL server on the given host

–keepold

Do not delete previous (renamed) target when done

–noindices

Do not include full index files in the backup

–password[=password]

The password to use when connecting to the server

–port=port_num

The TCP/IP port number to use for the connection

–quiet

Be silent except for errors

–regexp

Copy all databases with names that match the given regular expression

–resetmaster

Reset the binary log after locking all the tables

–resetslave

Reset the master.info file after locking all the tables

–socket=path

For connections to localhost

–tmpdir=path

The temporary directory

–user=user_name,

The MySQL username to use when connecting to the server

–version

Display version information and exit

2. mysqlhotcopy command output:

The above mysqlhotcopy command will display an output similar to the following.

[local-host]# /usr/bin/mysqlhotcopy -u root -p My2Secure$Password sugarcrm /home/backup/database --allowold --keepold
Locked 98 tables in 0 seconds.
Flushed tables (`sugarcrm`.`accounts`, `sugarcrm`.`accounts_audit`, `sugarcrm`.`accounts_bugs`) in 0 seconds.
Copying 295 files...
Copying indices for 0 files...
Unlocked tables.
mysqlhotcopy copied 98 tables (295 files) in 0 seconds (0 seconds overall).

By default, MySQL database is located under /var/lib/mysql/{db-name}. mysqlhotcopy takes a backup of the table files from this default database location, to the backup directory. The backup directory /home/backup/database/sugarcrm,  will contain exact copy of all the files from the real MySQL database /var/lib/mysql/sugarcrm directory.

[local-host]# ls -1 /var/lib/mysql/sugarcrm | wc -l
295
[local-host]# ls -1 /home/backup/database/sugarcrm | wc -l
295

Please note that every table has three corresponding files with the extension *.frm, *.MYD and *.MYI.  The database directory also contains a db.opt file that contains the database related parameter.

In the above example, you can see the mysqlhotcopy takes a backup of 98 sugarcrm database tables. So, the total number of files in the backup directory = 98 tables * 3 + 1 db configuration file = 296 files.

3. Restore from mysqlhotcopy

To restore the backup from the mysqlhotcopy backup, simply copy the files from the backup directory to the /var/lib/mysql/{db-name} directory. Just to be on the safe-side, make sure to stop the mysql before you restore (copy) the files. After you copy the files to the /var/lib/mysql/{db-name} start the mysql again.

4. Troubleshooting mysqlhotcopy

How to resolve Can’t locate DBD/mysql.pm issue? mysqlhotcopy is a perl script and it requires the perl-DBD module. You may receive the following error while executing mysqlhotcopy if perl-DBD module is not installed.

[local-host]# /usr/bin/mysqlhotcopy -u root -p My2Secure$Password sugarcrm /home/backup/database --allowold --keepold
install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains:
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/5.8.8 .) at (eval 7) line 3.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: DBM, ExampleP, File, Proxy, Sponge.
at /usr/bin/mysqlhotcopy line 177

Make sure to install the perl-DBD package as shown below.

[local-host]# rpm -ivh perl-DBD-MySQL-3.0007-1.fc6.i386.rpm
Preparing...                ########################################### [100%]
1:perl-DBD-MySQL         ########################################### [100%]

How to resolve the issue with perl-DBD installation? While installing the perl-DBD, you may get the following error message.

[local-host]# rpm -ivh perl-DBD-MySQL-3.0007-1.fc6.i386.rpm
rpmdb: Program version 4.3 doesn't match environment version
error: db4 error(-30974) from dbenv->open: DB_VERSION_MISMATCH: Database environment version mismatch
error: cannot open Packages index using db3 -  (-30974)
warning: cannot open Solve database in /usr/lib/rpmdb/i386-redhat-linux/redhat
rpmdb: Program version 4.3 doesn't match environment version
error: db4 error(-30974) from dbenv->open: DB_VERSION_MISMATCH: Database environment version mismatch
warning: cannot open Solve database in /usr/lib/rpmdb/i386-redhat-linux/redhat
error: Failed dependencies:
libmysqlclient.so.15 is needed by perl-DBD-MySQL-3.0007-1.fc6.i386
libmysqlclient.so.15(libmysqlclient_15) is needed by perl-DBD-MySQL-3.0007-1.fc6.i386

Download and install the MySQL-shared-compat from mysql.com and this should resolve the above mentioned error while installing the perl-DBD package.

[local-host]# rpm -ivh MySQL-shared-compat-5.1.25-0.rhel5.i386.rpm
Preparing...                ########################################### [100%]
1:MySQL-shared-compat    ########################################### [100%]

Do you use any other methods to backup or restore your MySQL database?  Please leave your comments.