How to install the web framework Mojolicious and run the web application
Learn how to install the web framework Mojolicious and run web applications. In the introduction to Ubuntu server construction, we will disclose the minimum knowledge necessary for building an environment for developing Perl Web systems.
Prerequisites for installing the web framework Mojolicious
As a prerequisite to installing the web framework Mojolicious, the users Perl and cpanm must be installed.
Installing the web framework Mojolicious
Install the web framework Mojolicious.
cpanm Mojolicious
Make sure you have Mojolicious installed. It's okay if no error occurs.
perl -e'use Mojolicious'
The smallest Mojolicious application
Let's create a Mojolicious application.
Save the following Mojolicious program as "myapp.pl".
use Mojolicious::Lite; get'/' => {text =>'Hello World!'}; app->start;
Launch a web application for the development environment
The morbo command launches the web application in the development environment.
morbo myapp.pl
The web application starts on port 3000.
Web application available at http://127.0.0.1:3000
127.0.0.1 is the address of the local server. Change this part to the IP address of your server and access it from your browser.
If port 3000 is not open on your VPS or cloud server, you will not be able to access it, so allow port 3000.
The following example is an example where the IP address of the server is "59.105.185.197".
http://59.105.185.197:3000
If "Hello World!" Is displayed on the screen, it is successful.
Launch a web application for production environment
Next, let's start the web application for the production environment. The hypnotoad command launches the web application for production.
hypnotoad myapp.pl
The web application starts on port 8080.
Web application available at http://127.0.0.1:8080
When you reboot, try again.
hypnotoad myapp.pl
Use the "--stop" option to stop.
hypnotoad --stop myapp.pl
Connect Mojolicious apps from a reverse proxy
In the production environment, connect the web application started by hypnotoad from a web server such as Apache with a reverse proxy.
Please refer to the following for this procedure.