Archive

Archive for the ‘Apache Performance’ Category

How to Upgrade Apache From 1.3 to 2.0 on a Directadmin Server

October 21st, 2008 No comments

When you get your new Directadmin server, it comes with default settings like Apache 1.3 and PHP4. I have already written how to update PHP version to PHP5. Today I will post a solution that can be used to upgrade your apache installation on a Directadmin server.

The idea is not mine, it is taken from Directadmin Official Site and is also listed on Directadmin Forum. I will post it here as I am trying to create a comprehensive guide on how to deal with Linux servers. So, first of all we need to have root access, and I’d advise you to shut down Apache before trying to update it. The command is

service httpd stop

Next you need to do the following list of commands:

cd /usr/local/directadmin/customapache
./build update
./build clean
./build update_data_ap2
./build convert
./build apache_2
./build php_ap2 n
./build mod_frontpage_ap2
./build mod_perl_ap2
/sbin/service httpd restart

This will download and install the latest Apache build and will compile it with most used modules. After the Apache is rebooted, your changes are applied and you should have a fully functional version of Apache. I just performed this action on the VPS where this site is located in order to improve its performance. I recommend you to do the same.

How to Find Which Script Causes Most Apache Load

October 18th, 2008 No comments

It is often hard to tell which process causes most Apache load. top and ps -aux commands don’t give us anything usable; they only allow us to see that Apache causes . We need to identify which scripts are not so good for and fix them.

The first advice is to view Apache server status. I have already written how to enable it here. This will allow you to monitor Apache requests and will show you which requests are most popular and which of them cause problems.

If you have many users on your server, suphp might help you to identify the problem. As all php scripts are run by corresponding user, you will be able to identify which user causes most server load related to Apache.

This article does not describe the process of identification of MySQL server load. Maybe I will write about it later.

How to Check if Apache Is Up and Restart if Not

September 17th, 2008 No comments

I do often monitor status as most often reason of is Apache overload. Some web hosting panels are sending notifications when your server is down; some web services like Alertra.com provide you with different and one of my hosters has his internal . But what to do if you need to go anywhere where you can’t get access to your server? You’ll need a cron task that will check whether apache is up and will restart it if not.

I’ve found a solution at a forum. You’ll need a simple shell script and here it is:

#!/bin/sh
run=`ps ax | grep /usr/sbin/httpd | grep -v grep | cut -c1-5 | paste -s -`
if [ "$run" ];
then
echo “Apache is running”
else
/etc/init.d/httpd start
fi

This script will check for a number of running script processes and will try to start apache if it is not running. You should add this script to crontab with any frequency you like. I’d suggest to run it every 3 minutes as it doesn’t cause , but your apache stability is vital.

Categories: Apache Performance, Linux Tricks Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Regular Expression to Parse Text Between Simple Tags (XML)

September 6th, 2008 2 comments

It is often necessary to extract text from a variable that contains HTML or XML code. I’ve created a simple regular expression that will help you to extract all text between certain tags into an array. It is a PHP solution, though regular expression is compatible with other programming languages.

preg_match_all(“/<tag>(.*?)<\/tag>/”, $source, $results);

This construsion will create an array with extracted data. All you need is to change “tag” to any tag you like. This string was created to parse xml files, but it will work for simple HTML tags without attributes too.

The function above will extract all occurences of regular expression match. $output will contain an array with the extracted values. Please, run var_dump to check what’s in this array