Wednesday, 2 September 2009

PHP Warning: Unknown: POST Content-Length of 28 bytes exceeds the limit of -2147483648 bytes in Unknown on line 0

If you are noticing the above error in apache error logs and having problems for login scripts the problem is with post_max_size variable in php.ini

Here is what you need to do, Find out the correct php.ini configuration file.

root@server [/usr]# php -i | grep php.ini

Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

Edit the loaded php.ini file and check for post_max_size variable value, Set it to 8M which is best recommended.

root@server [/usr]# grep post_max /usr/local/lib/php.ini

post_max_size = 8M

Then restart apache, That should resolve the problem.

How do I enable SMTP authentication?

You may find that you cannot relay mail because you have not enabled SMTP authentication in your e-mail client. The steps you use to resolve this problem depends on the mail client you utilise. A few commonly used mail clients are Outlook Express and Microsoft Outlook 2003:

Outlook Express: click Tools > Accounts > Under the "mail" tab select an email account > properties > Select the "Servers" tab > Under "My server requires authentication" simply tick this (You may use the same settings as your incoming mail server, pop3).

Microsoft Outlook 2003: click Tools > Email Accounts > Select "View or change existing email accounts...", click Next > Select your email account > Click "Change" > More settings > Under the "Outgoing Server" tab tick "My outgoing server requires authentication".


Microsoft Outlook 2007:

1. Select the 'Tools' menu and click 'Account settings'
2. Select the account you wish to enable authentication on and click 'Change'
3. Select the 'more settings' button
4. Select the 'Out going Server' tab
5. Place a check in the box labelled 'My outgoing server requires authentication' and the box that's labelled 'Log on to incoming mail server before sending'
6. Click 'OK'
7. Click 'Next'
8. Click 'Finish'


Mac Mail:

  1. Open Mac OS X Mail.

  2. From the Mail menu, choose Preferences.

  3. Click the Accounts icon.

  4. Click the Account Information tab.

  5. From Outgoing Mail Server (SMTP), mail.yourdomainname

  6. Click the Server Settings….

  7. Select Password from the Authentication drop-down box.

  8. Type your email ID in the User Name: field.

  9. Click OK.

  10. Close the Accounts window.

  11. Click Save to save the changes that you made.

Tuesday, 1 September 2009

Shell script to restart MySQL server if it is killed or not working

#!/bin/bash
# Shell script to restart MySQL server if it is killed or not working
# due to ANY causes.
# When script detects mysql is not running (it basically sends ping request
# to MySQL) it try to start using /etc/init.d/mysql script; and it sends an
# email to user indicating the status.
# This script must be run from Cron Job so that it can monitor mysql server.
# For more info visit following url:
# http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/08/linux-mysql-server-monitoring.html
# --------------------------------------------------------------------------
# Copyright (C) 2005 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------

# mysql root/admin username
MUSER="root"
# mysql admin/root password
MPASS="SET-ROOT-PASSWORD"
# mysql server hostname
MHOST="localhost"
#Shell script to start MySQL server i.e. path to MySQL daemon start/stop script.
# Debain uses following script, need to setup this according to your UNIX/Linux/BSD OS.
MSTART="/etc/init.d/mysql start"
# Email ID to send notification
EMAILID="notification@somewhere-corp.com"
# path to mail program
MAILCMD="$(which mail)"
# path mysqladmin
MADMIN="$(which mysqladmin)"

#### DO NOT CHANGE anything BELOW ####
MAILMESSAGE="/tmp/mysql.fail.$$"

# see if MySQL server is alive or not
# 2&1 could be better but i would like to keep it simple and easy to
# understand stuff :)
$MADMIN -h $MHOST -u $MUSER -p${MPASS} ping 2>/dev/null 1>/dev/null
if [ $? -ne 0 ]; then
echo "" >$MAILMESSAGE
echo "Error: MySQL Server is not running/responding ping request">>$MAILMESSAGE
echo "Hostname: $(hostname)" >>$MAILMESSAGE
echo "Date & Time: $(date)" >>$MAILMESSAGE
# try to start mysql
$MSTART>/dev/null
# see if it is started or not
o=$(ps cax | grep -c ' mysqld$')
if [ $o -eq 1 ]; then
sMess="MySQL Server MySQL server successfully restarted"
else
sMess="MySQL server FAILED to restart"
fi
# Email status too
echo "Current Status: $sMess" >>$MAILMESSAGE
echo "" >>$MAILMESSAGE
echo "*** This email generated by $(basename $0) shell script ***" >>$MAILMESSAGE
echo "*** Please don't reply this email, this is just notification email ***" >>$MAILMESSAGE
# send email
$MAILCMD -s "MySQL server" $EMAILID < $MAILMESSAGE
else # MySQL is running :) and do nothing
:
fi
# remove file
rm -f $MAILMESSAGE

How to resolve multiple problems due to permission issues

Sometimes, permissions might get screwed server wide resulting in various problems for different users.

Here are some steps to reset the permissions.

/scripts/checkbsdgroups — Checks and repairs proftpd ownership on FreeBSD.
/scripts/chownpublichtmls — Change ownership of all users web space to them, which is useful for converting to suexec. Files owned by nobody are deleted.

Then, login to WHM as ‘root’ and go to Whm >> Resellers >> Reseller Center >> Reset Resellers

Select all Resellers under Reset package permissions to default and click the reset button.

Assuming that you have an ACL with the default permissions, select all Resellers under ‘Apply an ACL list to multiple resellers >> Select the appropriate ACL list >> Apply.

Also, it is advised to run the following :

/scripts/fixeverything/
/scripts/upcp –force

service httpd restart
service named restart

How to Install X-cache

This is another one of my quick mini-guides for how to install Xcache php optimizer. We have found this to work very nicely on servers and can even work with zend and eaccelerator if you require both. We have found no stability issues with 1.2.1 and run it on several very large and important servers.

Download the source and start to compile:

# cd /usr/local/src/
# wget
http://xcache.lighttpd.net/pub/Releases/1.2.1/xcache-1.2.1.tar.gz
# tar -zxf xcache-1.2.1.tar.gz
# cd xcache-1.2.1


Next we have to run phpize, if it is not in a standard location you will need to do the full path. The configure may also require additional options if your php-config binary is not on the bin path.

# phpize
# ./configure


# make

# make install

ln -s /usr/local/lib/php/extensions/no-debug-non-zts-20020429/xcache.so /usr/local/php5//lib/php/extensions/no-debug-non-zts-20060613/xcache.so

Note The above sym-links the xcache.so to the php5.2.3 install, if you are unsure of the best place to put it run php -i |grep extension_dir and you will get something like this:

# php -i |grep extension_dir
extension_dir => /usr/local/php5//lib/php/extensions/no-debug-non-zts-20060613


You would then want to link the xcache.so into the /usr/local/php5//lib/php/extensions/no-debug-non-zts-20060613 directory as was done above. Finally you need to paste the rest into the php.ini. If you are unsure of where it is run “php -i |grep php.ini” . NOTE the admin user and password, you obviously need to change that.

[xcache-common]

extension = xcache.so

[xcache.admin]
xcache.admin.auth = On
xcache.admin.user = “eth00?
xcache.admin.pass = “some-password”


[xcache]
; ini only settings, all the values here is default unless explained


; select low level shm/allocator scheme implemenation
xcache.shm_scheme = “mmap”


; to disable: xcache.size=0
; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows
xcache.size = 0M


; set to cpu count (cat /proc/cpuinfo |grep -c processor)
xcache.count = 1


; just a hash hints, you can always store count(items) > slots
xcache.slots = 8K


; ttl of the cache item, 0=forever
xcache.ttl = 0


; interval of gc scanning expired items, 0=no scan, other values is in seconds
xcache.gc_interval = 0


; same as aboves but for variable cache
xcache.var_size = 0M
xcache.var_count = 1
xcache.var_slots = 8K
; default ttl
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300


xcache.test = Off
; N/A for /dev/zero
xcache.readonly_protection = Off
; for *nix, xcache.mmap_path is a file path, not directory.
; Use something like “/tmp/xcache” if you want to turn on ReadonlyProtection
; 2 group of php won’t share the same /tmp/xcache
; for win32, xcache.mmap_path=anonymous map name, not file path
xcache.mmap_path = “/dev/zero”


; leave it blank(disabled) or “/tmp/phpcore/”
; make sure it’s writable by php (without checking open_basedir)
xcache.coredump_directory = “”


; per request settings
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off


[xcache.coverager]
; per request settings
; enable coverage data collecting for xcache.coveragedump_directory and xcache_coverager_start/stop/get/clean() functions (will hurt executing performance)
xcache.coverager = Off


; ini only settings
; make sure it’s readable (care open_basedir) by coverage viewer script
; requires xcache.coverager=On
xcache.coveragedump_director
y = “”

Plesk error: Unable to open logs


While restarting  apache we face the following error in/var/log/httpd/error_log unable to open logs


You need to just fire the below commands and it done:


# echo $ulimit


If it is blank or a low value, try executing the command


# ulimit -n 65536


This is should fix the issue and apache should be working fine.



How to install Plesk license

To install the Plesk License you can use  License Manager function available in the Plesk administrator control panel >>> Server >>> License Management >>> Upload license.

That's all you have to do.