August 27th, 2008

Under PHP you need to use header() to send a raw HTTP header.
Using headers() method, you can easily transferred to the new page without having to click a link to continue. This is also useful for search engines. Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

PHP Redirect Script

You can easily redirect using following code:

<?php
/* Redirect browser */
header(”Location: http://theos.in/”);
/* Make sure that code below does not get executed when we redirect. */
exit;
?>

August 27th, 2008

You need to use biosdecode command line utility. Dmidecode is a tool or dumping a computer’s DMI (some say SMBIOS) table contents in a human-readable format. The output contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. This command works under Linux, UNIX and BSD computers.
Open a shell prompt and type the following command:
$ sudo dmidecode –type 17
OR
$ sudo dmidecode –type 17 | more
Sample output:

# dmidecode 2.9
SMBIOS 2.4 present.

Handle 0×0018, DMI type 17, 27 bytes
Memory Device
Array Handle: 0×0017
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 2048 MB
Form Factor: DIMM
Set: None
Locator: J6H1
Bank Locator: CHAN A DIMM 0
Type: DDR2
Type Detail: Synchronous
Speed: 800 MHz (1.2 ns)
Manufacturer: 0×2CFFFFFFFFFFFFFF
Serial Number: 0×00000000
Asset Tag: Unknown
Part Number: 0×5A494F4E203830302D3247422D413131382D

Handle 0×001A, DMI type 17, 27 bytes
Memory Device
Array Handle: 0×0017
Error Information Handle: Not Provided
Total Width: Unknown
Data Width: Unknown
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: J6H2
Bank Locator: CHAN A DIMM 1
Type: DDR2
Type Detail: None
Speed: Unknown
Manufacturer: NO DIMM
Serial Number: NO DIMM
Asset Tag: NO DIMM
Part Number: NO DIMM

ref : http://www.cyberciti.biz/faq/check-ram-speed-linux/

August 7th, 2008

This tutorial details installation of eAccelerator on Ubuntu 8.04 (Hardy Heron) and most Debian systems.

eAccelerator is a free open-source PHP accelerator, optimizer, and dynamic content cache. It increases the performance of PHP scripts by caching them in their compiled state, so that the overhead of compiling is almost completely eliminated. It also optimizes scripts to speed up their execution. eAccelerator typically reduces server load and increases the speed of your PHP code by 1-10 times.”

eAccelerator stores compiled PHP scripts in shared memory and executes code directly from it. It creates locks only for a short time, while searching for a compiled PHP script in the cache, so one script can be executed simultaneously by several engines. Files that can’t fit in shared memory are cached on disk only.”

It is important to note which version of PHP you are using on your system. “eAccelerator is still under development. The latest release, 0.9.5.3, supports PHP 4 and all PHP 5 releases including 5.2. In older releases, the encoder will only work with PHP versions from the 4.x.x branch. eAccelerator will not work with any other versions of PHP.”

 

Display PHP Information

PHP will report the relevant information about the installed version of PHP when you execute the phpinfo() function.  You will need to know what version of PHP you have installed in your system so you can load the appropriate version of eAccelerator. In order to execute this function from your machine you need to use your favorite editor to install the following file named info.php into the base directory (/var/www/):

<?php
phpinfo();
php?>
Using your browser enter the IP address of your server via http, such as http://localhost/info.php or http://192.168.1.2/info.php or via https, such as https://192.168.1.2/info.php to display the PHP configuration of your system:

PHPINFO Basic System.png

Note the PHP version which is installed on your system.

 

Prerequisites

The installation of eAccelerator on Ubuntu 8.04 will require that several program packages be installed on your system.  php5-dev is required to get the program phpize.  make is required for the program make.  Note that if you already have these packages installed on your system there is no harm in running the following commands as they will only confirm that the packages are already installed.

sudo apt-get install php5-dev
sudo apt-get install make

 

Install eAccelerator

Get the latest version of the eAccelerator from the eAccelerator Project.  Note that different versions of eAccelerator may or may not be compatible with your version of PHP.  Be sure to match the correct eAccelerator with your version of PHP.  With Ubuntu 8.04 it will be assumed that you are using PHP 5.2.x so eAccelerator 0.9.5.3 has been selected for installation.

sudo cd /tmp/
sudo wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
sudo tar xvjf eaccelerator-0.9.5.3.tar.bz2
sudo cd eaccelerator-0.9.5.3
sudo phpize
sudo ./configure –enable-eaccelerator=shared
sudo make
sudo make install

Now edit /etc/php5/apache2/php.ini and add the following line at the beginning of the file after the [PHP] tag:

[PHP]

; eAccelerator configuration
; Note that eAccelerator may also be installed as a PHP extension or as a zend_extension
; If you are using a thread safe build of PHP you must use
; zend_extension_ts instead of zend_extension
;extension                                = “/usr/lib/php5/20060613+lfs/eaccelerator.so”
zend_extension                       = “/usr/lib/php5/20060613+lfs/eaccelerator.so”
eaccelerator.shm_size           = “16″
eaccelerator.cache_dir          = “/var/cache/eaccelerator”
eaccelerator.enable             = “1″
eaccelerator.optimizer          = “1″
eaccelerator.check_mtime        = “1″
eaccelerator.debug              = “0″
eaccelerator.filter             = “”
eaccelerator.shm_max            = “0″
eaccelerator.shm_ttl            = “0″
eaccelerator.shm_prune_period   = “0″
eaccelerator.shm_only           = “0″
eaccelerator.compress           = “1″
eaccelerator.compress_level     = “9″
eaccelerator.allowed_admin_path = “/var/www/eaccelerator”
NOTE:  If you install Zend Optimizer and/or ionCube Loader you should be sure that ionCube loads before Zend Optimizer and eAccelerator installs before both for proper operation of all three extensions.
[PHP]

; eAccelerator configuration
; Note that eAccelerator may also be installed as a PHP extension or as a zend_extension
; If you are using a thread safe build of PHP you must use
; zend_extension_ts instead of zend_extension
;extension                       = “/usr/lib/php5/20060613+lfs/eaccelerator.so”
zend_extension                  = “/usr/lib/php5/20060613+lfs/eaccelerator.so”
eaccelerator.shm_size           = “16″
eaccelerator.cache_dir          = “/var/cache/eaccelerator”
eaccelerator.enable             = “1″
eaccelerator.optimizer          = “1″
eaccelerator.check_mtime        = “1″
eaccelerator.debug              = “0″
eaccelerator.filter             = “”
eaccelerator.shm_max            = “0″
eaccelerator.shm_ttl            = “0″
eaccelerator.shm_prune_period   = “0″
eaccelerator.shm_only           = “0″
eaccelerator.compress           = “1″
eaccelerator.compress_level     = “9″
eaccelerator.allowed_admin_path = “/var/www/eaccelerator”

; ionCube Loader configuration
zend_extension=/usr/local/lib/ioncube/ioncube_loader_lin_5.2.so

; Zend Optimizer configuration
zend_extension=/usr/local/lib/Zend/ZendOptimizer.so
zend_optimizer.optimization_level=15
Create and change permissions of the eAccelerator cache directory

sudo mkdir -p /var/cache/eaccelerator
sudo chmod 0777 /var/cache/eaccelerator

Restart Apache

sudo /etc/init.d/apache2 restart
Reload the info.php file that you created above in your browser you should now see that eAccelerator is mentioned in a box below the PHP Information on the page.  The box should look something like this:

info-php with eAccelerator.png

eAccelerator has now been successully installed.

Further down on the same page is a summary of the configuration for eAccelerator verifying the setup.

info-php eAccelerator.png

 ref : http://wiki.developer.mindtouch.com/MindTouch_Deki/FAQ/Configuration/How_do_I…Install_eAccelerator_on_Ubuntu_8.04_(Debian)

August 6th, 2008

Complex PHP applications, such as Drupal, can gain a lot of performance benefits from running a PHP op-code cache/accelerators.

APC,
Alternate PHP Cache, is now the most maintained free/open source op-code cache, and is being used more and more as it emerges to be the
most stable.

The instructions here detail how to get APC running on a CentOS 5 server. The server happened to have Plesk on it as well, which initially made me hesitant to install APC “normally”, since Plesk is so picky on what other software is installed on the server. However, it seems to have worked out well.

First, we need the pecl command so we can download and install APC from the repositories.

Do to so, we execute the following command:

yum install php-pear

But, this will not run on its own, we need the following package for the phpize command:

yum install php-devel

We also need the apxs command, which is installed via the following package:

yum install httpd-devel

Now we have all the software we need, so we install apc via the pecl command:

pecl install apc

Once that finishes, we need to enable apc in Apache’s configuration. the following command should do this for us.

echo “extension=apc.so” > /etc/php.d/apc.ini

Then we restart Apache:

/etc/init.d/httpd start

And we are all done. Watch for less execution time per page, and decreased memory usage per Apache process compared to what you had
before.

ref : http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html

August 6th, 2008

Complex PHP applications, such as Drupal, can gain a lot of performance benefits from running a PHP op-code cache/accelerators.

APC, Alternate PHP Cache, is now the most maintained free/open source op-code cache, and is being used more and more as it emerges to be the most stable.

The instructions here detail how to get APC running on an Ubuntu server running Gutsy Gibbon 7.10.

First, we need the pecl command so we can download and install APC from the repositories.

Do to so, we execute the following command:

aptitude install php-pear

But, this will not run on its own, we need the following package for the phpize command:

aptitude install php5-dev

We also need the apxs command, which is installed via the following package:

aptitude install apache2-dev

Now we have all the software we need, so we install apc via the pecl command:

pecl install apc

Once that finishes, we need to enable apc in Apache’s configuration. the following command should do this for us.

echo “extension=apc.so” > /etc/php5/apache2/conf.d/apc.ini

Then we restart Apache:

/etc/init.d/apache2 restart

And we are all done. Watch for less execution time per page, and decreased memory usage per Apache process compared to what you had before.

ref :  http://2bits.com/articles/installing-php-apc-gnulinux-ubuntu-gutsy-gibbon-710-and-debian.html

July 30th, 2008

Edit configuration files stored in /etc/sysconfig/network-scripts/

You can configure network card by editing text files stored in /etc/sysconfig/network-scripts/ directory. First change directory to /etc/sysconfig/network-scripts/:
# cd /etc/sysconfig/network-scripts/
You need to edit / create files as follows:

* /etc/sysconfig/network-scripts/ifcfg-eth0 : First Ethernet card configuration file
* /etc/sysconfig/network-scripts/ifcfg-eth1 : Second Ethernet card configuration file

To edit/create first NIC file, type command:
# vi ifcfg-eth0
Append/modify as follows:

# Intel Corporation 82573E Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:30:48:56:A6:2E
IPADDR=192.168.0.252
NETMASK=255.255.255.192
ONBOOT=yes

Save and close the file. Define default gateway (router IP) and hostname in /etc/sysconfig//network file:
# vi /etc/sysconfig/network
Append/modify configuration as follows:
NETWORKING=yes
HOSTNAME=www1.nixcraft.in
GATEWAY=192.168.1.254

Save and close the file. Restart networking:
# /etc/init.d/network restart

Make sure you have correct DNS server defined in /etc/resolv.conf file:
# vi /etc/resolv.conf
Setup DNS Server as follows:
nameserver 10.0.80.11
nameserver 10.0.80.12
nameserver 202.67.222.222

Save and close the file. Now you can ping the gateway/other hosts:
$ ping 192.168.1.252

ref : http://www.cyberciti.biz/faq/rhel-centos-fedoracore-linux-network-card-configuration/

July 22nd, 2008

Introduction

As an operating system that has gained a strong market share in the server environment, firewall applications have always been important to Linux, and Linux kernels have had packet filtering since the 1.1 series.

In 1994, Alan Cox created ipfwadm, the first firewall for Linux, which was based on ipfw from BSD and was enhanced for Linux 2.0. BSD has a reputation for conservative development and is still using ipfw many years later while Linux is now on to its second replacement. The second generation, ipchains, was introduced to Linux 2.2 in 1998, and iptables took its place during 1999, in the 2.4 kernel series.

iptables is included by default in all Linux distributions and is a sophisticated, stateful firewall which can be used on workstations and servers alike. It is far more powerful than Windows XP’s ICF, and (in my opinion) more powerful than BSD / OS X’s ipfw, though it is less user friendly than both.

Network ports used by common traffic

  • SSH - TCP 22
  • SMTP - UDP & TCP 25
  • DNS - UDP & TCP 53
  • DHCP - UDP 57
  • HTTP - TCP 80
  • Kerberos - UDP & TCP 88
  • POP3 - TCP 110
  • SMB - UDP 137:138 &TCP 139,445
  • IMAP - TCP 143
  • LDAP - UDP & TCP 389
  • HTTPS - TCP 443
  • LPD - UDP & TCP 515
  • AFP - UDP & TCP 548
  • CUPS - UDP & TCP 631
  • LDAP / SSL - UDP & TCP 636
  • IMAP / SSL - TCP 993
  • POP3 / SSL - TCP 995

iptables command

The syntax of the iptables command is:

iptables [command-type] [pattern-match-options] -j [target]

command-type

Can include

  • L - List rules in all chains
  • -F [chain] - Flush all rules from [chain]
  • -P [chain] - Set policy for [chain]. The policy can be “ACCEPT” or “DROP” (or “FORWARD” but we will not cover IP masquerading)
  • -A [chain] - Append a rule to [chain].
  • -D [chain] [rulenum] - Delete rule [rulenum] from chain [chain]
  • -N [chain] - Create a new chain with name [chain]

pattern-match-options

Source, destination, port, rate

Can include:

  • -p [protocol] - Where protocol is tcp, udp or icmp
  • -d [address / mask], -s [address / mask] - Specifies the destination / source name or address of the packet
  • –dport [port], –sport [port] - The destination / source port (can also be designated by protocol)
  • -i [interface], -o [interface] - Specifies which input / output interface the rule applies to ( eth0 , ppp0 )
  • -m state –state state_type - Where state_type can be NEW, ESTABLISHED, RELATED (such as an ICMP error message) or INVALID
  • –icmp-type [typename] - Allows specification of the ICMP type, which can be a numeric ICMP type, or one of the ICMP type names

Note that most of these patterns can include ! as a negation.

target

iptables has a number of different actions which can be applied to packets matching a particular rule:

  • DROP - silently drop packet without acknowledgement and terminate processing
  • REJECT - reject packet, send ICMP “Port unreachable” message and terminate processing
  • ACCEPT - accept packet and terminate processing
  • FORWARD - forward packet using Network Address Translation (NAT) and terminate processing (we will not cover this)
  • LOG - log at kernel level at “warn” level priority and continue to next chain

Examples

These examples can be cut and pasted directly in to the /etc/sysconfig/iptables file and loaded with service iptables restart. Feel free to use them and edit as you see fit.

The first example below is for a web and file server connected via a single ethernet device. Inbound FTP, SSH, HTTP, HTTPS, SMB, AFP and established connections are allowed while outbound connections are not restricted.

*filter
# Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn’t use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT

# Accept all established connections
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

# Allow all outbound traffic
-A OUTPUT -j ACCEPT

# Accept all SSH and Web server connections
-A INPUT -p tcp –dport 22 -j ACCEPT
-A INPUT -p tcp –dport 80 -j ACCEPT
-A INPUT -p tcp –dport 443 -j ACCEPT

# Samba (accept connections from 128.250.)
-A INPUT -p udp -s 128.250.0.0/16 –dport 137:138 -j ACCEPT
-A INPUT -p tcp -s 128.250.0.0/16 –dport 139 -j ACCEPT
-A INPUT -p tcp -s 128.250.0.0/16 –dport 445 -j ACCEPT

# AFP (accept connections from 128.250.)
-A INPUT -p udp -s 128.250.0.0/16 –dport 548 -j ACCEPT
-A INPUT -p tcp -s 128.250.0.0/16 –dport 548 -j ACCEPT

# Reject and log all other inbound
-A INPUT -j LOG
-A INPUT -j REJECT
-A FORWARD -j LOG
-A FORWARD -j REJECT

The second example is for an email server connected via dual ethernet devices. The server allows inbound connections for SSH, SMTP, POP3, IMAP, POP3 via SSL, IMAP via SSL and established traffic. Outbound connections are not restricted.

*filter

# Allow all loopback (lo0) traffic
# Drop all traffic to 127/8 that doesn’t use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT

# Accept all established connections
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

# Accept inbound SSH connections
-A INPUT -p tcp –dport 22 -j ACCEPT

# Allow inbound access to smtp via first ethernet device
-A INPUT -p tcp –dport smtp -i eth0 -j ACCEPT

# Allow access to other mail services via second ethernet device
-A INPUT -p tcp –dport pop3 -i eth1 -j ACCEPT
-A INPUT -p tcp –dport imap -i eth1 -j ACCEPT
-A INPUT -p tcp –dport pop3s -i eth1 -j ACCEPT
-A INPUT -p tcp –dport imap2 -i eth1 -j ACCEPT

# Allow all outbound traffic
-A OUTPUT -j ACCEPT

# Reject and log all other inbound
-A INPUT -j LOG
-A INPUT -j REJECT
-A FORWARD -j LOG
-A FORWARD -j REJECT

COMMIT

ref :: http://linux.unimelb.edu.au/server/course/fc3/iptables.html

July 22nd, 2008

#vipw
Edit or no Edit path of Home directory & save

#vi /usr/local/etc/proftpd.conf
find line :
[…]
#DefaultRoot ~
[…]
uncomment # to
[…]
DefaultRoot ~
[…]
save file

Restart FTP deamon

/usr/local/etc/rc.d/proftpd retstart

July 22nd, 2008

If you forgot you password for your ubuntu system you can recover using the following stepsTurn your computer on.

Press ESC at the grub prompt.

Press e for edit.

Highlight the line that begins kernel ………, press e

Go to the very end of the line, add rw init=/bin/bash

press enter, then press b to boot your system.

Your system will boot up to a passwordless root shell.

Type in passwd username

Set your password.

Type in reboot

ref : http://www.ubuntugeek.com/how-to-recover-password-under-ubuntu.html

July 22nd, 2008

Some time you might find some applications are having only .rpm files but you want a .deb package for your debian,Ubuntu and other debian derived ditributions.If you can’t find .deb debian package in any of the debian,ubuntu repositories or elsewhere, you can use the alien package converter to install the .rpm file.Alien is a program that converts between the rpm, dpkg, stampede slp, and slackware tgz file formats. If you want to use a package from another distribution than the one you have installed on your system, you can use alien to convert it to your preferred package format and install it.

Despite the large version number, alien is still (and will probably always be) rather experimental software. It has been used by many people for many years, but there are still many bugs and limitations.

Alien should not be used to replace important system packages, like sysvinit, shared libraries, or other things that are essential for the functioning of your system. Many of these packages are set up differently by Debian and Red Hat, and packages from the different distributions cannot be used interchangably. In general, if you can’t uninstall the package without breaking your system, don’t try to replace it with an alien version.

Install alien in Ubuntu

sudo apt-get install alien

This will install all the required packages.Now you can start converting your .rpm files to .deb packages.

Available Options for alien

Convert the package.rpm into a package.deb

sudo alien -d package-name.rpm

Convert the package.rpm into a package.deb, and install the generated package.

sudo alien -i package-name.rpm

If you want to keeps alien from changing the version number use the following command

sudo alien -k rpm-package-file.rpm

Example

Suppose we have a avg antivirus avg71lms-r30-a0782.i386.rpm file

To convert .rpm to debian

sudo alien -k avg71lms-r30-a0782.i386.rpm

Now you should be having avg71lms-r30-a0782.i386.deb file

To install .deb file

sudo dpkg -i avg71lms-r30-a0782.i386.deb

If you don’t use -k option you should see avg71lms_r30-1_i386.deb file the difference is it will add 1

If you want more available options for alien check alien man page

ref : http://www.ubuntugeek.com/install-rpm-files-in-ubuntu.html