Run PHP scripts using cron, send errors via e-mail.
10K+
It allows you to schedule your PHP scripts using cron and alert you via e-mail if something is wrong running your PHP scripts.
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.
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.
The image needs the following files/directories, just make sure to bind-mount them when you run the image
MAILTO=root
*/1 * * * * /scripts/MyCustomPHPScript.php
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
This image is build from this public Github repo.
Content type
Image
Digest
sha256:55639aa4c…
Size
16.3 MB
Last updated
6 months ago
docker pull martinh80/cronphp