Perl hosting for beginners - Cluj.pm March 2013

6,969 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
6,969
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Perl hosting for beginners - Cluj.pm March 2013

  1. 1. Perl web hosting for beginners Árpád Szász Freelance Perl Developer Twitter: @arpadszasz Blog: http://arpi.plenum.ro
  2. 2. Background ● Programming newbie
  3. 3. Background ● Programming newbie ● Want to host a simple dynamic website
  4. 4. Background ● Programming newbie ● Want to host a simple dynamic website ● Process must be easy
  5. 5. Background ● Programming newbie ● Want to host a simple dynamic website ● Process must be easy ● Using Microsoft Windows as a workstation
  6. 6. 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
  7. 7. Why use Perl? ● Perl makes easy things easy and hard things possible
  8. 8. 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)
  9. 9. 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
  10. 10. Why use shared hosting? ● Inexpensive
  11. 11. Why use shared hosting? ● Inexpensive ● Easy to setup
  12. 12. Strawberry Perl ● Perl distribution for Windows
  13. 13. Strawberry Perl ● Perl distribution for Windows ● Available at http://strawberryperl.com/
  14. 14. Strawberry Perl ● Perl distribution for Windows ● Available at http://strawberryperl.com/ ● Up to date (Perl version 5.16.3)
  15. 15. Apache ● Most popular web server
  16. 16. Apache ● ● Most popular web server Windows binaries available at http://httpd.apache.org/download.cgi
  17. 17. Mojolicious ● Next generation web framework
  18. 18. Mojolicious ● ● Next generation web framework Easy to deploy (only dependent on core Perl 5)
  19. 19. Mojolicious ● ● Next generation web framework Easy to deploy (only dependent on core Perl 5) – download from https://github.com/jamadam/mojo-legacy
  20. 20. 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
  21. 21. 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>
  22. 22. Configuring Apache ● Allow the use of .htaccess files ● Enable mod_rewrite LoadModule rewrite_module modules/mod_rewrite.so
  23. 23. 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');
  24. 24. 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 ...
  25. 25. Configuring .htaccess file ● Execute Perl programs as CGI AddHandler cgi-script .pl Options +ExecCGI
  26. 26. Configuring .htaccess file ● Execute Perl programs as CGI ● Route all requests to Mojolicious app RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ app.pl/$1 [L,QSA]
  27. 27. 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>
  28. 28. 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
  29. 29. Configure templates Add HTML markup to templates ● <h1>Welcome!</h1> <p> Hello and welcome to our silly website. </p>
  30. 30. 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>
  31. 31. Deploy ● Transfer contents of htdocs using FTP to server
  32. 32. Deploy ● ● Transfer contents of htdocs using FTP to server Access the application on the server via CGI
  33. 33. Questions?
  34. 34. Thank You! Talk and code available at https://github.com/arpadszasz/perl-hosting-beginners-talk

×