perl hosting for beginners - cluj.pm march 2013

34
Perl web hosting for beginners Árpád Szász Freelance Perl Developer Twitter: @arpadszasz Blog: http://arpi.plenum.ro

Upload: arpad-szasz

Post on 15-Jan-2015

6.419 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Perl hosting for beginners - Cluj.pm March 2013

Perl web hostingfor beginners

Árpád SzászFreelance Perl Developer

Twitter: @arpadszaszBlog: http://arpi.plenum.ro

Page 2: Perl hosting for beginners - Cluj.pm March 2013

Background

● Programming newbie

Page 3: Perl hosting for beginners - Cluj.pm March 2013

Background

● Programming newbie● Want to host a simple dynamic website

Page 4: Perl hosting for beginners - Cluj.pm March 2013

Background

● Programming newbie● Want to host a simple dynamic website● Process must be easy

Page 5: Perl hosting for beginners - Cluj.pm March 2013

Background

● Programming newbie● Want to host a simple dynamic website● Process must be easy● Using Microsoft Windows as a workstation

Page 6: Perl hosting for beginners - Cluj.pm March 2013

Background

● Programming newbie● Want to host a simple dynamic website● Process must be easy● Using Microsoft Windows as a workstation● Using GNU/Linux on the server side

Page 7: Perl hosting for beginners - Cluj.pm March 2013

Why use Perl?

● Perl makes easy things easy and hard things possible

Page 8: Perl hosting for beginners - Cluj.pm March 2013

Why use Perl?

● Perl makes easy things easy and hard things possible

● Perl is available by default on every shared host provider's servers (GNU/Linux)

Page 9: Perl hosting for beginners - Cluj.pm March 2013

Why use Perl?

● Perl makes easy things easy and hard things possible

● Perl is available by default on every shared host provider's servers (GNU/Linux)

● Perl is Modern

Page 10: Perl hosting for beginners - Cluj.pm March 2013

Why use shared hosting?

● Inexpensive

Page 11: Perl hosting for beginners - Cluj.pm March 2013

Why use shared hosting?

● Inexpensive● Easy to setup

Page 12: Perl hosting for beginners - Cluj.pm March 2013

Strawberry Perl

● Perl distribution for Windows

Page 13: Perl hosting for beginners - Cluj.pm March 2013

Strawberry Perl

● Perl distribution for Windows● Available at http://strawberryperl.com/

Page 14: Perl hosting for beginners - Cluj.pm March 2013

Strawberry Perl

● Perl distribution for Windows● Available at http://strawberryperl.com/ ● Up to date (Perl version 5.16.3)

Page 15: Perl hosting for beginners - Cluj.pm March 2013

Apache

● Most popular web server

Page 16: Perl hosting for beginners - Cluj.pm March 2013

Apache

● Most popular web server● Windows binaries available at

http://httpd.apache.org/download.cgi

Page 17: Perl hosting for beginners - Cluj.pm March 2013

Mojolicious

● Next generation web framework

Page 18: Perl hosting for beginners - Cluj.pm March 2013

Mojolicious

● Next generation web framework● Easy to deploy (only dependent on core Perl

5)

Page 19: Perl hosting for beginners - Cluj.pm March 2013

Mojolicious

● Next generation web framework● Easy to deploy (only dependent on core Perl

5)– download from

https://github.com/jamadam/mojo-legacy

Page 20: Perl hosting for beginners - Cluj.pm March 2013

Mojolicious

● Next generation web framework● Easy to deploy (only dependent on core Perl

5)– download from

https://github.com/jamadam/mojo-legacy

– extract lib folder from archive to Apache's htdocs folder

Page 21: Perl hosting for beginners - Cluj.pm March 2013

Configuring Apache

● Allow the use of .htaccess files<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">

AllowOverride All

Options FollowSymlinks

Order allow,deny

Allow from all

</Directory>

Page 22: Perl hosting for beginners - Cluj.pm March 2013

Configuring Apache

● Allow the use of .htaccess files● Enable mod_rewrite

LoadModule rewrite_module modules/mod_rewrite.so

Page 23: Perl hosting for beginners - Cluj.pm March 2013

Configuring Mojolicious app

● Goes into Apache's htdocs folder as app.pl#!perl

use 5.10.1;

use strict;

use lib qw(lib);

use Mojolicious::Lite;

get '/' => sub {

return shift->render('index');

};

get '/*page' => sub {

my $self = shift;

return $self->render( $self->param('page') );

};

app->start('cgi');

Page 24: Perl hosting for beginners - Cluj.pm March 2013

Configuring Mojolicious app

● Goes into Apache's htdocs folder as app.pl● Templates go into htdocs/templates

htdocs/templates/index.html.ep

htdocs/templates/contact.html.ep

...

Page 25: Perl hosting for beginners - Cluj.pm March 2013

Configuring .htaccess file

● Execute Perl programs as CGI

AddHandler cgi-script .plOptions +ExecCGI

Page 26: Perl hosting for beginners - Cluj.pm March 2013

Configuring .htaccess file

● Execute Perl programs as CGI● Route all requests to Mojolicious app

RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ app.pl/$1 [L,QSA]

Page 27: Perl hosting for beginners - Cluj.pm March 2013

Configuring .htaccess file

● Execute Perl programs as CGI● Route all requests to Mojolicious app● Deny listing of templates

<FilesMatch ".html.ep"> Order deny,allow Deny from all</FilesMatch>

Page 28: Perl hosting for beginners - Cluj.pm March 2013

Configuring .htaccess file

● Execute Perl programs as CGI● Route all requests to Mojolicious app● Deny listing of templates● Directory index points to app

DirectoryIndex app.pl

Page 29: Perl hosting for beginners - Cluj.pm March 2013

Configure templates

● Add HTML markup to templates<h1>Welcome!</h1>

<p>

Hello and welcome to our silly website.

</p>

Page 30: Perl hosting for beginners - Cluj.pm March 2013

Configure templates

● Add HTML markup to templates● Add Perl code to templates

<h1>Welcome!</h1>

<p>

Hello and welcome to our silly website. Server time is: <%= time %>

</p>

Page 31: Perl hosting for beginners - Cluj.pm March 2013

Deploy

● Transfer contents of htdocs using FTP to server

Page 32: Perl hosting for beginners - Cluj.pm March 2013

Deploy

● Transfer contents of htdocs using FTP to server

● Access the application on the server via CGI

Page 33: Perl hosting for beginners - Cluj.pm March 2013

Questions?

Page 34: Perl hosting for beginners - Cluj.pm March 2013

Thank You!

Talk and code available athttps://github.com/arpadszasz/perl-hosting-beginners-talk