Install LNMP on Alpine linux quickly

Alpine Linux is a lightweight, security-oriented Linux distribution based on musl libc and BusyBox. Some key things to know about Alpine Linux:

  • It’s designed to have a very small footprint, with the base image being only around 5MB in size. This makes it popular for use in containers and embedded systems.
  • It uses musl libc instead of glibc as its C library implementation. Musl is lighter weight than glibc.
  • The default package manager is apk, which allows installing, updating and removing packages in the .apk format.
  • It uses OpenRC as the init system instead of systemd, which helps reduce overhead.
  • Being security-focused, it applies proactive security patching and enables security hardening features by default.
  • Popular uses include running it as a lightweight container base image for Docker and Kubernetes, on embedded devices like routers, and on servers where minimal footprint is desired.
  • The official repositories contain over 13,000 packages, but the available packages are more limited than larger distros due to Alpine’s minimalism.

So in summary, Alpine emphasizes security and extreme compactness, making it well-suited for containerized environments and constrained hardware while still being a capable general-purpose Linux distribution.

Compared with Debian, both package manager and init system are different.

Here is a table to compare the apk package manager in Alpine Linux with the apt-get package manager used in Debian-based distributions like Ubuntu:

Featureapk (Alpine Linux)apt-get (Debian, Ubuntu)
Command Syntaxapk add packageapt-get install package
Update Repositoriesapk updateapt-get update
Upgrade Packagesapk upgradeapt-get upgrade
Remove Packageapk del packageapt-get remove package
Search Packagesapk search patternapt-cache search pattern
List Installedapk list --installeddpkg --list
Package Informationapk info packageapt-cache show package
Clean Cacheapk cache cleanapt-get clean
C Librarymusl libcglibc
Default Install Size~5MB~200MB+
Package Format.apk.deb
No. of Packages~13,000~51,000+ (Ubuntu)
Repositories/etc/apk/repositories/etc/apt/sources.list
Init SystemOpenRCsystemd (Ubuntu)

As the apk repositories is much smaller than the apt-get, so it is very important to choose the repositories address.

Go to https://pkgs.alpinelinux.org/ and search the package you want, get the branch name.

Go to https://mirrors.alpinelinux.org/ to choose a fast mirror and configure it.

nano /etc/apk/repositories
http://ftp.udx.icscoe.jp/Linux/alpine/edge/main
http://ftp.udx.icscoe.jp/Linux/alpine/edge/community
http://ftp.udx.icscoe.jp/Linux/alpine/edge/testing

# for PHP7

http://ftp.udx.icscoe.jp/Linux/alpine/v3.14/community/
http://ftp.udx.icscoe.jp/Linux/alpine/v3.14/main/
http://ftp.udx.icscoe.jp/Linux/alpine/v3.14/releases/

Here’s a table comparing the OpenRC init system used in Alpine Linux and the systemd init system used in many other Linux distributions:

FeatureOpenRCsystemd
Init System TypeDependency-basedParallelized
Service Managementrc-service commandsystemctl command
Service DefinitionScripts in /etc/init.dUnit files in /etc/systemd/system
Dependency HandlingDependency treeDeclarative dependencies
Process SupervisionTraditional Unix processesCgroups for process tracking
Boot ProcessSequential startupParallel startup
System LoggingTraditional syslogJournal for system logs
Additional Componentssystemd-logind, systemd-networkd, etc.
Resource UsageLightweightMore resource-intensive
Compatibility Layersystemd-sysv for SysV init scripts
Service Monitoringcronie, syslog-ngsystemd-journald, systemd-timesyncd
Adopted ByGentoo, Alpine LinuxRedHat, Debian, Arch Linux, Ubuntu
Start Servicerc-service <service> startsystemctl start <service>
Stop Servicerc-service <service> stopsystemctl stop <service>
Restart Servicerc-service <service> restartsystemctl restart <service>
Check Service Statusrc-service <service> statussystemctl status <service>

The status command is used to check the current running status of a service.

Here is the script to install the LNMP on alpine linux.

apk update
apk upgrade
apk add nginx
apk add mysql mysql-client
#apk add mariadb mariadb-client (the same)
apk add php7-fpm php7-mcrypt php7-soap php7-openssl php7-gmp php7-pdo_odbc php7-json php7-dom php7-pdo php7-zip php7-mysqli php7-sqlite3 php7-apcu php7-pdo_pgsql php7-bcmath php7-gd php7-odbc php7-pdo_mysql php7-pdo_sqlite php7-gettext php7-xmlreader php7-xmlrpc php7-bz2 php7-iconv php7-pdo_dblib php7-curl php7-ctype

rc-service nginx start
rc-service php-fpm7 start
rc-service mariadb start


Leave a Comment