install apache mason

来源:互联网 发布:西方主要哲学流派 知乎 编辑:程序博客网 时间:2024/05/17 05:14

What is mason?  http://www.masonhq.com/

Why mason? You are a PERL fan like me.


1. download Apache and make

wget http://www.apache.org/dist/httpd/httpd-2.2.21.tar.bz2

tar xjvf httpd-2.2.21.tar.bz2

./configure --prefix=/home/$USER/local/httpd \
    --enable-so    \
    --enable-cgi \
    --enable-info \
    --enable-rewrite \
    --enable-speling \
    --enable-usertrack \
    --enable-deflate \
    --enable-ssl \
    --enable-mime-magic \
    --enable-dav \
    --with-ssl=/usr/local/ssl

make && make install

If you have question when installing apache, google it. It is not the focus of this article. Make sure --enable-so and --enable-dav is in the option list.

2. download perl and make

I don't want to talk deeper about it, either. Go to http://www.perl.org/get.html and download a latest version. I used perl-5.14.2. There are tons of articles talking about how to install perl. But I suggest you should read the INSTALL file in perl-5.14.2.tar.gz firstly. Generally speaking, you can make perl by the commands below.

   sh Configure --help

   sh Configure -d  # withou the -d options, you have to press enter lots of times.
   make
   make test
   make install


3. make  mod_perl

Go to http://perl.apache.org/download/index.html. Download the latest version of mod_perl. I chose mod_perl-2.0.5 because I setup Apache 2.

   wget http://perl.apache.org/dist/mod_perl-2.0-current.tar.gz

   tar xzvf .....

   perl Makefile.PL MP_APXS=/home/cydoo/local/httpd/bin/apxs

   make && make install

   file ~/local/httpd/modules/mod_perl.so

If you didn't install a new Apache as I did. You should pay attention. If you are using a pre-packaged Apache, you should read here http://perl.apache.org/docs/2.0/user/install/install.html#Dynamic_mod_perl.


4. Make mason.

Mason is something like PHP in PERL world. If you are a java developer, you can take it as freemaker, velocity, facelet or tiles. A template language and you can separate your business service from web layer. I don't want to dig deep why we need web layer. If you application is big enough, and you want to speed up when generating HTML. You will like to create a web layer for your application.

You can install mason with one line command: $PERL_HOME/bin/cpan HTML::Mason. But I choose to install it from svn.

   svn co https://svn.urth.org/svn/Mason/trunk Mason-trunk   
   cd Mason-trunk
   perl Build.PL
   ./Build
   ./Build install
5. Enable mason preprocessor in Apache.
vi $APACHE_HOME/conf/httpd.conf, add the following lines into httpd.conf
LoadModule perl_module        modules/mod_perl.so                                               
PerlModule HTML::Mason::ApacheHandler

AddHandler perl-script        .mi
AddHandler perl-script        .mason
PerlHandler HTML::Mason::ApacheHandler

DirectoryIndex index.html index.mi

DirectoryIndex index.html index.mason

6. Test if it works.

$APACHE_HOME/bin/apachectl restart

http://localhost:8000           # you can change you LISTEN port in httpd.conf

The page will tell you "It works". It means Apache works.

After then, create a index.mi in htdocs.

   mv index.html index.html.ori

   echo 'Greetings, <% ("Earthlings", "Martians")[rand 2] %>' > index.mi

Visit http://localhost:8000 again, you will get what you are looking for.

There is a sample folder in svn. You can start mason from there. Good luck.


7. Postscripts 

Install Mason on Ubutu again.

cat /etc/lsb-release DISTRIB_ID=UbuntuDISTRIB_RELEASE=12.04DISTRIB_CODENAME=preciseDISTRIB_DESCRIPTION="Ubuntu 12.04.3 LTS"sudo apt-get install libboost-thread-dev# install perlwget    http://www.cpan.org/src/5.0/perl-5.12.5.tar.gz• CFLAGS='-m64 -mtune=nocona' ./Configure -des -A ccflags=-fPIC -Dusethreads  -Dprefix=$HOME/local/perl-5.12.5   # for 64 bit system• ./Configure -des -Dusethreads  -Dprefix=$HOME/local/perl-5.12.5   # for 32bit systemmake testmake install# Add perl into your path.# Install apache  http://tr.im/4d685 (omitted, -v 2.2.23)./configure --enable-so --enable-ssl --with-ssl=$HOME/local/openssl  \                     --enable-mods-shared=all --enable-cgi --enable-rewrite  \                     --enable-info \                     --enable-speling \                     --enable-usertrack \                     --enable-deflate \                     --enable-mime-magic \                     --enable-dav \                     --prefix=$HOME/local/httpd && make && make install # install mod_perl# Prerequisites, http://tr.im/4d674. Double check if you have time.perl -MCPAN -e 'install("threads.pm")'   # shellperl -MCPAN -e 'install("Compress::Zlib")'wget http://perl.apache.org/dist/mod_perl-2.0.7.tar.gzperl Makefile.PL MP_APXS=$HOME/local/httpd/bin/apxs && make && make installls `$HOME/local/httpd/bin/apxs -q LIBEXECDIR`/mod_perl.so# Add the line      "LoadModule perl_module modules/mod_perl.so" into $HOME/local/httpd/conf/httpd.conf# install masonsvn co https://svn.urth.org/^Cn/Mason/tags/release-1.33 mason-1.33perl -MCPAN -e 'install("Params::Validate")' && \    perl -MCPAN -e 'install("Exception::Class")' && \    perl -MCPAN -e 'install("Class::Container")' && \    perl -MCPAN -e 'install("File::Spec")' && \    perl -MCPAN -e 'install("Scalar::Util")'  && \    perl -MCPAN -e 'install("Cache::Cache")' && \    perl -MCPAN -e 'install("CGI.pm")'perl Build.PL &&   ./Build    &&    ./Build install# Add the following lines into $HOME/local/httpd/conf/httpd.conf<IfModule perl_module>    PerlModule HTML::Mason::ApacheHandler                                                                                                AddHandler perl-script        .m    AddHandler perl-script        .mi    AddHandler perl-script        .mason    PerlHandler HTML::Mason::ApacheHandler    DirectoryIndex index.html index.m    DirectoryIndex index.html index.mi    DirectoryIndex index.html index.mason</IfModule># Verifyecho 'Greetings, <% ("Earthlings", "Martians")[rand 2] %>' > $HOME/local/httpd/htdocs/index.mi$HOME/local/httpd/bin/apachectl restarthttps://yourhost:8000/


原创粉丝点击