Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rawleyfowler/mojolicious-mod-perl-example
An example of running Mojolicious under Apache2 & mod_perl.
https://github.com/rawleyfowler/mojolicious-mod-perl-example
Last synced: 13 days ago
JSON representation
An example of running Mojolicious under Apache2 & mod_perl.
- Host: GitHub
- URL: https://github.com/rawleyfowler/mojolicious-mod-perl-example
- Owner: rawleyfowler
- Created: 2023-10-31T13:43:01.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-31T20:12:42.000Z (about 1 year ago)
- Last Synced: 2024-10-11T02:44:55.202Z (about 1 month ago)
- Language: Dockerfile
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Running mod_perl with Mojolicious in Docker
### Generate your config
Thanks to motemen for some nicely pre-configured
`mod_perl` and `Apache2` images.```
docker run --rm motemen/mod_perl:5.36.0-2.4.58 cat /usr/local/apache2/conf/httpd.conf > httpd.conf
echo 'Include /usr/local/apache2/conf/mojolicious.conf' >> httpd.conf
```### Enable Prefork MPM instead of Event MPM
In `httpd.conf`:
```apache
#LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
```### Write your application
In `lib/App.pm`:
```perl
package App;use 5.036;
use Mojolicious::Lite -signatures;
sub get_app { app; }
get '/' => sub {
shift->render( text => "Hello World!" );
};1;
```### Write your Plack shim
In `app.psgi`:
```perl
use 5.036;use lib 'lib';
use App;
use Plack::Builder;builder {
App::get_app->start;
};
```### Write your mod_perl apache conf
In `mojolicious.conf`:
```apache
LoadModule perl_module modules/mod_perl.so
SetHandler perl-script
PerlResponseHandler Plack::Handler::Apache2
PerlSetVar psgi_app /app.psgi
```
### Write your Dockerfile
In `Dockerfile`:
```docker
FROM motemen/mod_perl:5.36.0-2.4.58-2.0.13
COPY app.psgi /app.psgi
COPY lib /usr/local/apache2/lib
COPY httpd.conf /usr/local/apache2/conf/httpd.conf
COPY mojolicious.conf /usr/local/apache2/conf/mojolicious.conf
RUN apt-get update -y && apt-get install -y wget make build-essential
RUN cpan -iT Plack Mojolicious
EXPOSE 80
CMD ["httpd-foreground"]
```### Run with docker
```shell
$ docker build . -t mod-perl
$ docker run -p 80:80 mod-perl
$ curl http://localhost:80/
```You should see `Hello World!`.
### Running with auto-reloading (for development)
You can make this auto-reload if you use a volume for `lib/` against `/usr/local/apache2/lib/`
Originally posted on My Website.