Binding to IP aliases and using non-standard ports

Problems with the Linux version of XAMPP, questions, comments, and anything related.

Binding to IP aliases and using non-standard ports

Postby JKMickelson » 23. February 2007 10:15

I have code that enables the /opt/lampp/lampp script to read the actual values in the config files for http, https, mysql, and proftpd instead of presuming the defaults. The code uses these config file values when checking the port (i.e. testport).

This allows XAMPP to co-reside with an RPM installation (apt-get, yum, etc) of httpd, mysqld, and any ftp service. This also allows XAMPP to be bound to an IP alias (using identical ports) which provides a discreet environment.

The importance of this ability is that I can now easily run two versions of Apache, MySQL, and PHP without disturbing either environment.

How do I contribute this code to XAMPP?

Thanks,
Jonathan
JKMickelson
 
Posts: 30
Joined: 23. February 2007 09:56

The proposed changes...

Postby JKMickelson » 23. February 2007 22:20

These are the proposed changes to the lampp script:

After the copyright notice, add the line
Code: Select all
. /opt/lampp/checkport

Replace these individual lines of code
Code: Select all
if testport 80
if testport 443
if testport 3306
if testport 21

with these lines respectively
Code: Select all
if checkport HTTP
if checkport HTTPS
if checkport MYSQL
if checkport FTP


The checkport script is placed in the /opt/lampp directory.

Done!
JKMickelson
 
Posts: 30
Joined: 23. February 2007 09:56

This is the checkport script

Postby JKMickelson » 24. February 2007 00:42

This is the checkport script.

Code: Select all
#!/bin/bash
# checkport
# description: checks if the port is in use for the service specified.
#              uses actual config file values, both IP address and port number.
#
# usage: checkport [HTTP | HTTPS | MYSQL | FTP]
#
# getport
# description: gets the IP address and port number for the service specified.
#              uses actual config file values, both IP address and port number.
#
# usage: getport [HTTP | HTTPS | MYSQL | FTP]
#
###############################################################################
# Copyright 2007 by Jonathan K Mickelson
# Tri-license: MPL 1.1/LGPL 2.1/GPL 2.0
# see http://www.mozilla.org/MPL/

function getport()
{
    httpd_conf='/opt/lampp/etc/httpd.conf'
    httpd_ssl_conf='/opt/lampp/etc/extra/httpd-ssl.conf'
    mysql_conf='/opt/lampp/etc/my.cnf'
    proftpd_conf='/opt/lampp/etc/proftpd.conf'

    case "$1" in
        'HTTP')
            var=`grep ^Listen $httpd_conf`
            set -- $var
            port=$2
            ;;
        'HTTPS')
            var=`grep ^Listen $httpd_ssl_conf`
            set -- $var
            port=$2
            ;;
        'MYSQL')
            OIFS=$IFS
            IFS="=$IFS"
            ip=`grep ^bind-address $mysql_conf`
            set -- $ip
            ip=$2
            if [ "$ip" != "" ]
            then
                ip=$ip:
            fi
            var=`grep ^port $mysql_conf`
            set -- $var
            IFS=$OIFS
            port=$ip$2
            ;;
        'FTP')
            ip=`grep ^DefaultAddress $proftpd_conf`
            set -- $ip
            ip=$2
            if [ "$ip" != "" ]
            then
                ip=$ip:
            fi
            var=`grep ^Port $proftpd_conf`
            set -- $var
            port=$ip$2
            ;;
        *)
            port=0
            ;;
    esac
    echo $port
}

function checkport()
{
    port=$(getport $1)
    # add colon if IP address is not present
    if echo $port|grep : >/dev/null
    then
        PORT=$port
    else
        PORT=:$port
    fi

    MATCH=' .*LISTEN *$'
    if netstat -an|grep "$PORT$MATCH" >/dev/null
    then
        ret=0
    else
        ret=1
    fi
    return $ret
}
JKMickelson
 
Posts: 30
Joined: 23. February 2007 09:56

Postby Oswald » 25. February 2007 18:45

Dear Jonathan!

Looks great!!! I think I've to include it into the next XAMPP release. But I'll move checkport to /opt/lampp/bin to keep the /opt/lampp directory clean.

Thanks a million!!! Do you've more ideas? ;)

Many greetings
Oswald
User avatar
Oswald
Apache Friends
 
Posts: 2718
Joined: 26. December 2002 19:51
Location: Berlin, Germany
Operating System: Linux


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 12 guests