Wednesday, March 28, 2012

Procedure To Add a Swap File

You need to use the dd command to create swap file. The mkswap command is used to set up a Linux swap area on a device or in a file.

a) Login as the root user.

b) Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):
# dd if=/dev/zero of=/swapfile1 bs=1024 count=524288

c) Set up a Linux swap area:
# mkswap /swapfile1

d) Activate /swapfile1 swap space immediately:
# swapon /swapfile1

e) To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using a text editor such as vi:
# vi /etc/fstab

Append the following line:
/swapfile1 swap swap defaults 0 0

So next time Linux comes up after reboot, it enables the new swap file for you automatically.

g) How do I verify swap is activated or not?
Simply use the free command:
$ free -m

* How to replace Apache with Lighttpd on Cpanel

Lighttpd is another free webserver that is becoming more popular due to it's performance boosts over Apache and thus improving the overall server performance. This guide will show you how it's possible to replace Apache with Lighttpd while running CPanel.

Things to do prior to making the switch:

1. Make sure to recompile Apache with fastcgi support. This can be done via WHM --> Apache Configuration.
2. This setup is better for servers with a few large sites than a host with many smaller sites as a Shared host would have. If Apache is working fine, there is no need to do this.
3. If you need to have sites with SSL enabled, it will be a little trickier and will not be covered in this how-to. You can reference this link for more details:
http://redmine.lighttpd.net/wiki/1/DocsSL
4. When creating accounts after making the switch to Lighttpd, you will still use the Create Account feature, but since httpd will not be running, you will have to manually add the virtual host details to the lighttpd.conf file or hosts.conf as we will have in this example.

Step 1

Download and compile Lighttpd:

1. First get the source from www.lighttpd.net and follow the instructions there.
2. To configure: ./configure --with-openssl --with-zlib --with-bzip2 --with-memcache
NOTE: may need to install pcre-devel (yum install pcre-devel)
3. Follow the instructions here to get lighttpd configured after the install: http://redmine.lighttpd.net/projects...tallFromSource You may need to change the path in /etc/init.d/lighttpd file to /usr/local/sbin/lighttpd for it to start.
4. Configure the lighttpd.conf file in /etc/lighttpd/. Example of a working lighttpd.conf:
Code:

server.modules = ( "mod_fastcgi", "mod_rewrite", "mod_dirlisting", "mod_auth", "mod_setenv", "mod_status" )
server.document-root = "/usr/local/apache/htdocs"
server.errorlog = "/etc/lighttpd/error.log"
server.username = "nobody"
server.groupname = "nobody"
index-file.names = ( "index.html", "index.htm", "index.php" )
server.tag = "Web Services"
status.status-url = "/lighttpd-status"
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
server.port = 80
include "includes/mime.conf"
include "includes/optimizations.conf"
include "includes/php.conf"
include "includes/hosts.conf"

You can get the server.document-root from the existing httpd.conf file for Apache for the main VirtualHost.
5. In the /etc/lighttpd directory, create the includes directory:
Code:

mkdir includes

and create the mime.conf, optimizations.conf, php.conf and hosts.conf files in the includes directory. Chmod them to 644:
Code:

chmod -R 644 includes

run this command within the /etc/lighttpd directory.
6. Now we need to populate the created conf files that lighttpd will load upon startup.

mime.conf:
Code:

mimetype.assign = (
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "application/ogg",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".cpp" => "text/plain",
".log" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar",
"" => "application/octet-stream"
)

optimizations.conf:
Code:

server.event-handler = "linux-sysepoll"
server.max-fds = 32768
server.network-backend = "linux-sendfile"
server.max-connections = 8192
server.max-keep-alive-requests = 15
server.max-keep-alive-idle = 15
server.max-read-idle = 15
server.max-write-idle = 15
server.max-worker = 1

The 'server.max-worker' variable should be changed according to how many CPUs the server has, and if it's a 64bit system. If it's a 32bit system, and the load stays low, keep it at 1. To get rid of keep-alive, set both of the keep-alive lines to 0. Max connections can be alterted to your needs

php.conf:
Code:

fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket-" + var.PID,
"bin-path" => "/usr/bin/php-cgi",
"max-procs" => 20,
"idle-timeout" => 10,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "20",
"PHP_FCGI_MAX_REQUESTS" => "500" ),
)
)
)

To get the bin-path, just run
Code:

whereis php-cgi

and that will show you the path. You have to compile Apache with fastcgi support first via WHM as mentioned previously. PHP can run as DSO/CLI still via WHM.

hosts.conf:
Code:

$HTTP["host"] =~ "^(www\.|)domain\.com$" {
server.document-root = "/home/domain/public_html/"
}

$HTTP["host"] =~ "^(www\.|)domain2\.com$" {
server.document-root = "/home/domain2/public_html/"
}

Adjust this file to your needs. Look at your Apache's httpd.conf file and setup each vhost using the above templates for each domain/subdomain you have in httpd.conf. If you wish to add logs to each domain, you can add the following lines to each one of the vhosts above between the {} brackets:
Code:

server.errorlog = "/var/log/lighttpd/domain/error.log"
accesslog.filename = "/var/log/lighttpd/domain/access.log"
server.error-handler-404= "/e404.php"

Now you should be all done with the main lighttpd configuration, so go ahead and turn it on:
Code:

/etc/init.d/lighttpd start

7. Now we need to turn off Apache so it does not start on boot or start by Cpanel. To do this, login to WHM and go to Service Manager, then uncheck both of the boxes for httpd. You can also run the following command to turn it off via shell:
Code:

chkconfig httpd off

This will ensure Apache won't start.

At this point, you should be running completely on lighttpd. Everything else in Cpanel/WHM will work as usual (mysql, dns, email, etc..). If you need to recompile php, you can do so via Apache Configuration, just be sure to turn off Apache again after you recompile.

source: http://forums.ayksolutions.com/showthread.php?p=829

How to backup your linux VPS.

Backup script for vps

#!/bin/sh
####################################
#
# Backup to NFS mount script.
#
####################################

# What to backup.
backup_files="/"

# Where to backup to.
dest="/home/backup"

# Create archive filename.
day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"

# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo

# Backup the files using tar.
tar czf $dest/$archive_file $backup_files

# Print end status message.
echo
echo "Backup finished"
date

# Long listing of files in $dest to check file sizes.
ls -lh $dest

Wednesday, March 14, 2012

enable php function

1. Remove all functions from disable_functions in php.ini
2. Add functions in php.ini suhosin.executor.func.blacklist = “” those you want to disable globally.

After that in the virtual host section of a domain you can add below code to enable a function only for one domain:


………..

php_admin_value suhosin.executor.func.blacklist = “shell_exec”

……


In this example shell_exec has been enabled for the VirtualHost.

PS:virtual host settings will work only if suhosin is installed in the server

Thursday, March 8, 2012

Install nginx

Login to SSH and do this

cd /usr/local/src
wget http://nginxcp.com/latest/nginxadmin.tar
tar xf nginxadmin.tar
cd publicnginx
./pythonfix
./nginxinstaller install

It's Done...... Now go to WHM and search for nginx, You will see it there

are you getting "502 Bad Gateway" error ?

here is the solution

go to WHM and search for "tweak settings"

open it and search for "Apache non-SSL" and set it to "0.0.0.0:8081"

mass upload bash script (good for Megaupload)

#!/bin/bash

ftp -inv << FTP
open ftp.eu.filesonic.com
user USERNAME PASSWORD
lcd /YOUR/FOLDER/WITH/FILES
mput *.zip
bye
FTP

Wednesday, March 7, 2012

GRUB Commands

GRUB has a powerful command line option. All you have to do to start the command line is to use the command grub.



You can see a list of the possible commands by using the help.

PHP Code:
grub> help
blocklist FILE boot
cat FILE chainloader [--force] FILE
clear color NORMAL [HIGHLIGHT]
configfile FILE device DRIVE DEVICE
displayapm displaymem
find FILENAME geometry DRIVE [CYLINDER HEAD SECTOR [
halt [--no-apm] help [--all] [PATTERN ...]
hide PARTITION initrd FILE [ARG ...]
kernel [--no-mem-option] [--type=TYPE] makeactive
map TO_DRIVE FROM_DRIVE md5crypt
module FILE [ARG ...] modulenounzip FILE [ARG ...]
pager [FLAG] partnew PART TYPE START LEN
parttype PART TYPE quit
reboot root [DEVICE [HDBIAS]]
rootnoverify [DEVICE [HDBIAS]] serial [--unit=UNIT] [--port=PORT] [--
setkey [TO_KEY FROM_KEY] setup [--prefix=DIR] [--stage2=STAGE2_
terminal [--dumb] [--no-echo] [--no-ed terminfo [--name=NAME --cursor-address
testvbe MODE unhide PARTITION
uppermem KBYTES vbeprobe [MODE]



The displaymem command will show you what GRUB thinks is the system address space map of the machine. The lower memory is the address space in the first megabyte of memory.

PHP Code:
grub> displaymem
EISA Memory BIOS Interface is present
Address Map BIOS Interface is present
Lower memory: 640K, Upper memory (to first chipset hole): 3072K
[Address Range Descriptor entries immediately follow (values are 64-bit)]
Usable RAM: Base Address: 0x0 X 4GB + 0x0,
Length: 0x0 X 4GB + 0xa0000 bytes
Reserved: Base Address: 0x0 X 4GB + 0xa0000,
Length: 0x0 X 4GB + 0x60000 bytes
Usable RAM: Base Address: 0x0 X 4GB + 0x100000,
Length: 0x0 X 4GB + 0x300000 bytes




PHP Code:
grub> find /sbin/init
(hd0,1)


enter find ( and then tab

PHP Code:
grub> find (hd0,


Use the tab
PHP Code:
grub> find (hd0,
Possible partitions are:
Partition num: 0, Filesystem type is ext2fs, partition type 0x83
Partition num: 1, Filesystem type is ext2fs, partition type 0x83
Partition num: 2, Filesystem type is ext2fs, partition type 0x83
Partition num: 4, Filesystem type unknown, partition type 0x8e
Partition num: 5, Filesystem type unknown, partition type 0x8e

Disk /dev/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 523 4096575 83 Linux
/dev/hda3 524 650 1020127+ 83 Linux
/dev/hda4 651 1044 3164805 5 Extended
/dev/hda5 651 663 104391 8e Linux LVM
/dev/hda6 664 676 104391 8e Linux LVM

grub> find /grub/menu.lst
(hd0,0)



PHP Code:
grub> find /sbin/init
(hd0,1)