Archive for the ‘System Administration’ Category

PHP Perl Class

Hello,

I have a bit of problem combining PHP and Perl language.

I am trying to pass Perl variables into PHP and keep getting this error

“PHP Fatal error: Class ‘Perl’ not found in /var/www/html/hidden.php on line 3

find attached copy of my script.

Regards,
Customer

Naturally, I thought the customer was crazy. Then I looked at the script:

$perl = new Perl();
$perl->require(“userexit.pl”);

I lol’ed and then search, it seems the Perl class is provided by the Zend people in the form of a php extension, which is, fortunately, in pecl.

Unfortunately, this package seems to be broken :)

( ~ ) pecl install perl
Package “perl” Version “1.0.0″ does not have REST xml available
install failed

I did some searching and found an ‘open’ bug report:
16807

Rather than did too deep, I decided to just install the module manually for the customer.

# wget http://pecl.php.net/get/perl-1.0.0.tgz
# tar xzfv perl-1.0.0.tgz
# cd perl-1.0.0
# phpize
# ./configure
# make
# make install

Now edit your php.ini to include:

extension=perl.so

Or on Red Hat/Fedora, simply:

echo “extension=perl.so” > /etc/php.d/perl.ini

Don’t forget to restart apache.

viola:

# php -v ; php -m | grep perl
PHP 5.1.6 (cli) (built: Feb 26 2009 07:01:12)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
perl

As always, be careful when installing unmanaged modules. Future updates to php may introduce instability when depending modules are not rebuilt with the new symbol table.

Happy Hacking.

Vyatta – Community Software Download

Open Source networking. They provide Xen and VMware Images. I am going to play around with this a bit and blog about my experience. Why? Because it looks like I am working.

Vyatta – Community Software Download.

Transfer domain to new client in plesk

Like many things that should be easy in plesk, this requires manually updating the plesk database.

Before making changes to the psa database, it is always a good idea to make a backup:

mysqldump –opt -Q psa > psa.sql

First, we need some database normalization information:

mysql> use psa

mysql> SELECT id,pname from clients order by id;
+—-+——————+
| id | pname |
+—-+——————+
| 1 | My Domains |
| 2 | Desmond Willy |
| 4 | Beacon |
| 5 | Ham |
| 6 | Lefty |
| 7 | Simon Cowle |
| 8 | Scottyl |
| 9 | SomeRandom Guy |
+—-+——————+
8 rows in set (0.00 sec)

mysql> select id,displayname,cl_id from domains where displayname=’transferme.com’
-> ;
+—–+—————–+——-+
| id | displayname | cl_id |
+—–+—————–+——-+
| 101 | transferme.com | 1 |
+—–+—————–+——-+
1 row in set (0.00 sec)

So we can see that transferme.com is part of the My Domains client, but we want it to be part of the ‘SomeRandom Guy’ client. To do this we simply need to update the cl_id for the domain:

mysql> UPDATE domains SET cl_id=9 WHERE id=101;

mysql> select id,displayname,cl_id from domains where displayname=’transferme.com’;
+—–+—————–+——-+
| id | displayname | cl_id |
+—–+—————–+——-+
| 101 | transferme.com | 9 |
+—–+—————–+——-+
1 row in set (0.00 sec)

Now that is done. One last thing that is important not to forget, you must ensure that the client you are transfering the domain to has the ip that transferme.com is hosted on in its ip pool. If not, plesk will choke on itself.

Register.com, migration pains

Well. It has been a long day. I awoke this morning dealing with a major network outage. Once that passed, I settled into my normal routine of fixing Linux problems. While dumping some 80G of databases, I figured I would get a head start on my migration. I am moving blacknode.net to slicehost, so my first order of work was cleaning up and migrating my zones to slicehost’s nameservers. No big deal there.

Now here is where the trouble starts. For some reason I cannot recall, I used register.com as blacknode’s registrar 3 years ago when I sniped the domain from some German quake 2 gaming clan. After a few minutes of remembering my login credentials, I was there, looking at there root nameserver editing tool. I double checked my work and entered the new nameservers. I clicked submit.

I have walked customers through this process THOUSANDS of times. webmasters and ecommerce noobs have a stigma attached to all things DNS. The words TTL and root NS records seem to go hand in hand with 24-48 hours of downtime. The average domain owner also seems dread making changes at the registrar level; especially when register.com is involved. After todays experience, I think I finally understand why.

For some reason my dns changes would not stick. The interface simply said that the change failed and that I should try again. I did so, and still no go. The register.com website gloats about its amazing call center support. I think this is how they justify being the most expensive registrar on the planet.

So after the receptionist, who politely told me my estimated hold time (5 minutes), I was connected to a techie type who seemed to know what this crazy DNS thing was, or at least new what words to throw around. She went through the dns change process that I had just went through and verified that my dns servers we up and answering queries but ran into the same problems I did. She got me into a ticket and escalated the problem to a tech with access to the backend.

This was around 3:30pm.

I checked the status of my ticket by querying the whois database for register.com. After about an hour, I noticed something very wrong:

DNS Servers:

dns234.c.register.com
dns249.d.register.com
dns073.b.register.com
dns134.a.register.com

It seems that the annonymous technician was able to reset my domains root nameserver record to the default for register.com. I hoped this was a temporary thing, so I waited for about 5 minutes before getting worried. I attempted to alter the record to point to the slicehost nameservers again, but no dice. I tried to put it back to what I had initially, fail.

You see, I migrated my zone from Rackspace nameservers. The zone happily resolves on both slicehost dns and rackspace dns. So not being able to change it was not a problem, as long as the the records stayed what it had been for the last 3 years. It was about 4:30.

So I called up again. Same procedure, I had a ticket number, but the techie still had to jump through the hoops. I was ensured that my issue was being addressed by the highest escalation point available and that they would get to the bottom of the issue. They seemed to believe that the problem existed upstream somewhere, unfortunaitly, those guys live on the east coast, and are 9-5.

While on hold, I began adding the important records to the register.com dns servers. It seems that the original ip I had hosted blacknode.net on was still present on register’s nameservers with a TTL of about 14400 seconds. The ip was a dynamic address used on a residential broadband network. So i ended up caching this on my local dns…

So I was effectively down. Not that this cheesy blog gets allot of traffic. Or like I make money off this site. But if I did, I am sure I would be pissed.

The techie got back on the phone after about 15 minutes and said that they could not resolve the issue without the real technicians who only worked daywalker hours.

I think I will be transferring my domain elsewhere. Godaddy seems to be it.

~

Rackspace Cloud API

In an article here, Rackspace is announcing the availability of their beta web services api that can be used to jack into their cloud. Much like EC2, this should lead the way for projects like scaler, that dynamically grow a configuration as thresholds are reached.

Check out http://www.rackspacecloud.com/ for more info. I am going to sign up, I will let you know how it goes.

Enable core dumps with apache, RHEL5

If you are like me, you had some trouble getting apache to dump core on a RHEL5 system. The following steps have produced positive results for me:

echo "ulimit -c unlimited >/dev/null 2>&1" >> /etc/profile
echo "DAEMON_COREFILE_LIMIT='unlimited'" >> /etc/sysconfig/init
echo 1 > /proc/sys/fs/suid_dumpable
echo "core.%p" > /proc/sys/kernel/core_pattern
echo "CoreDumpDirectory /var/apache-core-dumps" > \
/etc/httpd/conf.d/core_dumps.conf
mkdir /var/apache-core-dumps
chown apache: /var/apache-core-dumps
source /etc/profile
/etc/init.d/httpd restart

Now you can test it by sending a SIGSEGV to a random apache child process:

# tail -f /var/log/httpd/error_log | grep -i seg &
# ps auxwww |grep httpd (pick a random pid not owned by root)
# kill -11 2014
# [Mon Jul 06 21:05:39 2009] [notice] child pid 2014 exit signal
Segmentation fault (11), possible coredump in /var/apache-core-dumps
# cd /var/apache-core-dumps
# ls
core.2014

You can then get a backtrace using gdb:

# gdb /usr/sbin/httpd core.2014
(gdb) > bt full

I hope this helps someone. Please feel free to comment.

Redirect domain.com to www.domain.com, universal

I still get allot of these requests, so I thought I would share this. You can add this rewrite rule to the .htaccess file located at the domains documentroot or in the virtualhost or directory context of the apache configuration to achieve the desired result.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}$1 [QSA,R=301,L]

Redirect index.php to root of current directory

An SEO conscious customer was having duplicate content issues for:

http://domain.com/something/

and

http://domain.com/something/index.php

Simply rewriting index.php to / will not be effective as httpd makes an internal redirect to the DirectoryIndex, causing a redirect loop.

In order to distinguish between the internal redirect and a client request, the %{THE_REQUEST} server variable is used.

When placed in the in the Directory context in the httpd.conf or in the .htaccess file located in the document root or desired origin directory, the following rule will achieve the desired results:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]+\ (.*)/index.php\ HTTP/
RewriteRule .*index.php$ http://%{HTTP_HOST}%1/ [L]

Note, this should be placed before any query_string rewriting you are doing for things like clean urls.

This will work recursively from its origin, so:

http://domain.com/something/index.php

and

http://domain.com/something/else/index.php

will be rewritten to:

http://domain.com/something/

and

http://domain.com/something/else/

Stop the plesk adminstrator from recieving dr.web license failures

… And other things that might annoy him/her

There was a request that went around for months from a plesk administrator griping about the various messages that appear in his mailbox, such as the dr.web license notification. By default, messages to the root and postmaster accounts are sent to the plesk administrator. This is accomplished via qmail aliases.

# cd /var/qmail/alias/
# ls -al
total 28
drwxr-sr-x 2 alias qmail 4096 Mar 9 01:59 .
drwxr-xr-x 11 root qmail 4096 Sep 29 21:14 ..
-rw-r–r– 1 root qmail 26 Dec 10 2007 .qmail-mailer-daemon
-rw-r–r– 1 root qmail 16 Mar 9 01:57 .qmail-postmaster
-rw-r–r– 1 root qmail 16 Mar 9 01:57 .qmail-root

Typically these look something link this:
# cat .qmail-postmaster
&plesk_admin_address@foo.bar.com

To keep the customer happy, I made a slight amendment to the alias:

# cat .qmail-postmaster
|cat >/dev/null
# cat .qmail-root
|cat >/dev/null

Removing the aliases will cause all kinds of noise in the logs and actually break the server’s already fragile rfc compliance (rfc2821:4.5.1) . This allows the messages to be ‘handled’ silently. Since most plesk ‘administrators’ don’t care to know how many failed ssh attempts there were in a month, or how much disk space they are using, it is usually a working solution when you can’t get dr.web to stfu.

tomcat + mod_jk + rhel5

[Warning: This guide needs to be updated. 09.08.2009]

v0.5

Because I’m tired of my peers thinking that the process is difficult, I decided to write a quick guide detailing the process of installing tomcat on rhel5 and configuring mod_jk with apache.

RHEL5 provides tomcat5 via RHN, unless you have access to another secure and maintained repository that provides tomcat, I recommend using RedHat’s package.

To install tomcat:

yum install tomcat5
/etc/init.d/tomcat5 start
chkconfig --levels 345 tomcat5 on

This will install and start the tomcat5 web server on port 8080. The redhat tomcat rpms are nearly identical in implementation to the jpackage rpms. $CATALINA_HOME is still /usr/share/tomcat5. That directory contains symlinks to other places.  So /usr/share/tomcat5/conf is a link to /etc/tomcat5.

To test the installation, I use the tomcats sample webapp which can be acquired and deployed like so:

wget http://tomcat.apache.org/tomcat-5.5-doc/appdev/sample/sample.war
mv sample.war /usr/share/tomcat5/webapps

The cool thing about .war files is the way tomcat interacts with them. Simply moving the sample.war to $CATALINA_HOME/wabapps will deploy the web base application. Tomcat will automatically extract, or explode sample.war to $CATALINA_HOME/wabapps/sample.

You can access the newly deployed application via the tomcat web server.

http://foo.bar:8080/sample/

If you have installed the tomcat5-webapps package, you will notice some other directories populating the webapps directory. There is a special webapp directory called ROOT which represents the root of the tomcat server, which can always be accessed by going to the root of the server.

http://foo.bar:8080/

Unless you plan on running tomcat on port 80, you are going to want apache to hand off, or connect, requests to the tomcat server. This is where mod_jk comes into the picture. mod_jk is an apache module known as a connector.

First, download the correct binary for your architecture and install it:

wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.23/mod_jk-1.2.23-apache-2.2.x-linux-i686.so

***
For x86_64 change to:

wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.23/mod_jk-1.2.23-apache-2.2.x-linux-x86_64.so
***

chmod +x mod_jk-1.2.23-apache-2.2.x-linux-i686.so
cp -av mod_jk-1.2.23-apache-2.2.x-linux-i686.so /etc/httpd/modules/mod_jk.so

vim /etc/httpd/conf.d/mod_jk.conf

LoadModule jk_module modules/mod_jk.so

JkWorkersFile /etc/httpd/conf/workers.properties
JkShmFile /var/log/httpd/mod_jk.shm
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info


vim /etc/httpd/conf/workers.properties

workers.tomcat_home=/usr/share/tomcat5

workers.java_home=/usr/lib/jvm/java

worker.list=jkworker

worker.jkworker.port=8009
worker.jkworker.host=localhost
worker.jkworker.type=ajp13

Now restart apache:

/etc/init.d/httpd configtest
/etc/init.d/httpd restart

At this point you have everything you need to run jsp pages and servlets with tomcat, while still hanging on to familiar httpd virtual hosting and configuration. If you have not read the tomcat documentation on connectors, then you should at this point.

In order to use mod_jk to connect to a tomcat webapp, we need to mount it via the apache configuration. The JkMount directive takes care of this for us. To demonstrate this run the following:

mkdir /usr/share/tomcat5/webapps/test/

vim /usr/share/tomcat5/webapps/test/index.jsp

Hello, I am a jsp script!

<%
// get client locale
java.util.Locale locale = request.getLocale();

// get Dateformat for client’s locale
java.text.DateFormat dateFormat =
java.text.DateFormat.getDateTimeInstance(
java.text.DateFormat.LONG,
java.text.DateFormat.LONG, locale);

%>

The time is:
<%=dateFormat.format( new java.util.Date() ) %>

Now add the following somewhere in the apache configuration:

JkMount /test/* jkworker

JkMount works similar to the apache alias directive. It can be used in the main configuration or virtualhost context. For testing purposes, you can append the mount line to your mod_jk.conf file.

Restart apache and hit the following:

http://localhost/test/

Tomcat ships with a web based administration webapp and also a manager webapp that can be used to deploy other webapps. To use these features, you need to install them from rhn if they have not already been installaed:

yum install tomcat5-admin-webapps

In order to access these webapps, you need to first authenticate. In tomcat, you can define users and user roles. Users and roles are defined in $CATALINA_HOME/conf/tomcat-users.xml (/etc/tomat5/tomcat-users.xml). The admin webapps require authenticated users to have certain roles before they are granted access. For the admin webapp, a user who has the role ‘admin’ is granted access. For the manager webapp, the user will need the ‘manager’ role.

By default, the admin and manager roles are not created so you must define them and assign a user to them. I typically create an ‘admin’ user and give that user both the admin and manager roles. Open up /etc/tomat5/tomcat-users.xml and edit it to look like this:

<?xml version=’1.0′ encoding=’utf-8′?>
<tomcat-users>
<role rolename=”admin”/>
<role rolename=”tomcat”/>
<role rolename=”manager”/>
<role rolename=”role1″/>
<user username=”admin” password=”SuperSecretPassword” roles=”admin,tomcat,manager”/>
<user username=”tomcat” password=”tomcat” roles=”tomcat”/>
<user username=”both” password=”tomcat” roles=”tomcat,role1″/>
<user username=”role1″ password=”tomcat” roles=”role1″/>
</tomcat-users>

Now you can access both the manager and the admin panel with the admin user. Try this out:

httpd://yourdomain.net:8080/admin
httpd://yourdomain.net:8080/manager

If you don’t want to type the port, you can mount the apps with JkMount /admin/* jkworker or JkMount /manager/* jkworker.

At present, this guide is far from complete. However, I think something like this would have helped me the first time I had to install tomcat on a shared server. Please feel free to post comments and flames.

jrod@blacknode.net

Return top