Alpine Linux is a powerful ultra lightweight distro super popular for micro services such as Kubernetes and Docker.

Basically, it contains only the bare minimum to work and what is needed to know about it is mostly related to its package manager (APK) and init system (OpenRC).

Most basic commands:

apk update && apk upgrade
apk info
apk update
apk upgrade
apk search nano
apk add nano
apk del nano 
apk add --no-cache aws-cli
apk add mysql-client
apk add openssh-server
rc-service sshd start
rc-service sshd restart
rc-service sshd status
rc-update add sshd
rc-update -v show
netstat -tulpn
reboot
halt

The following tips work well Alpine v3.17.

NGINX + PHP8

apk add nginx php php-fpm php-opcache php-gd php-mysqli php-zlib php-curl
php -v
nginx -v
rc-update add nginx default
rc-update add php-fpm81 default
nano /etc/nginx/http.d/default.conf
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root    /var/www/default;

        index   index.html index.htm index.php;

        location ~ \.php$ {
                fastcgi_pass      127.0.0.1:9000;
                fastcgi_index     index.php;
                include           fastcgi.conf;
        }
}
service php-fpm81 restart
service nginx restart
echo "<?php echo 'PHP works!'; ?>" > /var/www/default/index.php
chown nginx: -R /var/www/*

CLOUDFLARE TUNNEL

For ADM

curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/bin/cloudflared

For ARM

curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64 -o /usr/bin/cloudflared

Then,

cloudflared service install ****************
service cloudflared start
rc-update add cloudflared default
cloudflared service uninstall

EXECUTING COMMANDS AFTER BOOT

nano /etc/local.d/rc.local.start
#!/bin/sh
echo "execute this after boot"
exit 0
chmod +x /etc/local.d/rc.local.start
rc-update add local

INSTALL MYSQL (MARIADB)

apk add mysql mysql-client
/etc/init.d/mariadb setup
/etc/init.d/mariadb start
mysql_secure_installation
rc-update add mariadb default

MSMTP WITH GMAIL + PHP CONFIG

apk add msmtp
nano /etc/msmtprc
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
account gmail
host smtp.gmail.com
port 587
from <USERNAME>@gmail.com
user <USERNAME>@gmail.com
password <PASSWORD>
account default : gmail
nano /etc/php81/php.ini
...
;SMTP = localhost
;smtp_port = 25
sendmail_path = “/usr/bin/msmtp -t”
...

OPENVPN SERVER IN LXC

On the Proxmox Host (if applicable).

modprobe tun
chown 100000:100000 /dev/net/tun
nano /etc/pve/lxc/100.conf

The CT number is 100 for this example. Append the following lines.

lxc.cgroup2.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net dev/net none bind,create=dir

On the guest CT.

apk add openvpn
rc-update add openvpn default

CRONTAB

Install, start and enable on boot.

apk add cronie
rc-service cronie start
rc-update add cronie

Edit the crontab file.

/etc/crontabs/root

Force it to reload by creating the following file.

touch /etc/crontabs/cron.update

Confirm the file has been automatically deleted (a confirmation that cron reloaded its table).

ls -la /etc/crontabs/cron.update

Show the list of loaded cronjobs.

crontab -l

Another way is to add scripts in one of the following directories according to the periodicity:

  • /etc/periodic/
    • 15min/
    • daily/
    • hourly/
    • monthly/
    • weekly/

The script shall not have any extension (e.g. /etc/periodic/month/backup). See template:

#!/bin/sh
echo `date`
# BACKUP COMMANDS
exit 0

Remember to mark the file as executable:

chmod +x /etc/periodic/month/backup

Again: the first line of the script must be #!/bin/sh and the filename shall NOT contain a period (.).

SETTING TIMEZONE

apk add tzdata
cp /usr/share/zoneinfo/America/Toronto /etc/localtime
date