Archive for the ‘Linux’ Category

Apache - Address already in use: make_sock: could not bind to address

Tuesday, August 19th, 2008

This error message can be caused by an improper shut down, the apache processes are still hanging around and apachectl restart won’t work.

Solution

just kill off the hanging processes:
# fuser 80/tcp
80/tcp: 3010 3702 4088 16754
# kill -n 9 3010
# kill -n 9 3702
# kill -n 9 4088
# kill -n 9 16754
# apachectl start

or if there’s loads of processes use
# for i in $(fuser 80/tcp);do kill -n 9 $i;done
to kill them all off

How to fix (rpmdb Lock table is out of available locker entries) error when trying to use RPM.

Tuesday, May 13th, 2008

If you are trying to use rpm or yum (which in turn calls RPM) and its showing a locker issues that looks something like this:

rpmdb: Lock table is out of available locker entries
error: db4 error(22) from db->close: Invalid argument
error: cannot open Packages index

or

rpmdb: Lock table is out of available locker entries
error: db4 error(22) from db->close: Invalid argument
error: cannot open Packages index using db3 - Cannot allocate memory (12)
error: cannot open Packages database in /var/lib/rpm

Solution :
Make a backup of /var/lib/rpm in case you break something:

tar cvzf rpmdb-backup.tar.gz /var/lib/rpm

Remove the Berkeley databases that rpm uses:

rm /var/lib/rpm/__db.00*

Make rpm rebuild the databases from scratch (may take a short while):

rpm –rebuilddb

Now, check rpm to make sure everything is okay:

rpm -qa | sort

Why does this happen?
When rpm accesses the Berkeley database files, it makes temporary locker entries within the tables while it searches for data. If you control-c your rpm processes often, this issue will occur much sooner because the locks are never cleared.

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

Plesk Linux server — Configure qmail to run on port 26.

Sunday, July 29th, 2007

Follow below steps to change smtp port on plesk server to 26.

>> cd /etc/xinetd.d
>> ls -l | grep smtp*
>> cat smtp_psa

service smtp
{
socket_type = stream
protocol = tcp
wait = no
disable = no
user = root
instances = UNLIMITED
server = /var/qmail/bin/tcp-env
server_args = /usr/sbin/rblsmtpd -r bl.spamcop.net /var/qmail/bin/relaylock /var/qmail/bin/qmail-smtpd /var/qmail/bin/smtp_auth /var/qmail/bin/true /var/qmail/bin/cmd5checkpw /var/qmail/bin/true
}

>> pico /etc/services

Add this line
smtp_psa_new 26/tcp mail
smtp_psa_new 26/udp mail

>> cp smtp_psa smtp_psa_new

Change the service line in the new file ’smtp_psa_new” to be this:

service smtp_psa_new
{
socket_type = stream
protocol = tcp
wait = no
disable = no
user = root
instances = UNLIMITED
server = /var/qmail/bin/tcp-env
server_args = /usr/sbin/rblsmtpd -r bl.spamcop.net /var/qmail/bin/relaylock /var/qmail/bin/qmail-smtpd /var/qmail/bin/smtp_auth /var/qmail/bin/true /var/qmail/bin/cmd5checkpw /var/qmail/bin/true
}

>> /etc/init.d/xinetd restart

And you should see smtp listening on ports 25, and 26:

>> netstat -anp | grep xinetd

tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6989/xinetd
tcp 0 0 0.0.0.0:26 0.0.0.0:* LISTEN 6989/xinetd

You are done ..

Plesk - How to access MySQL from the command line?

Sunday, July 29th, 2007

You can use this command on command prompt -

mysql -umysql_user -pmysqlpass

IonCube Error zend_hash_destroy

Wednesday, June 6th, 2007

If you come across error after installing ioncube

/home/username/public_html/ioncube/ioncube_loader_lin_5.2.so: undefined symbol: zend_hash_destroy in

Follow this –

This can occur if PHP is configured with the option
–enable-versioning
This option can prevent the export of global PHP API symbols, causing failure when attempting to link libraries such as the Loader or Zend Optimiser. PHP must be rebuilt without that option so that the PHP API is correctly visible. A phpinfo page should show at the top of the page what options were used to configure PHP, and should confirm that the option had been used.

Thanks

MySQL Quota Check Tool

Saturday, May 26th, 2007

I came across wonderfull mysql quota check tool — Here is how it works -

The MySQL Quota-Tool helps you to set a size limit on MySQL databases.

It works by checking the size of each database and revoking the INSERT- and REATE-priveleges for the databases, which exceed the given size limit.

When the size of the database falls below the given limit, the INSERT- and CREATE-priveleges are granted again.

This (of course) doesn’t work for users who have global priveleges, because the quota is database and not user based, but in most environments privileges are given in the “db”-table which is modified by the MySQL Quota Tool.

#!/usr/bin/php -q

/*
* MySQL quota script
* written by Sebastian Marsching
*
*/

/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

/*
* Create table for quota data with the following statement:
*
* CREATE TABLE `Quota` (`Db` CHAR(64) NOT NULL,
* `Limit` BIGINT NOT NULL,
* `Exceeded` ENUM('Y','N') DEFAULT 'N' NOT NULL,
* PRIMARY KEY (`Db`), UNIQUE (`Db`));
*
* The field 'db' stores the information for which database
* you want to limit the size.
* The field 'limit' is the size limit in bytes.
* The field 'exceeded' is only used internally and must be
* initialized with 'N'.
*/

/*
* Settings
*/

$mysql_host = 'localhost';
$mysql_user = 'root'; // Do NOT change, root-access is required
$mysql_pass = '';
$mysql_db = 'quotadb'; // Not the DB to check, but the db with the quota table
$mysql_table = 'quota';

/*
* Do NOT change anything below
*/

$debug = 0;

// Connect to MySQL Server

if (!mysql_connect($mysql_host, $mysql_user, $mysql_pass))
{
echo "Connection to MySQL-server failed!";
exit;
}

// Select database

if (!mysql_select_db($mysql_db))
{
echo "Selection of database $mysql_db failed!";
exit;
}

// Check quota for each entry in quota table

$sql = "SELECT * FROM $mysql_table;";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result))
{
$quota_db = $row['db'];
$quota_limit = $row['limit'];
$quota_exceeded = ($row['exceeded']=='Y') ? 1 : 0;

if ($debug)
echo "Checking quota for '$quota_db'...\n";

$qsql = "SHOW TABLE STATUS FROM $quota_db;";
$qresult = mysql_query($qsql);

if ($debug)
echo "SQL-query is \"$qsql\"\n";

$quota_size = 0;

while ($qrow = mysql_fetch_array($qresult))
{
if ($debug)
{ echo "Result of query:\n"; var_dump($qrow); }
$quota_size += $qrow['Data_length'] + $qrow['Index_length'];
}

if ($debug)
echo "Size is $quota_size bytes, limit is $quota_limit bytes\n";

if ($debug && $quota_exceeded)
echo "Quota is marked as exceeded.\n";
if ($debug && !$quota_exceeded)
echo "Quota is not marked as exceeded.\n";

if (($quota_size > $quota_limit) && !$quota_exceeded)
{
if ($debug)
echo “Locking database…\n”;
// Save in quota table
$usql = “UPDATE $mysql_table SET exceeded=’Y’ WHERE db=’$quota_db’;”;
mysql_query($usql);
if ($debug)
echo “Querying: $usql\n”;
// Dismiss CREATE and INSERT privilege for database
mysql_select_db(’mysql’);
$usql = “UPDATE db SET Insert_priv=’N', Create_priv=’N’ WHERE Db=’$quota_db’;”;
mysql_query($usql);
if ($debug)
echo “Querying: $usql\n”;
mysql_select_db($mysql_db);
}

if (($quota_size <= $quota_limit) && $quota_exceeded)
{
if ($debug)
echo "Unlocking database...\n";
// Save in quota table
$usql = "UPDATE $mysql_table SET exceeded='N' WHERE db='$quota_db';";
mysql_query($usql);
if ($debug)
echo "Querying: $usql\n";
// Grant CREATE and INSERT privilege for database
mysql_select_db('mysql');
$usql = "UPDATE db SET Insert_priv='Y', Create_priv='Y' WHERE Db='$quota_db';";
mysql_query($usql);
if ($debug)
echo "Querying: $usql\n";
mysql_select_db($mysql_db);
}
}

?>

—-

More details can be found at – http://projects.marsching.org/mysql_quota/

I am going to install this tool and see how it works for me :)

Thanks,
Preeti S.
ThinkSupport.net

Here is how to turn off safe_mode in php for 1 domain — Ensim Server

Friday, May 25th, 2007

Here is how to turn off safe_mode in php for 1 domain

pico /etc/httpd/conf/siteXX/safemode

where ’siteXX’ is the domain’s site number.

“sitelookup -d domain.com” to get site number

in that file type this line:

php_admin_flag safe_mode off

now restart apache

Thanks

Fantastico De Luxe 2.10.2 r45 (LATEST and STABLE releases) has fixed Mysql Bug

Friday, May 25th, 2007

If you were having issues connecting to mysql through fantastico (though you have mysql server up and running )

Fantastico has released patch for mysql bug - http://netenberg.com/forum/viewtopic.php?t=5786
Fantastico De Luxe 2.10.2 r45 (LATEST and STABLE releases)

Changes/Fixes:
- Fixed: MySQL Bug (http://netenberg.com/forum/viewtopic.php?t=5786)

Cheers :)
Sachin J.
http://thinksupport.net