Tipsheet

Tips and tricks...

logging php errors on godaddy hosting

Godaddys' linux hosting allows for editing your own "php.ini" file and enables support for logging errors, good for debugging purposes when developing with php.

Add the below lines to php.ini in the document root, to log all errors:

error_reporting  =  E_ALL
log_errors = on
error_log = /home/content/p/a/t/pathto/html/error_log

You should also protect the php.ini and error_log file via .htaccess:

<FilesMatch "(error_log|php\.ini)$">
  Order deny,allow
  Deny from all
</FilesMatch>

tar with Extended Attributes/xattrs support in RedHat 5

If using earlier versions, use "star" to backup and restore files with extended attributes. SELinux and ACLs use these Extended Attributes to store the security contexts and access control lists respectively.

Tar has now been rebuilt in RedHat 5 and added support for Extended Attributes.

--selinux Archive the SELinux attributes of the files and directories
--acls Archive the ACL attributes of files and directories
--xattrs Archive all Extended Attributes of files and directories.
This includes both SELinux and ACL attributes, as well as any other xattr.

Finding setuid and setgid files

setuid files when executed inherit the permissions of the owner of the file. So having files with setuid of root is a bad idea.

Here's how to find it and unset it.

Note:
There are some system files like at and crontab that have these bits set and is required for it to run.

# find / -perm +6000 -type f -exec ls -ld {}\; > setuid.txt &

To unset it:

# chmod a-s <file>

`yum update kernel` without removing old kernels

Edit "/etc/yum/pluginconf.d/installonlyn.conf" and change the enabled to "0" or increase the "tokeep" value to the number of versions you want to keep.

[main]
enabled=1
# this sets the number of package versions which are kept
tokeep=2

Hosting multiple domains pointed to the same web-space

Place the snippet of code in an index.php file to pull up a different web page for each domain pointed to the same web-space.

<?
$serverName = $HTTP_HOST;
$serverName = str_replace("www.","",$serverName);
$serverName = str_replace(".com","",$serverName);
$serverName = str_replace(".net","",$serverName);
$serverName = str_replace(".org","",$serverName);
if (!(empty($serverName))) {
   include("./".$serverName.".html");
}
?>

masquerade with iptables

Allows for easy sharing of internet connection to an internal network with dynamic IP range.

# iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE

Sending mail to a SMTP server using telnet

$ telnet remotehost 25
HELO localhost
MAIL FROM: johndoe@localhost
RCPT TO: jilldoe@remotehost
DATA
Subject:Test Message
This is a test message.
.
QUIT

RAID notes...

  1. Create RAID-1 level array with 2 active devices and 1 spare:
    # mdadm -C /dev/md0 -l 1 -n 2 /dev/hda{8,9} -x 1 /dev/hda10

    Note: RAID-1 provides for redundancy and needs a minimum of 2 partitions and any number of spares.

  2. Show details:
    # mdadm --detail /dev/md0
  3. Mark Faulty:
    # mdadm --manage /dev/md0 -f /dev/hda8

    Note: When partition is marked faulty, the spare quickly replaces it in RAID 1 array.

  4. Remove:
    # mdadm --manage /dev/md0 -r /dev/hda8

    Note: Only faulty partitions can be removed.

  5. Add:
    # mdadm --manage /dev/md0 -a /dev/hda8

    Note: Only removed partitions can be added.

  6. Stop RAID:
    # mdadm --stop /dev/md0
  7. Run RAID:
    # mdadm --assemble /dev/md0 /dev/hda{8,9,10}

    Note: Before assembling, check on the UUID of the devices. They should all be the same and show only one array:

    mdadm --examine --scan /dev/hda{8,9,10}

  8. Remove the md signature from disk
    # mdadm --zero-superblock /dev/hda{8,9,10}
  9. Scan md superblock
    # mdadm --examine --scan
  10. Scan currently active arrays
    mdadm --detail --scan
  11. Monitor RAID:
    # nohup mdadm --monitor --mail=root --delay=300 /dev/md0 &

Converting bin/cue to iso format

You might come across a disc image in the BIN/CUE format. BIN/CUE files can be directly burned to CD via K3B, however if you want to convert to an iso, a command line application called bchunk can be used.

# yum --enablerepo=extras install bchunk
# bchunk image.bin image.cue image.iso

Enabling quotas for users

Check to make sure the quota package is installed, else run:

# yum install quota


Edit "/etc/fstab" and add "usrquota,grpquota" to the / partition:

LABEL=/    /    ext3    defaults,usrquota,grpquota    1 1


Then run:

# mount -o remount /
# quotacheck -avugm
# quotaon -avugm


To check quotas for all users:
# repquota -a


To edit quota for a particular user:
# edquota -u <user>


Alternately use setquota:
# setquota <softlimit> <hardlimit> 0 0 <user>

Syndicate content
Comment