Installing SSH2 extension for PHP on Centos 6

Installing the SSH2 PHP extension on CentOS is actually pretty simple. Although it isn’t available as a straight yum install, it boils down to a few short steps.
Firstly, we’re going to install the dependencies:

yum install gcc php-devel php-pear libssh2 libssh2-devel

These will allow us to build the SSH2 extension using pecl.

pecl install -f ssh2

After running that command, it should stop at a line like:

WARNING: channel "" has updated its protocols, use "pecl channel-update" to update
downloading ssh2-0.11.3.tgz ...
Starting to download ssh2-0.11.3.tgz (23,062 bytes)
........done: 23,062 bytes
5 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
libssh2 prefix? [autodetect] :

All you have to do is hit Enter and it should detect the proper path. Once the install is completed, you just have to tell PHP to load the extension when it boots.

touch /etc/php.d/ssh2.ini
echo > /etc/php.d/ssh2.ini

Now restart your webserver and test to see if the changes took effect.

/etc/init.d/lighttpd restart
php -m | grep ssh2

You should get a line returned with ‘ssh2′.

lighttpd doesn’t start – selinux

Lighttpd doesn’t start due to a conflict with file descriptors:


# /etc/init.d/lighttpd restart
Stopping lighttpd:                                 [FAILED]
Starting lighttpd: 2012-06-03 00:57:12: (server.c.722) couldn't set 'max filedescriptors' Permission denied


Install SE utils

yum install policycoreutils-python

Create SELinux module to allow lighttpd to set its own open file descriptors limit

#/usr/sbin/semodule -DB
# /etc/init.d/auditd restart
Stopping auditd:                                   [  OK  ]
Starting auditd:                                   [  OK  ]
#grep lighttpd /var/log/audit/audit.log | audit2allow -M lighttpdmaxfds
#/usr/sbin/semodule -i lighttpdmaxfds.pp
# /etc/init.d/lighttpd restart
Stopping lighttpd:                                 [FAILED]
Starting lighttpd:                                 [  OK  ]
# /usr/sbin/semodule -B

Create WMQ QueueManager using script

Here is a handy script to make QM on Centos. This should be run after switching to mqm user.

Save the following as


##            Main Routine

echo "Checking if [$qm] exists?..."
qm=`dspmq | awk '{ print $1 }' | sed 's/QMNAME(//g;s/)//g' | grep -o $qm`
if [ "$qm" = "" ];
echo "Creating: [$qm]"
`crtmqm $qm`
echo "Successfully created $q, Exiting with value 0"
echo "[$qmname], already exists"
status=`dspmq -m $qmname| cut -d '(' -f2,3 | cut -d ')' -f2 | cut -d '(' -f2`
echo status of queue manager [$qm] is [$status]
echo "Exiting Main Routine.. "

##                 Entry Point

if [ ! "$1" ];
echo "Fail: You must pass in a queue manager name"
exit 1
echo "Queue Manager to create = $qm"
echo "Calling Main function ... "
main $*
exit 0

Use following command to create Queue Manager TEST_QM1

Install WMQ6.0 on Centos

This article explains step-by-step installation of WMQ6.0 on Centos 6.0.

  • Download WMQ6.0 from IBM Website ( login required)
  • After downloading the package and extracting the same on /tmp, accept license by running script
  • Install the packages, commands listed below
rpm  -ivh  MQSeriesServer-6.0.2-3.i386.rpm
rpm  -ivh  MQSeriesRuntime-6.0.2-3.i386.rpm
rpm  -ivh  MQSeriesSDK-6.0.2-3.i386.rpm
rpm  -ivh  MQSeriesSamples-6.0.2-3.i386.rpm
rpm  -ivh  MQSeriesClient-6.0.2-3.i386.rpm
rpm  -ivh  MQSeriesJava-6.0.2-3.i386.rpm
rpm  -ivh  MQSeriesTXClient-6.0.2-3.i386.rpm
rpm  -ivh  MQSeriesServer-6.0.2-3.i386.rpm
rpm  -ivh  MQSeriesMan-6.0.2-3.i386.rpm
rpm  -ivh –nodeps  MQSeriesFTA-6.0.2-3.i386.rpm
rpm  -ivh –nodeps MQSeriesIES30-6.0.2-3.i386.rpm
rpm  -ivh –nodeps MQSeriesConfig-6.0.2-3.i386.rpm
rpm  -ivh  MQSeriesKeyMan-6.0.2-3.i386.rpm
rpm  -ivh  gsk7bas-7.0-4.11.i386.rpm
rpm  -ivh  IBMJava2-142-ia32-SDK-1.4.2-9.0.i386.rpm 
  • Done.

A Brief outline on IBM Webshpere MQ (WMQ)

IBM Websphere MQ (WMQ or MQ Series) is a middleware for messaging in a cross platform environment. MQI – Message Queue Interface – api used to commmunicate with a Message Queue Manager (MQM). 

Queue Manager (MQM) 

  • Manages queues and messages for applications 
  • Transfers messages to other Queue Managers via channels using existing network facilities. 
  • It refers to objects that are defined by the administrator.
  • Coordinates updates to databases and queues using two-phase commit. 
  • Gets and puts from/to queues are committed together with SQL updates, or backed out if necessary. 
  • Segments messages, if necessary, and assembles them. 
  • Can group messages and send them as one physical message to their destination, where they are automatically disassembled. 
  • Can send one message to more than one destination using a user-defined dynamic destination list. 
  • Allow administrators to create and delete queues, alter properties of existing queues,control the operation of queue manager. 
  • Front-end available on Eclipse to manage Queue Manager 

 Queue Manager Clusters 

  • Queue Managers that form a cluster can run in the same machine or in different machines on different platforms. 
  • Two of Queue Managers maintain a repository that contains information about all queue managers and queues in the cluster (full repository). Other Queue Managers maintain only a repository of the objects they are interested in (partial repository).
  • Queue Managers use special cluster channels to exchange information. 
  • Client application may specify a queue manager and direct the message to a specific queue in a cluster or it may let a queue manager to determine where the queue is and to which one to send the message. 
  • Client uses a Transmission Queue on its machine and destination queue is called “Target Queue”. 
  • Administrator must define the name of the cluster, when a queue is defined. 
  • MQSeries distributes the messages round robin. 

 Queue Manager Objects 

  •  A Queue Manager uses 3 types of objects, namely, Queues, Process Definitions and Channels. 
  • Queues are used to store messages. 
  • Process Definition object defines an application to a queue manager. It contains a name of a program (and its path) to be triggered when a message arrives for it.
  • Channel is a communication link. There are 2 kinds of channels, namely, Message Channels and MQI channels. 
  • Message Channel connects 2 queue managers via Message Channel Agents (MCA). Message Channel is unidirectional. 
  • MCA is a program (also called mover) that transfers messages from a transmission queue to a communication link and from communication link to a target queue. 
  • MQI channel connects MQSeries client to a queue manager and is bi-directional. 
  • Message Channel can run at 2 speeds: fast and normal. Fast Channels improve performance but messages can be lost in case of channel failure. 

Message Queues 

  • Message Queues belong to Queue Manager. 
  • Types of Messages Queues are: 
    • Local Queue – is a real queue
    • Cluster Queue – is a local queue that is known throughout a cluster of queue managers. 
    • Remote Queue – structure describing a queue hosted by a different queue manager. 
    • Transmission Queue – a local queue used for messages to be sent to a remote queue. 
    • Initiation Queue – local queue with a special purpose 
    • Dynamic Queue – local queue created on the fly 
    • Alias Queue – if you do not like the queue name 
    • Dead-Letter Queue – one for each queue manager 
    • Reply-to Queue – specified in request message 
    • Model Queue – model for local queues 
    • Repository Queue – hold cluster information 

Samba as a Primary Domain Controller

Although it cannot act as an Active Directory Primary Domain Controller (PDC), a Samba server can be configured to appear as a Windows NT4-style domain controller. A major advantage of this configuration is the ability to centralize user and machine credentials. Samba can also use multiple backends to store the user information.

Primary Domain Controller

This section covers configuring Samba as a Primary Domain Controller (PDC) using the default smbpasswd backend.

First, install Samba, and libpam-smbpass to sync the user accounts, by entering the following in a terminal prompt:

sudo apt-get install samba libpam-smbpass
Next, configure Samba by editing /etc/samba/smb.conf. The security mode should be set to user, and the workgroup should relate to your organization:

workgroup = EXAMPLE

security = user
In the commented “Domains” section add or uncomment the following:

domain logons = yes
logon path = \%N%Uprofile
logon drive = H:
logon home = \%N%U
logon script = logon.cmd
add machine script = sudo /usr/sbin/useradd -N -g machines -c Machine -d /var/lib/samba -s /bin/false %u
domain logons: provides the netlogon service causing Samba to act as a domain controller.

logon path: places the user’s Windows profile into their home directory. It is also possible to configure a [profiles] share placing all profiles under a single directory.

logon drive: specifies the home directory local path.

logon home: specifies the home directory location.

logon script: determines the script to be run locally once a user has logged in. The script needs to be placed in the [netlogon] share.

add machine script: a script that will automatically create the Machine Trust Account needed for a workstation to join the domain.

In this example the machines group will need to be created using the addgroup utility see the section called “Adding and Deleting Users” for details.

Also, rights need to be explicitly provided to the Domain Admins group to allow the add machine script (and other admin functions) to work. This is achieved by executing:

net rpc rights grant “EXAMPLEDomain Admins” SeMachineAccountPrivilege SePrintOperatorPrivilege
SeAddUsersPrivilege SeDiskOperatorPrivilege SeRemoteShutdownPrivilege

If you wish to not use Roaming Profiles leave the logon home and logon path options commented.

Uncomment the [homes] share to allow the logon home to be mapped:

comment = Home Directories
browseable = no
read only = no
create mask = 0700
directory mask = 0700
valid users = %S
When configured as a domain controller a [netlogon] share needs to be configured. To enable the share, uncomment:

comment = Network Logon Service
path = /srv/samba/netlogon
guest ok = yes
read only = yes
share modes = no

The original netlogon share path is /home/samba/netlogon, but according to the Filesystem Hierarchy Standard (FHS), /srv is the correct location for site-specific data provided by the system.

Now create the netlogon directory, and an empty (for now) logon.cmd script file:

sudo mkdir -p /srv/samba/netlogon
sudo touch /srv/samba/netlogon/logon.cmd
You can enter any normal Windows logon script commands in logon.cmd to customize the client’s environment.

With root being disabled by default, in order to join a workstation to the domain, a system group needs to be mapped to the Windows Domain Admins group. Using the net utility, from a terminal enter:

sudo net groupmap add ntgroup=”Domain Admins” unixgroup=sysadmin rid=512 type=d

Change sysadmin to whichever group you prefer. Also, the user used to join the domain needs to be a member of the sysadmin group, as well as a member of the system admin group. The admin group allows sudo use.

Finally, restart Samba to enable the new domain controller:

sudo restart smbd
sudo restart nmbd
You should now be able to join Windows clients to the Domain in the same manner as joining them to an NT4 domain running on a Windows server.

Backup Domain Controller
With a Primary Domain Controller (PDC) on the network it is best to have a Backup Domain Controller (BDC) as well. This will allow clients to authenticate in case the PDC becomes unavailable.

When configuring Samba as a BDC you need a way to sync account information with the PDC. There are multiple ways of accomplishing this scp, rsync, or by using LDAP as the passdb backend.

Using LDAP is the most robust way to sync account information, because both domain controllers can use the same information in real time. However, setting up a LDAP server may be overly complicated for a small number of user and computer accounts. See the section called “Samba and LDAP” for details.

First, install samba and libpam-smbpass. From a terminal enter:

sudo apt-get install samba libpam-smbpass
Now, edit /etc/samba/smb.conf and uncomment the following in the [global]:

workgroup = EXAMPLE

security = user
In the commented Domains uncomment or add:

domain logons = yes
domain master = no
Make sure a user has rights to read the files in /var/lib/samba. For example, to allow users in the admin group to scp the files, enter:

sudo chgrp -R admin /var/lib/samba
Next, sync the user accounts, using scp to copy the /var/lib/samba directory from the PDC:

sudo scp -r username@pdc:/var/lib/samba /var/lib

Replace username with a valid username and pdc with the hostname or IP Address of your actual PDC.

Finally, restart samba:

sudo restart smbd
sudo restart nmbd
You can test that your Backup Domain controller is working by stopping the Samba daemon on the PDC, then trying to login to a Windows client joined to the domain.

Another thing to keep in mind is if you have configured the logon home option as a directory on the PDC, and the PDC becomes unavailable, access to the user’s Home drive will also be unavailable. For this reason it is best to configure the logon home to reside on a separate file server from the PDC and BDC.

Howto Samba Active Directory Integration

Samba Directory Server Integration

  1. Once part of an Active Directory domain, Samba can provide file and print services to AD users.
    The simplest way to join an AD domain is to use Likewise-open.

Once part of the domain, enter the following command in the terminal prompt:

sudo apt-get install samba smbfs smbclient

Since the likewise-open and samba packages use separate secrets.tdb files, a symlink will need to be created in/var/lib/samba:

sudo mv /var/lib/samba/secrets.tdb /var/lib/samba/secrets.tdb.orig
sudo ln -s /etc/samba/secrets.tdb /var/lib/samba

Next, edit /etc/samba/smb.conf changing:

workgroup = EXAMPLE
security = ads
idmap backend = lwopen
idmap uid = 50-9999999999
idmap gid = 50-9999999999

Restart samba for the new settings to take effect:

sudo restart smbd
sudo restart nmbd

You should now be able to access any Samba shares from a Windows client. However, be sure to give the appropriate AD users or groups access to the share directory. See the section called “Securing a Samba File and Print Server” for more details.

Accessing a Windows Share

Now that the Samba server is part of the Active Directory domain you can access any Windows server shares:

  • To mount a Windows file share enter the following in a terminal prompt:
    mount.cifs // mount_point

    It is also possible to access shares on computers not part of an AD domain, but a username and password will need to be provided.

  • To mount the share during boot place an entry in /etc/fstab, for example:
    // /mnt/windows cifs auto,username=steve,password=secret,rw 0        0
  • Another way to copy files from a Windows server is to use the smbclient utility. To list the files in a Windows share:
    smbclient // -k -c "ls"
  • To copy a file from the share, enter:
    smbclient // -k -c "get file.txt"

    This will copy the file.txt into the current directory.

  • And to copy a file to the share:
    smbclient // -k -c "put /etc/hosts hosts"

    This will copy the /etc/hosts to //

  • The -c option used above allows you to execute the smbclient command all at once. This is useful for scripting and minor file operations. To enter the smb: > prompt, a FTP like prompt where you can execute normal file and directory commands, simply execute:
    smbclient // -k
Replace all instances of,username=steve,password=secret, and file.txt with your server’s IP, hostname, share name, file name, and an actual username and password with rights to the share.