Wednesday, March 21, 2012

How to enable php with apache on linux?

Purpose : Enable php engine in apache
OS Environement : Linux [RHEL, Centos]
Application : php, apache httpd
Prerequisites : Make sure php is installed in the system first.
Implementation Steps : 

1. Locate libphp5.so

In most of cases, libphp5.so will be present inside /etc/httpd/modules

2. Add following in httpd.conf :

# Use for PHP 5.x:
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php

# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php

AddType text/html .php

# PHP Syntax Coloring
# (optional but useful for reading PHP source for debugging):

AddType application/x-httpd-php-source phps

3. Restart apache web server :

$ /etc/init.d/httpd restart

4. Verification :

$ httpd -t|grep -i php

5. Create a php file inside web directory. Put the following content in that file like :

vi info.php


phpinfo();
?>

6. Access the file through browser like http://localhost/info.php. If it shows all the enables php directives or modules then php works fine.


Wednesday, March 14, 2012

How to store sftp log messages in custom file on Linux ?

■  Purpose : store sftp log messages in custom file
■ OS Environment : RHEL 6
■  Applications: sftp, syslog
■  Prerequisites : Assuming chrooted environment is setup at /chroot, disable SELinux
■  Implementation Steps :

1. Modify sshd config file. 

Make sure "AUTHPRIV" facility is used in sshd_config file. Sample file looks like :

$ cat /etc/ssh/sshd_config :

Subsystem sftp internal-sftp -f AUTHPRIV -l VERBOSE

2. Use proper additional socket file in /etc/sysconfig/rsyslog like :

vi /etc/sysconfig/rsyslog

SYSLOGD_OPTIONS="-m 0 -a /chroots/dev/log"

3. Following lines should be present in /etc/rsyslog.conf :

Add following lines :

$InputUnixListenSocketHostname internal-sftp
$AddUnixListenSocket /chroots/dev/log

# Log internal-sftp activity in a separate file

:programname, isequal, "internal-sftp" -/var/log/sftp.log
:programname, isequal, "internal-sftp" ~
:programname, isequal, "sshd" -/var/log/sftp.log
:programname, isequal, "sshd" ~


4. Make sure that a hard link to socket file like :

$mkdir -p /chroots/dev
$ln /chroots/dev/log /chroots/
dev/log

5. Restart rsyslog and sshd service :

$ service rsyslog restart
$ service sshd restart


6. Testing :

Open a terminal and execute following command on it like :

$tailf /var/log/sftp.log

Try to access SFTP account like :

$sftp username@IP
pw: 

Enter password You'll see that all sftp logs messages are available in /var/log/sftp.log. 


Wednesday, March 7, 2012

How to setup multiple gateways for multiple Ethernets?

■ Purpose : Setup multiple gateways in linux
■ OS Environment : Linux [RHEL 5, 6]
■  Application : iproute package
■  Implementation Steps :
■  Assumption : eth0 has gateway 10.1XX.69.1 and eth3's gateway is 10.1XX.66.1.

Concept : Defining the gateway in two tables in conjunction with each interface.

1. Put entries in routing table :

echo "1 ISP1" >> /etc/iproute2/rt_tables
echo "2 ISP2 " >> /etc/iproute2/rt_tables

2.  Setup routing rules for  ISP1 table:

$ ip route add default via 10.1XX.69.1 dev eth0 table ISP1
$ ip rule add from 10.1XX.69.0/24 table ISP1


For the ISP2 table:

$ ip route add default via 10.1XX.66.1 dev eth3 table ISP2
$ ip rule add from 10.1XX.66.0/24 table ISP2

3. Make above rules persistent:

Put below entries in rc.local file  :

ip route add default via 10.1XX.69.1 dev eth0 table ISP1
ip rule add from 10.1XX.69.0/24 table ISP1
ip route add default via 10.1XX.66.1 dev eth3 table ISP2
ip rule add from 10.1XX.66.0/24 table ISP2

Note : You should replace the IP addresses in above commands.