Server - Contents

Mojolicious

revised:12-Jul-2021

Background

This Perl-base web framework is the outcome of the founders' best experiences with their earlier work with Catalyst, making it one of the most flexible and power in its field, providing users with both simplicity and complexity according to one's goals. Perl in its 5th version has had decades of mature development, offering a wide choice of tutorials, code snippets and modules to cover any task one might wish to accomplish. This writer seeks in its introduction to provide a relatively simple but extendable website that offers not only public pages but private ones as well for number of users that a webmaster can manage without the need of a database – ideal for a modest-sized institution or organisation.
Following login3 app is heavily indebted to the author, Sebastian Riedel of this example found at: login

Prerequisites: Basic Server (Debian 10.3 64bit) with Webmin, FTP, Firewall and [optional] iRedmail application: a server linked with a domain name (eg. myexample.com) and familiarity with creating and deploying a basic HTML website.

Note: Some basic knowledge in Perl would be useful – for starters, see Learn Perl in 2 hours 30 minutes Secondly, the current presentation presents a full Mojolicious app. However, Mojolicious Lite provides excellent means to learn and experiment with Mojolicious generally.

For a National Office or a Local Assembly seeking a more complex, adaptable website with private pages to authorized usertogether with the option to have a mail-form within (see Flask Mail and possibly including a Google map link, then Mojolicious (a perl-based environment) offers significant potential and ease.

As with the BasicSite, the setup proposed here is to have the Mojolicious website up and running first on the PC then to have the same site established on the server (running iRedmail/Nginx) with the two sites synchronized via FTP (eg. FileZilla)

Part A: Creating the Perl/Mojolicious Environment on the PC

Step01: Install Perl on a PC (Windows)
Following this link: Strawberry-Perl download and install the usual 64-bit version. It would be useful here to create a folder for Perl scripts under the Documents file; such as perlexamples.

Step02 Install Mojolicious
Install Mojolicous, opening 'PowerShell'[Win10] or in Win 7+, typing in 'cmd' after opening the Windows Start button.

perl -MCPAN -e shell // Its own shell command will open and type in the following:
install Mojolicious // allow time for the install.
install Crypt::Bcrypt::Easy // [optional] for the Login3 app.
exit // type this to return to PowerShell.

Step03: Create a Mojolicious App
In the Powershell, change to your perlexamples directory and type the following:

cd Documents\Scripts\perlexamples
mojo generate app MyApp
cd my_app
perl script/my_app daemon -l http://0.0.0.0:5000 // Go to browser via link at:- http://localhost:5000

Enter in the browser, type in this url: localhost:5000 (eg. http://localhost:5000),find a default Mojolicious welcome webpage. Type in the Powershell: 'ctl'+c to exit.

Step 4: Replace MyApp with Login3
From your perlexamples directory, remove MyApp and download login3.zip and unzipped it. Download as well this helper app login-helper.zip

cd login3
perl script/login_app daemon -l http://0.0.0.0:5000 // use 'john'and password 'a123s' to login.

Step 5: Modify Login3
a. The routes can be modified, added or removed making entries similar to those found in these two files: LoginApp.pm and in LoginApp/Controller/login.pm
b. The page content can be modified, added or removed their respective html.eps file in the templates directory with images, downloadable files placed in the public directory.
c. Users can be modified, added or removed in the hash $USERS found in LoginApp/Model/users.pm Hashed passwords can be provided with the login-helper app

Step06(Optional) Site with Email Contact Form
Where the website associated with a mailserver (eg. using iRedmail) and a contact form, then see the Mojo-Extras page

Mojolicious Mojo-PartB
Mojo-Deploy Mojo-Extras