The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
=head1 NAME

OpenResty::Spec::Install - Installation instructions for OpenResty servers

=head1 DESCRIPTION

This is a basic guideline for settting up an OpenResty server on your own machine. Someone has succeeded in setting up one on Windows XP using ActivePerl 5.8.8. The normal development environment is Linux though. If you have any particular question, feel free to ask us by sending an email to the authors.

=over

=item 1.

Grab the openresty package and unpack it to some place, let's say it's openresty.

=item 2.

Enter the openresty directory, run "perl Makefile.PL" to check missing dependencies:

    $ cd openresty
    $ perl Makefile.PL
    $ sudo make  # This will install missing dependencies
    $ make test  # run the test suite using the PgMocked backend

For the PostgreSQL database, you need to prepare a PostgreSQL account (e.g.
"agentzh"); and you need to create an empty database (e.g., "test"),
and you need to create a stored precedure language named "plpgsql" for that database,
contact your PostgreSQL DBA for it or read the PostgreSQL manual.

Normally, the following commands are used:

    $ createdb test
    $ createuser -P agentzh
    $ createlang plpgsql test

=item 3.

Edit your F<etc/site_openresty.conf> file, change the configure settings
under [backend] section according to your previous settings. The default settings look like this:

    [backend]
    recording=0
    # You should change the line below to type=Pg or type=PgFarm
    type=PgMocked
    host=localhost
    user=agentzh
    password=agentzh
    database=test

Most of the time, you need to change C<type=PgMocked> to C<type=Pg>, as well as the last 3 lines (unless you're using exactly the same user, password, and database name). The default "PgMocked" backend is a mocked PostgreSQL database which is useful only for testing purposes.

=item 4.

For the Pg backend, one needs to create the "anonymous" role in his database (like "test"):

    $ createuser -RSDL anonymous

You shouldn't grant any permissions to it.

=item 5.

Create a "tester" user account for our test suite in OpenResty (drop it if it already exists):

    $ bin/openresty deluser tester
    $ bin/openresty adduser tester

Give a password (say, "password") to its Admin role. Also create a second
user account "tester2":

    $ bin/openresty adduser tester2

Update your F<etc/site_openresty.conf> to reflect your these settings:

    [test_suite]
    use_http=0
    server=tester:password@localhost
    server2=tester2:password@localhost

You may have your own passwords here though.

=item 6.

To have OpenResty's built-in actions C<RunView> and C<RunAction> working, you
need to build the F<restyscript> compiler in the subdirectory F<haskell/>. It
is written in Haskell and please see the README file in F<haskell/> for
detailed installation instruction:

L<http://svn.openfoundry.org/openapi/trunk/haskell/README>

If you're really nervous about installing GHC and other Haskell libraries,
you can fetch a binary version of the F<restyscript> compiler if you're
on an 32-bit x86 linux:

    $ wget 'http://openresty.org/restyscript' -O haskell/bin/restyscript
    $ chmod +x haskell/bin/restyscript

A quick test would be

    $ echo 'select 3' | haskell/bin/restyscript view rs
    select 3

=item 7.

Now you can already run the test suite without an external HTTP server like Apache (but with a true Pg backend):

    $ make test

Also, it's already possible to start the OpenResty server using the standalone server provided by L<HTTP::Server::Simple>:

    $ bin/openresty start
    HTTP::Server::Simple: You can connect to your server at http://localhost:8000/

=item 8.

It's preferred to run OpenResty.pm as a FastCGI application under Apache2 or lighttpd. And Apache2 mod_fcgid is recommended.

See L<OpenResty::Spec::Install::Apache> For configuration docs for Apache. And see L<OpenResty::Spec::Install::Lighttpd> for configuration docs for Lighttpd.

=back

=head2 HOW TO TEST ONE SPECIFIC TEST SUITE FILE

It's also possible to debug a simple .t file, for instance,

    make t/01-sanity.t -f dev.mk

Or use the OPENRESTY_TEST_SERVER environment to test a remote OpenResty server, for example:

    OPENRESTY_TEST_SERVER=teser:password@10.62.136.86 prove -Ilib -r t

where 10.62.136.86 is the IP (or hostname or URL) of your OpenResty server
being tested.

To test the Pg cluster rather than the desktop Pg, update your F<etc/site_openresty.conf>:

    [backend]
    type=PgFarm

and also set other items in the same group if necessary.

=head1 SYSTEM-WIDE INSTALLATION

Some times it's desired to do "C<sudo make install>" and install all the OpenResty modules and command line tools to the system-wide perl.

The steps are simple:

=over

=item 1.

Build the C<haskell/bin/restyscript> program

=item 2.

The usual CPAN module installation process:

    perl Makefile.PL
    make
    sudo make install

=item 3.

Copy the config files to F</etc/openresty/>. Essentially, it is

    mkdir /etc/openresty
    cp etc/*.conf /etc/openresty/

=item 4.

Now you can test your installation by starting the standalone server for OPenResty:

    openresty start

=back

=head1 AUTHOR

Agent Zhang (agentzh) C<< <agentzh@yahoo.cn> >>,
Laser Henry (laser) C<< <laserhenry@gmail.com> >>.

=head1 SEE ALSO

L<openresty>, L<OpenResty::Config>, L<OpenResty::Spec::AccountAdmin>, L<OpenResty::Spec::Upgrading>, L<OpenResty::Spec::TestSuite>, L<OpenResty>.