Archive for the ‘VPS’ Category

How to Send Email from a PHP Script

Saturday, January 12th, 2008

Using php mail() function to send emails from php script.

Send Email from a PHP Script Example :

The first argument to this function is the recipient, the second specifies the message’s subject and the third one should contain the body. So to send a simple sample message, we could use:

$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("

Message successfully sent!

“);
} else {
echo(”

Message delivery failed…

“);
}
?>

Save this file as mail.php and browse from url http://yourdomain/mail.php

what ports are listening on my server?

Sunday, July 29th, 2007

You can use this commands –

lsof -i

Or

netstat –listen

Timeout error occurred trying to start MySQL Daemon.

Friday, May 18th, 2007

I came across mysql error — “Timeout error occurred trying to start MySQL Daemon.”

Mysql will not restart —

[root@vps init.d]# ./mysqld restart
Stopping MySQL: [FAILED]
Timeout error occurred trying to start MySQL Daemon.
Starting MySQL: [FAILED]

Server Details :
Linux VPS — Plesk Installed.
Mysql Version : 4.1

——

Solution : Add this line in /etc/my.cnf

skip-innodb under socket=/var/lib/mysql/mysql.sock

vi /etc/my.cnf
——–

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-innodb
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
———

Thanks,
Sachin
ThinkSupport.net

CGI is down on the server!

Saturday, May 12th, 2007

First check the Apache error logs.

—————————————————
[Sat Mar 31 21:24:19 2007] [error] [client 65.254.32.50] Premature end of script headers: /home/youngerb/public_html/cgi-bin/at3/admin.cgi
admin.cgi: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory
[Sat Mar 31 21:24:29 2007] [error] [client 59.95.36.168] Premature end of script headers: /home/youngerb/public_html/cgi-bin/at3/admin.cgi
—————————————————

It seems shared libraries libstdc++.so.5 is missing or courrpted on the server.

Just do this

yum install compat-lib*

Windows Memory Test tool

Sunday, April 29th, 2007

Windows Memory test tool –

AleGr-MEMTEST-Download

Cheers..

cgi files generate Internal Server Error

Sunday, April 22nd, 2007

This means that the cgi script did not execute properly. There are several causes that can generate this error so a few things would need to be checked.

1) check the /var/log/httpd/suexec_log. It contains any errors that would be as a result of not having correct permissions on the file. The file needs to be in a cgi-bin and must have the owner/group as the username who owns the site. If it’s owned by anyone else, it will not run. Also, the script must have execute permission. The most common chmod permission is 755. Go through all directories from the public_html down to the directory the script is in, and make sure they’re all set to 755 (public_html can be 750 *only* if it has a group of apache).

If the suexec_log only shows the script being run, then the cause may be with the script code itself. The easiest way to figure out script coding problems is to first run the script manually from an ssh prompt.

cd /home/username/domains/domain.com/public_html/cgi-bin
./script.cgi
One common error is to use an incorrect interpreter. The 2 most common interpreters are:

#!/usr/bin/perl
and

#!/usr/local/bin/php
This code must appear on the first line of the script. Somtimes a file is uploaded in windows format so the trailing newline (return) character is formed incorrectly and the file would need to be reuploaded in a different format.

Other errors that would be generated when running the script manually from ssh would be missing perl modules, in which case you’ll need to install them yourself. Cpan is the easiest method to install new perl modules, eg:

perl -e shell -MCPAN
install Bundle::DBD::mysql

Increase the max upload filesize in apache/php

Sunday, April 22nd, 2007

edit: php.ini file on server

You can locate php.ini file using — php -i | grep php.ini

/usr/local/lib/php.ini

Search for

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
Change the 2M to whatever new value you want, then restart apache.

Running CGI script from any directory or via /~username/cgi-bin

Sunday, April 22nd, 2007

In order to force apache to allow cgi script to run, simply create a file called .htaccess inside the directory in which you wish to run the scripts. Inser this text into the file:

Options +ExecCGI
AddHandler cgi-script .cgi .pl

Installing Ioncube Loaders on your server..

Saturday, April 21st, 2007

You WILL require root access to the server in order to do this.

1. Download the latest loaders to your computer from http://www.ioncube.com/loaders.php and upload them to your webspace
2. Move the ioncube folder to a permanent location by entering:
mv ioncube /usr/local
3. Next, you need to locate the php.ini file, to do this enter:
locate php.ini
4. You should find it is in /usr/local/lib/php.ini. Now that you know the location of php.ini you need to edit it.
pico /usr/local/lib/php.ini
5. Now find where other zend extentions are in the file.
ctrl + w: zend_extension
6. Paste in your new line for ioncube loader
zend_extension = /usr/local/ioncube/ioncube_loader_lin_x.so (Replace x with your version of PHP eg. 4.4)
7. Save the changes
ctrl + X then Y and enter
8. Restart the web server to take effect.
/etc/init.d/httpd restart

That’s it! Ioncube is now installed on your server! You should now see a section in your PHP Info page that says:

Additional Modules
Module Name ionCube Loader

Simple Commad to detect DOSS attack

Thursday, April 19th, 2007

Try this command as one of the method to check if your server is under doss attack

netstat -anp |grep ‘tcp\|udp’ | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n

You can block ips using apf -d ipnumber