Archive for May, 2006

Running suPHP and mod_php side by side on Plesk

Sunday, May 14th, 2006

By default all the Plesk servers runs mod_php for speed. This has one major drawback and that is that if a clients creates files via PHP, they are owned by the webserver user under which mod_php runs. The solution to the problem seems to enable suPHP for the clients that needs to create files via PHP.

Below is the procedure that I found to work:

  1. Download the mod_php RPM from the Dag Wiers repository:

    wget http://dag.wieers.com/packages/mod_suphp/mod_suphp-0.6.1-2.1.el3.rf.i386.rpm

  2. Install the mod_php RPM:

    rpm -Uvh mod_suphp-0.6.1-2.1.el3.rf.i386.rpm

  3. Disable able the mod_suphp AddHandler in /etc/httpd/conf.d/suphp.conf
  4. Your /etc/httpd/conf.d/suphp.conf, should only have the following lines:

    LoadModule suphp_module modules/mod_suphp.so
    LoadModule php4_module modules/libphp4.so
    suPHP_Engine off

    Putting the above into your config will default to PHP pages being run by mod_php.

  5. To switch a virtual host over to mod_suphp, use the following:

    <Directory /home/httpd/vhosts/<VHOST>/httpdocs>
    <IfModule sapi_apache2.c>
    <IfModule mod_suphp.c>
        RemoveHandler x-httpd-php
        php_admin_flag engine Off
        suPHP_AddHandler x-httpd-php .php
        suPHP_Engine on
        AddHandler x-httpd-php .php
        suPHP_UserGroup <USER> <GROUP>
    </IfModule>
    </IfModule>
    </Directory>

    The config above will only activate if both mod_php and mod_suphp is loaded. Remember to replace the <VHOST>, <USER> and <GROUP> entries with the correct virtual host, Unix user and Unix group.

EDIT: In later versions of PHP, the CLI and CGI version are 2 separate binaries. You now need to edit the /etc/suphp.conf file to reflect the correct binary in the x-httpd-php=php:/usr/bin/php-cgi entry. To determine which binary you need to add, simple do a php -v on the command line. The binary that outputs the cgi information as part of the version information, is the correct binary.

RubyGems on RHEL3/CentOs3

Saturday, May 13th, 2006

This howto guide is based on RubyGems version 0.8.11 which was the current version at the time of writing this guide.

Download the mod_RubyGems source code from: http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz

Extract the .tgz file to a suitable location:

cd /usr/src
tar zxvf /usr/local/src/rubygems-0.8.11.tgz
cd rubygems-0.8.11.tgz

Run the setup command:

ruby setup.rb

Now compile the program:

make

Finally, install ruby:

make install

It is now time to configure Apache to run with mod_ruby. Please see this post.

Howto install mod_ruby on RHEL3/CentOS3

Wednesday, May 10th, 2006

This howto guide is based on mod_ruby version 1.2.5 which was the current version at the time of writing this guide. We also need version 1.2.5, since it supports the Apache::RailsDispatcher, which is needed if we want to run RubyOnRails in our Plesk environment.

Download the mod_ruby source code from: http://www.modruby.net/archive/mod_ruby-1.2.5.tar.gz

Extract the .tar.gz file to a suitable location:

cd /usr/src
tar zxvf /usr/local/src/mod_ruby-1.2.5.tar.gz
cd mod_ruby-1.2.5

Run the configure command:

./configure.rb --with-apxs=/usr/sbin/apxs

Now compile the program:

make

Finally, install ruby:

make install

It is now time to configure Apache to run with mod_ruby.

Apache::RailsDispatcher can run multiple applications in the same process. It works like this:

  • require loads libraries into the top level, and they are shared with all applications.
  • require_dependency loads libraries into an anonymous module for each application.
  • In the development environment, the anonymous module is orphaned on each request. So required_dependency loads libraries every time.
  • In the production environment, the same anonymous module is used for the same application. So required_dependency loads libraries only at once.
  • Rails configurations such as ActiveRecord::Base.colorize_logging are reset on each request.

This hack is just a workaround until YARV supports multiple VM instances. We can get it in the near future, I hope.

To use Apache::RailsDispatcher, you have to write the following configuration in httpd.conf.

RubySafeLevel 0
# If you use RubyGems
# RubyRequire rubygems
RubyRequire apache/rails-dispatcher
RubyTransHandler Apache::RailsDispatcher.instance
<Location /ruby-application-name>
    SetHandler ruby-object
    RubyHandler Apache::RailsDispatcher.instance
    RubyOption rails_uri_root /ruby-application-name
    RubyOption rails_root /path/to/rails/root
    RubyOption rails_env production
</Location>

Please note that you can’t override exinting classes like this:

class Array     def cycle()         self.each_with_index {|o, i| yield(o, %w(odd even)[i % 2])}     end end

You should prepend Object:: to the class name:

class Object::Array     def cycle()         self.each_with_index {|o, i| yield(o, %w(odd even)[i % 2])}     end end

This behaivour is same as Kernel.load(filename, true). If you don’t like this, please convince Matz to change it.

Your done. You should now have a valid ruby interperter running on your server.

Portions of this post is courtesy of: http://blog.shugo.net/articles/2005/08/03/running-rails-on-mod_ruby

Configure Ruby 1.8.4 on RHEL3/CentOS3

Wednesday, May 10th, 2006

This howto guide is based on ruby version 1.8.4 which was the current version at the time of writing this guide.

Download the ruby source code from: http://www.rubyonrails.org/down

Extract the .tar.gz file to a suitable location:

cd /usr/src
tar zxvf /usr/local/src/ruby-1.8.4.tar.gz

Run the configure command:

./configure --prefix=/usr --sysconfdir=/etc --enable-shared --enable-install-doc

Now compile the program:

make

Run the test suite:

make test

You should receive a: “test succeeded” output.
Finally, install ruby:

make install

Your done. You should now have a valid ruby interperter running on your server.

Howto: Install mod_python on Plesk

Wednesday, May 10th, 2006

This is a simple guide to install/upgrade mod_python on a Plesk RHEL box, running Apache 2.0.x. You need to have at least Python version 2.2.1 installed for this to work.

I could not get mod_python version 3.2.8 running at the time of writing.

  1. Download and extract mod_python:

    cd /usr/local/src
    wget http://apache.mirrors.pair.com/httpd/modpython/mod_python-3.1.4.tgz
    tar zxvf mod_python-3.1.4.tgz

  2. Configure & install mod_python

    cd mod_python-3.1.4
    ./configure --with-apxs=/usr/sbin/apxs (check where your apxs is by typing: locate apxs)
    make
    make install

  3. Configure Apache:

    vi /etc/httpd/conf.d/pyhton.conf

    Locate your LoadModule – section and add the following line under the others:

    LoadModule python_module modules/mod_python.so

  4. Installation done, now time for testing:

    First go to a publicly accessible directory. Make a test directory for mod_python by typing:

    mkdir python

    Now open vi and write the following lines:

    AddHandler python-program .py
    PythonHandler testingpython
    PythonDebug O
    n

    save the file as .htaccess.

    Now open up vi again and copy/paste the following lines:

    from mod_python import apache

    def handler(req):
            req.send_http_header()
            req.write("Hello World!")
            return apache.OK

    close and save as testingpython.py. Those are tabs not spaces. If you left align everything you will get this error:

    IndentationError: expected an indented block (testingpython.py, line 4)"

    Now restart Apache by typing: service httpd restart

Take your browser to www.mydomain.com/python/testingpython.py and you should see “Hello World!” If you can see this message then you have succesfully installed mod_python.

Dr.Web, qmail & SpamAssassin on Plesk 7.5.4

Wednesday, May 3rd, 2006

For some reason the Dr.Web, qmail and SpamAssassin integration on Plesk sometimes does not work properly after an upgrade.

It is important to make sure that the binaries in the /var/qmail/bin directory have the following permissions, to enable Dr.Web, qmail and SpamAssassin to work together.

-r-s–x–x 1 drweb qmail 161024 Mar 19 01:34 qmail-queue
-r-s–x–x 1 drweb qmail 161024 Mar 19 01:34 qmail-queue.drweb
-r-s–x–x 1 qmailq qmail 15936 Aug 24 2005 qmail-queue.origin

The process runs as follows:

  1. Incoming mail will be delivered using the qmail-queue binary, which is a specially compiled version that allows qmail to scan the email for viruses.
  2. The qmail-queue binary will write a temporary file in the /var/drweb/spool/ directory. It is therefore important to check the permissions on the /var/drweb/spool/. They should be:

    drwxrwx— 2 drweb nofiles 4096 May 3 13:20 spool

  3. The qmail-queue binary will also read the /etc/drweb/drweb_qmail.conf file and it will execute the file found in the QmailQueue = tag, once virus scanning is complete. The QmailQueue = tag usually contains:
    /var/qmail/bin/qmail-queue.origin

  4. After the virus scanning process completes, the qmail-queue.origin binary will run. This binary will in turn run the SpamAssassin rules as defined in each users configuration.

The following files maybe useful in locating a problem:

  1. /usr/local/psa/var/log/maillog – This file contains the mail logs and you will quickly see if any errors are being generated in it.
  2. /var/drweb/log/drwebd.log - This file contains the Dr.Web logs for all scanned emails.