Sign inSign up

martinh80/cronphp

By martinh80

•Updated 6 months ago

Run PHP scripts using cron, send errors via e-mail.

Image
Integration & delivery
Internet of things
Monitoring & observability
0

10K+

martinh80/cronphp repository overview

⁠What does this container image do?

It allows you to schedule your PHP scripts using cron and alert you via e-mail if something is wrong running your PHP scripts.

⁠Why did you create this image?

My home has solar panels which provides metrics through an API. In the beginning I created a VM on my FreeNAS. This VM ran several PHP scripts to retrieve data, store it in a local influxdb time series database and visualise it through Grafana dashboards. Going forward with new technologies available, I decided to migrate this to containers on TrueNAS Scale. Although Grafana and Influxdb container images are provided by these companies, I could not find a maintained container image for running PHP scripts through cron that also provided a way to send errors through e-mail. So I decided to build it myself and provide the solution to others.

⁠What does this container image contain?

It is based on Alpine linux, a very lightweight base image. On top of that PHP is installed, including the PHP-Curl and PHP-openssl libraries. It also adds mailx as a mail client and msmtp⁠ as a simple SMTP client. This allows the cron daemon to send e-mail of any errors during execution.

⁠How do I use it?

The image needs the following files/directories, just make sure to bind-mount them when you run the image

  • /scripts/, a directory that contains your PHP scripts
  • /crontab, a standard crontab⁠ file that on error sends e-mail to the local root user
  • /etc/msmtprc, the configuration file for the smtp client, which will forward mail to an upstream smtp server
  • /etc/aliases, the configuration file that tells the system what e-mail address to use for the local root user

⁠Example /crontab

MAILTO=root
*/1 * * * * /scripts/MyCustomPHPScript.php

⁠Example /etc/msmtprc

The msmtp project has proper documentation. This is the configuration I use with my gmail account.

# Set default values
defaults
auth    on
tls     on
tls_trust_file  /etc/ssl/certs/ca-certificates.crt
syslog  on

# Gmail
account gmail
host    smtp.gmail.com
port    587
from    [email protected]
user    [email protected]
password mypassword

# Set a default account
account default : gmail
aliases /etc/aliases

Note: you should never use your real password here. Make sure you have 2FA enabled in your gmail account, and create an appkey at https://myaccount.google.com/apppasswords⁠

⁠Example /etc/aliases

⁠Source code

This image is build from this public Github repo⁠.

Tag summary

Content type

Image

Digest

sha256:55639aa4c…

Size

16.3 MB

Last updated

6 months ago

docker pull martinh80/cronphp