Monday, October 25, 2010

Some notes about Apache server and MySQL

Apache web server FAQ is  here

Start web server, log in as root

1)/usr/sbin/apachectl start   (Latest Linux  comes httpd server)

(Bear in mind that an Apache RPM may already be installed on your system depending on how Linux was originally installed on your computer. To find out, at the shell prompt, type:

rpm -qa | grep apache





2) hostname; default web site is http://hostname

Any subdirectories which existed under /home/httpd should now be moved to /var/www. Alternatively, the contents of /var/www can be moved to /home/httpd, and the configuration file can be updated accordingly.

3) Setup   index.html    for /var/www/index.html

check configure file under directory:  /etc/httpd/conf

4) for a user url

under /var/www/html,  ln -s  /home/jiansen/html  jiansen, then user jiansen has a website:  http://hostname/jiansen

5) Change the website name can be found  here

6) CGI

The ScriptAlias directive looks like:

        ScriptAlias /cgi-bin/ /usr/local/apache/cgi-bin/

The example shown is from your default httpd.conf configuration file, if you installed Apache in the default location. The ScriptAlias directive is much like the Alias directive, which defines a URL prefix that is to mapped to a particular directory. Alias and ScriptAlias are usually used for directories that are outside of the DocumentRoot directory. The difference between Alias and ScriptAlias is that ScriptAlias has the added meaning that everything under that URL prefix will be considered a CGI program. So, the example above tells Apache that any request for a resource beginning with /cgi-bin/ should be served from the directory /usr/local/apache/cgi-bin/, and should be treated as a CGI program.

For example, if the URL http://www.example.com/cgi-bin/test.pl is requested, Apache will attempt to execute the file /usr/local/apache/cgi-bin/test.pl and return the output. Of course, the file will have to exist, and be executable, and return output in a particular way, or Apache will return an error message.

CGI outside of ScriptAlias directories

CGI programs are often restricted to ScriptAlias'ed directories for security reasons. In this way, administrators can tightly control who is allowed to use CGI programs. However, if the proper security precautions are taken, there is no reason why CGI programs cannot be run from arbitrary directories. For example, you may wish to let users have web content in their home directories with the UserDir directive. If they want to have their own CGI programs, but don't have access to the main cgi-bin directory, they will need to be able to run CGI programs elsewhere.

Explicitly using Options to permit CGI execution

You could explicitly use the Options directive, inside your main server configuration file, to specify that CGI execution was permitted in a particular directory:

        <Directory /usr/local/apache/htdocs/somedir>

                Options +ExecCGI

        </Directory>

The above directive tells Apache to permit the execution of CGI files. You will also need to tell the server what files are CGI files. The following AddHandler directive tells the server to treat all files with the cgi or pl extension as CGI programs:

     AddHandler cgi-script cgi pl

cgi example1 (shell script)

 CGI Shell script to output a text page: /var/www/cgi-bin/cat-a-text-page

#!/bin/sh

CAT=/bin/cat

COLCRT=/usr/bin/colcrt

echo Content-type: text/plain

echo ""

if [[ -x $CAT && -x $COLCRT ]]

then

        $CAT $1 | $COLCRT

else

        echo Cannot find command on this system.

fi

 

Useage: <A HREF="/cgi-bin/cat-a-text-page?/home/jiansen/asy_dir.alu/mainalzz.f">Text of link</A>

Note that the permissions on the shell script must changed to make the script executable: chmod +x cat-a-text-page

cgi example2 (perl)

#!/usr/bin/perl

print "Content-type: text/html\r\n\r\n";

print "Hello, World.";

Example of mysql:

To reset a root password that you forgot (using paths on our system):

[root@host root]#killall mysqld

[root@host root]#/usr/libexec/mysqld -Sg --user=root &

[root@host root]# mysql

Welcome to the MySQL monitor.  Commands end with ; or g.

Your MySQL connection id is 1 to server version: 3.23.41

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

No comments:

Post a Comment