Archive

Archive for April, 2008

Starting Apache And Named On Server Boot

April 30th, 2008 No comments

If you have installed Apache and Bind by yourself, they do not start automatically upon your server boot. In order to start them you don’t need any special knowledge, only a small linux command.
chkconfig --level 235 httpd on
chkconfig --level 235 named on

This will start these services automatically on runlevels 2,3 and 5. You don’t need to set them on other runlevels. Then you need to ensure whether everything went ok. Anothe simple command:
chkconfig --list httpd
chkconfig --list named

You should get something like this:
httpd 0:off 1:off 2:on 3:on 4:off 5:on 6:off

Have fun!

Viewing Apache Server Status From Your Browser

April 29th, 2008 No comments

Sometimes you need to have a look at , especially, if your server serves many users and if often busy. You should monitor you server’s CPU load, and view other information.

There is a simple solution in httpd.conf, that allows you to do this directly from your browser. All you need is just to add some lines to your configuration file. First of all, you should have the following sting, that makes this possible:
LoadModule status_module modules/mod_status.so

Usually at the bottom of the httpd.conf you can find some lines about server status. Let’s take the comments off.
ExtendedStatus On

This will show you more information, it’s what you exactly need. You don’t have to make this information public, but it will be very informative and useful for you. Then go down and add these lines:
<Location /server-status>
SetHandler server-status
</Location>

This URL will be relative to your Servername, so make sure you have set it up. You also should protect this location  just as shown in the sample httpd.conf:

#    Order deny,allow
#    Deny from all
#    Allow from .example.com

Just add your own limits and have fun! is done!

Encoding ASCII Characters in URL – PHP Solution

April 29th, 2008 No comments

Sometimes you need to encode the whole URL, not just specific characters that are encoded with urlencode(). You might need to represent your query string or anything else as shown at W3C School. There is quite a simple solution in PHP:

<?
$string="some-string";

for ($i=0; $i<strlen($url); $i++)
{
$mass[$i]=”%”.dechex(ord($url{$i}));
}

$encoded_string=implode(“”, $mass);
?>

In the sample provided the string is transformed into an array and then each array element is replaced with its hex representation. Then the array is transformed back to string.

I’ve been searching for this code on the net, but had to write it by myself and I’d like to share it with you.

This will help you to encode urls, form data or anything you like. Just paste the code and add your string! Hope this will help you to develop more efficient sites!

Apache 2.0 Default Virtualhost That Works

April 28th, 2008 No comments

If your server does not have any kind of graphic interface (Directadmin, Cpanel, etc…), you’ll have to create Apache Virtualhosts manually. You will need a working Virtualhost template for this. Using Apache example will guide you to problems with .htaccess files, therefore it will work too. I will show you a working example for Apache 2. Here it is:

<VirtualHost localhost.com:80>

ServerName www.localhost.com
ServerAlias www.localhost.com localhost.com
ServerAdmin webmaster@localhost.com
DocumentRoot /var/www/html/localhost.com/
UseCanonicalName OFF

<Directory /var/www/html/localhost.com>

Options +Includes -Indexes
Allowoverride All

</Directory>

</VirtualHost>

In this sample your user files are located at /var/www/html/localhost.com. It will also deny directory listing (make sure to take a look at DirectoryIndex directive and add all the necessary index types in httpd.conf). Have fun as everything you need is to change localhost.com to your domain name.