Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

mod_perl apache and thin apache - same machine - HOW -TO

Quote Reply
mod_perl apache and thin apache - same machine - HOW -TO
PRE-first -- this is a _long_ message. I would suggest starting a new thread
to ask questions, and just post additional instructions to this one.


FIRST: some cautions,

#1... BACKUP EVERYTHING!!! Use tar and put it in a safe place.

#2.... don't do this in the middle of the night, when you are tired, or not thinking
clearly. It's a simple, straight forward process -- thanks to the Apache people and the
Gnu people, and all the opensource people who worked hard to make some of the most awesome,
complete, self-configuring install programs ever!! and to Alex who gave the short,
concise version of what to do <G>

#3... Don't take shortcuts. Period. Don't try to run:
/usr/local/apache_perl/bin/apachectl start from the
/usr/local/apache/bin directory.... the program defaults to the LOCAL copy, not
the one you expect. You run the /usr/local/apache_perl/bin/apachectl program, but
it runs the /usr/local/apache/bin/httpd and uses the /usr/local/apache/conf/httpd.conf

#4... KNOW what is going on! This goes back to #2. I was using wsftp and having it
open the files for me. What I didn't do is CLOSE the file - http.conf - after editing it,
so when I transfered the other version, and clicked on it in the wsftp window -- it wasn't
smart enough to notice the changes, and I edited the old file -- BIG source of error...
fortunately I'd been bitten by it before, so I found it really fast.

#5... every time you _think_ you fixed something ... CLOSE ALL UNNECESSARY WINDOWS
(on any platform) and then run it. You won't be tempted to make a change in the wrong
window if something doesn't work. This goes back to #2, #3, and #4 <G>


SECOND: This is _my_ install on Unix (pretty generic Solaris 2.7). It probably won't
work on NT, but the _process_ is similar.


THIRD: Now that we have that out of the way, I'm _assuming_ some knowledge of Unix,
Perl, Apache, and that you have "root" access to your server. If you don't, sorry,
this won't apply to you at all. I'm not going to start at how to log in, use
telnet, tar, gz, etc. I'm assuming you know that -- or can figure it out by reading
the INSTALL, README, CONFIGURE and other capitalized files in _EACH_OF_THE_DOWNLOAD_ARCHIVES_
you get. This in _NO_WAY_ replaces reading those docs, it just makes the step-by-step
for this specific process easier.

FOURTH: I make no warrantees, and I probably can't help you if something doesn't work.
That is why you BACK UP EVERYTHING!!! I take you through the backup steps, where possible.


FIFTH: If you read this far, we can begin.

----------


1) BACKUP EVERYTHING (AGAIN!) Smile

2) if your apache is in /usr/local/apache then the command is:
tar -cvf /your/home/directory/my_apache_backup.tar /usr/local/apache

the -cvf loosely translated is "create verbose file(not device)"
the next is the location/file of the new archive
the last is a list of files/directories to include.

3) Now that that is out of the way, make a copy of your httpd file, _AND_
your httpd.conf file ---

cp /usr/local/apache/bin/httpd /usr/local/apache/bin/httpd_no_perl
cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf_no_perl

The reason for this, is if all else fails, and things go really bad, you
can quickly mv httpd_no_perl to httpd and httpd.conf_no_perl to httpd.conf
and restart your servers and sort things out.

4) Now, you need to download the current version of apache, mod_perl, and mod_php
if you want that. I do, because it has it's uses..

5) I'm purposely NOT using CPAN, since we are making changes, I didn't want to
add in any 3rd party complexity.

6) Apache_1.3.11 which is the version I installed, has very well done interface.
Your Apache could have a different number, but it should be AT LEAST this high,
or higher.

mod_perl-1.21 is the current version, and I chose the newest PHP3 -- not 4,
since 4 is still "beta"

php_3.0.14 is the latest bug fix.

Your exact file names will vary --- the '_' and '.' are often interchanged
on different systems.

7) In your home directory, or sub directory, put the 3 files together, and we
will untar, and unzip them. in the same directory.

Variations of how to do this are: (the xxx's are the version numbers)

tar -zxf apache_x.xx.tar.gz
gunzip <apache_1.3.X.tar.gz | tar xvf -

or type gunzip apache_x.xx.tar.gz
then tar -xvf apache_x.xx.tar

Remember, the '_' and '.' can change, so CHECK YOUR FILE LIST: ls -l -d a* for
the exact name. (and the .gz file disappears leaving the 'tar' file when you unzip it)

Do the same for mod_perl and php.

8) You should now have a directory list that looks like:

drwxr-xr-x 8 pugdog other 512 Jan 27 05:54 apache_1.3.11
-rw-r--r-- 1 pugdog other 6717440 Jan 26 17:46 apache_1.3.11.tar
-rw-r--r-- 1 pugdog other 3298304 Jan 26 17:24 apache_tar
drwxr-xr-x 24 pugdog other 1024 Jan 27 05:09 mod_perl-1.21
-rw-r--r-- 1 pugdog other 1177600 Jan 26 18:22 mod_perl-1.21.tar
drwxr-xr-x 26 500 www 4096 Oct 31 02:20 perl5.005_03
-rw-r--r-- 1 pugdog other 13793280 Oct 31 02:05 perl5_005_03_tar
drwxr-xr-x 16 root root 3584 Jan 27 05:51 php-3.0.14
-rw-r--r-- 1 pugdog other 12943360 Jan 27 05:31 php-3_0_14_tar

you see my "apache_tar" backup file, the fact I recently upgraded perl,
and the three new directories and .tar files. NOTE: the apache and
mod_perl were .tar, and the php was '_tar'

9) NOW: you need to Pre-configure Apache in order to set some defaults for PHP,
it's sort of a circular thing. The configure script sets parameters that are
used during the builds, but doesn't actuall "DO" anything. Using the paths
above (this is in your home directory... /usr/homes/me/working or something similar)
For the "thin" apache, we just do a configure/build, for the mod_perl apache, we
have to bounce around a bit. We will do thin first.

You can usually do the following as "you" , but the "build" and "install" has to
be done as 'root' ... I'm going to use 'root' prompts since they are easy ... the
'>' means that's what the system sends back. I do that _ONLY_ where it's necessary
since these files spit out literally 1000's of lines of progress.

NOTE: I am _NOT_ using dynamic (DSO) linking, since it's new, probably buggy,
not well supported, etc, etc, and the purpose for us is SPEED, so lets link it all in.

# pwd
> /usr/homes/me/working
# cd apache_1.3.11


Now, you need to set up the configure file. READ THE DOCS!!! The _minimal_ string
to pass to this apache is
./configure --prefix=PREFIX

where "PREFIX" is the install directory.
we are using /usr/local/apache (the default) _AND_ /usr/local/apache_perl (the mod_perl)

Let's make the "thin" apache first.

# ./configure --prefix=/usr/local/apache

('root' should never have '.' in it's path, but I load a shell to make life easier
when I'm working..... if you have '.' in your path, you don't need the './' but
it can't hurt).

The above sets the scripts to compile apache in the default location.

You should _not_ see any error messages. If you do, it's up to you to track them down! <G>



10) Now, we need to compile PHP.

# cd ../php-3.0.14
# pwd
> /usr/homes/me/working/php-3.0.14 (I'm a bit paranoid)

#./configure --with-mysql=/usr/local/mysql-3.22.23b-sun-solaris2.6-sparc \
--with-apache=../apache_1.3.11 --enable-track-vars

You need to put the path to your MySQL install directory, and the apache directory
we just created in as above. ABSOLUTE paths are great, relative work if you are careful.

Now, we need to make/install/etc.

# make
# make install

As always, you'll see a _LOT_ of output, hopefully no errors. You need to do this as 'root'
since it installs stuff in the perl tree, and other places.

Then, we need to go back to apache.

# cd ../apache_1.3.x

# ./configure --prefix=/usr/local/apache \
--activate-module=src/modules/php3/libphp3.a \
--enable-module=rewrite \
--enable-module=proxy


NOTE: The above line is correct! Yes, we know libphp3.a does not exist at this
stage. It isn't supposed to. It will be created.)

We also need to compile in the "proxy" and the "rewrite" engine is a good idea.

Again, hopefully no errors.

# make

# make install

You can edit /usr/local/lib/php3.ini file to set PHP options.
You also need to edit your httpd.conf or srm.conf file and add:
AddType application/x-httpd-php3 .php3


The current version of the httpd.conf file has some lines you just need to uncomment:
>> # For example, the PHP 3.x module (not part of the Apache distribution - see
>> # http://www.php.net) will typically use:
>> #
>> AddType application/x-httpd-php3 .php3
>> AddType application/x-httpd-php3-source .phps


You also need to add in the proxy statements:

ProxyPass /perl/ http://postcards.com:81/cgi-bin/
ProxyPassReverse /perl/ http://postcards.com:81/cgi-bin/

I added them in the block, uncommented the IF block, and the ProxyRequests.

<IfModule mod_proxy.c>
ProxyRequests On
ProxyPass /perl/ http://postcards.com:81/cgi-bin/
ProxyPassReverse /perl/ http://postcards.com:81/cgi-bin/
</IfModule>

According to the docs, "ProxyPass" is honored even if ProxyRequests is Off.
Uncommenting the <IF> block allows you to use the same config file for your
generic Apache if you have to go back to it for some reason.

11) That's _IT_ for the thin apache!

12) Now for mod_perl

This file is going to be installed in the apache_perl directory, so we need
to change the ./configure file ...

# ./configure --prefix=/usr/local/apache_perl

> should not have any errors....

# cd ../mod_perl-1.21
# pwd
> /usr/home/me/working/mod_perl-1.21

Now, we are going to _just_ compile mod_perl, put it in the Apache source tree,
and go back to apache to finish the config. Why? I like it better that way.


#perl Makefile.PL \
APACHE_SRC=../apache_1.3.11/src \
DO_HTTPD=1 \
USE_APACI=1 \
PREP_HTTPD=1 \
EVERYTHING=1


That is the "generic" compile. No tweaks (maybe people will post some later).


Again, you should not see any errors, and you should be 'root'


13) Now, we need to go back to the apache directory, and finally make the "Fat" apache.

# cd ../apache_1.3.11


# ./configure --prefix=/usr/local/apache_perl \
--activate-module=src/modules/perl/libperl.a \
--enable-module=rewrite \
--enable-module=proxy
# make
# make install

14) You should now have 2 copies of apache, in two different directories.

Edit the /usr/local/apache_perl/conf/httpd.conf file so that:

Change the port that it listens to from '80' to '81'

Next: You need to take your "thin" apache httpd.conf and merge it into the httpd.conf
for this apache. You do not need to put the proxy statements in, but you should
set you virtual servers, permissions on directories, etc so that this apache is
as secure as the other apache, the _only_ difference is that it listens on port
81, not 80, and it's got mod_perl compiled in.

(an easy, but potentially risky, way is to make a copy of the httpd.conf from the
'thin' apache, change every occurance of /apache to /apache_perl, then make the
change from port 80 to 81 ... and it should be ok... but check it LINE BY LINE!
You won't need PHP or Proxy in this version... You also might want to set the number
of servers to 5, and max to 10, etc... you don't need as many of these as your thin one)

This is _VERY_ important, since if you don't add in all your directory configurations,
and such, all your "locked" directories like the 'admin' are now unprotected ---

To check it, first start the 'fat' server

# cd /usr/local/apache/bin/
# apachectl start

Check it: http://www.yourdomain.com:81/cgi-bin/Links_Dir/admin/admin.cgi

(change that line to reflect where your Link SQL admin is).

You should see your admin screen with the flashing "WARNING" unless you set all
your directory permissions.



15) Now, you need to restart the "thin" server... this is the moment of truth!!

# cd /usr/local/apache/bin
# apachectl start

NOTE!!!! ---- NOTE!!! check your running processes (ps -ef on Solaris) to
to make sure you see BOTH your servers running!! You should see a bunch of
lines with:

/usr/local/apache/bin/httpd and lines with
/usr/local/apache_perl/bin/httpd

If you don't, make sure that your httpd.conf files are really different, and
you started apache from the correct ./bin directory, or by full path from OUTSIDE
the /usr/local tree.

16) The _final_ test is to check your proxy passing....

type http://www.yourdomain.com/perl/Links_dir/admin/admin.cgi

If you don't get anything, or an error, check your error log. IT might be permissions.
I can't use "localhost" on my machine for some unknown reason, I had to put my full
domain name in the ProxyPass statement. I know it's a problem in my configuration, since
I can't use it in a lot of places I should be able to, but using the fully qualified
domain name is not a problem, and is just as good.

17) I don't think I left anything I did out... and once I figure out a few things, it
really went fast. Post your questions/results to a new thread, the first of you
who dare to try it!



================
NOTE!! Let me know of any typos, errors, or such in this file. I'll edit them, so
this message is as correct as possible.

Please don't post to this thread, it will just confuse things.
Email me..... pugdog@ibm.net



------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/








Quote Reply
Re: mod_perl apache and thin apache - same machine - HOW -TO In reply to
NOTE: I have not yet changed the Links.pm file to reflect this.

That's tonight's project, and the FAQ will probably be running on dual apache by morning.

It looks like all that has to be changed is the following 2 lines:

Code:
# admin files are. No trailing slash.
$LINKS{admin_root_url} = "http://www.postcards.com/perl/FAQ/admin";

and

# This should be the URL to where your public cgi scripts are (add, modify, search).
$LINKS{db_cgi_url} = "http://www.postcards.com/perl/FAQ";

The /cgi-bin/ becomes /perl/ so that when it's replaced, all the http:// calls are directed to the mod_perl server.

The paths need to remain /cgi-bin/ since that is the actual location of the files.

Seems to be working on the FAQ:

www.postcards.com/FAQ/LinkSQL/

Let me know of any problems!

[This message has been edited by pugdog (edited January 27, 2000).]
Quote Reply
Re: mod_perl apache and thin apache - same machine - HOW -TO In reply to
On adding PHP to the "fat" apache... I thought about that.... For exactly those reasons.

(I didn't do it for convenience reasons, I needed my apache/php to work, whether I could get the mod_perl apache to work or not via proxy).

I'll try to polish the instructions, and give options once I make sure all the instructions work.

That way, there would be one very large Apache/perl/php, the lean apache.

Mod_perl and mod_php work well together, since I've seen the install instructions list both several times.

Actually, if that's what someone wants to do, just compile the "thin" apache with:

Code:
# ./configure --prefix=/usr/local/apache \
--enable-module=rewrite \
--enable-module=proxy

# make
# make install

Then reconfigure it:

Code:
# ./configure --prefix=/usr/local/apache_perl

to set the new default path. Follow the instructions for preparing mod_php, then follow the instructions for preparing mod_perl, then go back to the apache directory:

Code:
cd ../apache_1.3.11
# ./configure --prefix=/usr/local/apache_perl \
--activate-module=src/modules/php3/libphp3.a \
--activate-module=src/modules/perl/libperl.a \
--enable-module=rewrite

# make
# make install

And that should do it.

NOTE: I left the proxy out of the "fat" apache as suggested.

Alex suggested for safety to:

mv /usr/local/apache_perl/bin/httpd /usr/local/apache_perl/bin/httpd_perl

and

mv /usr/local/apache_perl/bin/apachectl
/usr/local/apache_perl/bin/perl_ctl

So you won't accidentally make the mistake of which daemon to start.





------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/






[This message has been edited by pugdog (edited January 28, 2000).]
Quote Reply
Re: mod_perl apache and thin apache - same machine - HOW -TO In reply to
Looks good! A couple points:

1. I would bother adding the --enable-module=proxy for the mod_perl server as it just adds to overhead and I doubt you'd use it.

2. It's useful to rename your httpd to httpd_perl or perl_httpd, and rename your apachectl to perlctl. This way you don't get the two servers mixed up. Make sure you edit thew new perlctl and change what httpd is called.

I've never tried this, but you might also want to throw php in your backend server for the same reasons we do this with perl. You can then use mod_rewrite to proxy back any php requests:

RewriteRule %{REQUEST_URI} \.php$ [P]

or something like that (been a while). Wink You then have a light apache that should be less then a meg (can get down to 500-600kb) that handles just graphics and static pages.

Cheers,

Alex
Quote Reply
Re: mod_perl apache and thin apache - same machine - HOW -TO In reply to
If anyone is interested, I recompiled the apaches, (once you know how, it's not hard <G> )

The file sizes changed as below:

=====================================

Compiled with PHP in the Thin, and mod_perl in the fat

-rwxr-xr-x 1 root other 1404196 Jan 27 05:54 httpd* -- thin

-rwxr-xr-x 1 root other 1631908 Jan 27 06:53 httpd_perl* -- fat

=====================================

Recompiled with nohing but the required modules in the 'thin' and mod_perl,mod_php,
and no proxy in the fat.

-rwxr-xr-x 1 root other 2137372 Jan 28 17:30 httpd* -- fat apache php & perl

-rwxr-xr-x 1 root other 818936 Jan 28 17:51 httpd* -- thin apache no php

=====================================


The total file size didn't change much, but the savings will be in total memory usage and CPU (less code to chug through).

If you run 5-10 copies of the "fat" server, you only load PHP 10 times, rather than keeping it in the thin server, where I usually keep 25 around, and have as many as 40 or 50 going most of the time.

This seems like a good tweak, now I need to figure out the proxy passing for PHP <G>





------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/