Ph
Networking Azure

phpIPAM on Ubuntu 24.04 on Azure User Guide

| Product: phpIPAM on Ubuntu 24.04 on Azure

Overview

phpIPAM is an open source web application for IP address management (IPAM). It keeps track of IPv4 and IPv6 subnets and the addresses in them, VLANs, VRFs, devices, NAT rules and circuits, scans subnets for hosts that answer, and offers a REST API for automation.

This image runs the official phpIPAM 1.9.2 release on Ubuntu 24.04 LTS, served by Apache with PHP 8.3, with its database in MariaDB on the same virtual machine. It is installed the way the phpIPAM documentation describes, and the web installer is switched off.

Nothing is shared between virtual machines. On the first boot of your virtual machine a one time service creates the phpIPAM database, sets a new password for phpIPAM's Admin account and a new password for the database account, makes a TLS certificate for the virtual machine's address and writes the passwords to /root/phpipam-credentials.txt, readable by root only. The web server starts only after that service has finished, so phpIPAM is never served with a default password.

The image also ships with:

  • HTTPS on port 443 from the first boot; port 80 redirects to HTTPS
  • MariaDB listening on the virtual machine only (127.0.0.1)
  • Apache and MariaDB blocked from reaching the Azure instance metadata endpoint and the WireServer
  • phpIPAM's host status checks and discovery scans scheduled every 15 minutes (they act only on subnets where you switch them on)
  • Ubuntu's unattended security upgrades switched on

The default operating system user is the administrator account you choose when you create the virtual machine (azureuser in the examples below). phpIPAM's code is in /var/www/phpipam and its web root is /var/www/phpipam/public.

Prerequisites

  • A Microsoft Azure subscription in which you can create resource groups, virtual networks and virtual machines
  • An SSH key pair for the administrator account
  • A network security group that allows inbound TCP 22 from your own network, and TCP 443 (and 80, which redirects to HTTPS) from the networks your team uses
  • The Azure CLI (az) if you deploy from the command line

The recommended size is Standard_B2s (2 vCPUs, 4 GiB memory). It is plenty for thousands of subnets; choose a larger size if you scan many large subnets often.

Step 1: Deploy the Virtual Machine

Option A: the Azure Portal

  1. Sign in to the Azure Portal, open Marketplace, search for phpIPAM on Ubuntu 24.04 by cloudimg and select Create.
  2. On Basics choose your subscription, a resource group, a region and a name, and pick Standard_B2s or larger. Under Administrator account choose SSH public key and enter your user name and key.
  3. Under Inbound port rules allow SSH (22), HTTP (80) and HTTPS (443). Limit SSH and HTTPS to your own networks on the Networking tab afterwards: phpIPAM holds your network plan.
  4. Select Review + create, then Create.

First boot finishes about a minute after the virtual machine shows Running.

Option B: the Azure CLI

Accept the Marketplace terms once per subscription, then create the virtual machine. Replace <your-mgmt-cidr> with the network you connect from, for example 203.0.113.0/24.

az vm image terms accept --urn cloudimg1647283583153:phpipam:default:latest

RG=phpipam-rg
az group create --name $RG --location eastus
az vm create \
  --resource-group $RG \
  --name phpipam-01 \
  --image cloudimg1647283583153:phpipam:default:latest \
  --size Standard_B2s \
  --admin-username azureuser \
  --ssh-key-values ~/.ssh/id_rsa.pub \
  --public-ip-sku Standard \
  --nsg-rule NONE
az network nsg rule create --resource-group $RG --nsg-name phpipam-01NSG \
  --name AllowMgmt --priority 1000 --access Allow --protocol Tcp \
  --direction Inbound --source-address-prefixes <your-mgmt-cidr> --destination-port-ranges 22 80 443

Step 2: Connect to the Virtual Machine

Find the public IP address, then connect over SSH:

az vm show --resource-group phpipam-rg --name phpipam-01 --show-details --query publicIps -o tsv
ssh azureuser@<public-ip>

The message of the day shows the web address and where the credentials are:

  phpIPAM 1.9.2 on Ubuntu 24.04 (cloudimg)
  Web interface:     https://203.0.113.10/
  Admin credentials: sudo cat /root/phpipam-credentials.txt
  Change address:    sudo cloudimg-set-public-address <ip-or-dns-name>
  User guide:        https://www.cloudimg.co.uk/guides/phpipam-on-ubuntu-24-04-azure/

Check that the services are running and that phpIPAM answers:

systemctl is-active apache2 mariadb cron
sudo mariadb -N -e 'SELECT version, dbversion FROM phpipam.settings'
curl -sk -o /dev/null -w '%{http_code}\n' https://127.0.0.1/healthz
active
active
active
1.92    48
200

The database reports phpIPAM's schema version (1.92, for release 1.9.2) and its schema revision.

phpIPAM services, versions and health check on a new VM

Step 3: Read the Admin Credentials

sudo cat /root/phpipam-credentials.txt

The file holds the web address, the phpIPAM user name (Admin) and its password, and the database account phpIPAM uses, all created on this virtual machine (the passwords are masked here):

# phpIPAM 1.9.2 - generated on first boot by phpipam-firstboot.service. Unique to this VM; store it safely.
PHPIPAM_URL=https://203.0.113.10/
PHPIPAM_ADMIN_USER=Admin
PHPIPAM_ADMIN_PASSWORD=************************

# MariaDB (on this VM only; phpIPAM signs in over the local socket). Root: sudo mariadb
PHPIPAM_DB_NAME=phpipam
PHPIPAM_DB_USER=phpipam
PHPIPAM_DB_PASSWORD=************************

# Sign in at PHPIPAM_URL as Admin, then change the password under your user menu > Edit profile.
# The certificate is self-signed and made for this VM: your browser warns until you install your own.
# Use your own DNS name or another address:  sudo cloudimg-set-public-address ipam.example.com
# User guide: https://www.cloudimg.co.uk/guides/phpipam-on-ubuntu-24-04-azure/

Store the passwords in a password manager. You only need the database password if you connect to MariaDB as the phpipam user yourself; sudo mariadb always works for root.

The per VM credentials file and its permissions

Step 4: Sign in to phpIPAM

Open https://<public-ip>/ in your browser. The certificate is a self-signed one made for this virtual machine, so the browser warns once; accept it to continue, or install your own certificate first (step 9). phpIPAM opens its sign-in page.

The phpIPAM sign-in page served over HTTPS on first boot

Sign in as Admin with the password from the credentials file. phpIPAM blocks an address for five minutes after five failed sign-ins in a row.

Step 5: The Dashboard

After you sign in, phpIPAM opens its dashboard. The menu on the top bar holds Subnets, VLAN and VRF, the Tools menu (search, devices, NAT, scans, changelog and more) and, for administrators, Administration. Your user menu at the top right holds Edit profile and Logout.

The phpIPAM dashboard after the first sign in

Change the Admin password now: open the user menu, choose Edit profile, enter a new password twice and save. Give each colleague their own account under Administration > Users rather than sharing Admin.

Step 6: Sections and Subnets

phpIPAM groups subnets into sections. A new installation comes with phpIPAM's own example data: a Customers section with a 10.10.0.0/16 subnet and two /24 customer subnets, an IPv6 section and two example VLANs. Use them to look around, then delete them or rename them for your own network.

The subnets in the Customers section

To add your own:

  1. Open Administration > Sections and select Add section. Give it a name, for example Azure or Data centre.
  2. Open the new section from Subnets, then Add subnet. Enter the network in CIDR form (for example 10.20.0.0/16), a description and, if you use them, a VLAN and a VRF. Subnets you add inside a larger one are nested under it.
  3. Open a subnet to see its address table. Select Add new IP address, or select a free address in the subnet map, to record an address with its host name, owner, device and description.

A subnet's IP address table with its usage map

Each subnet shows its usage, the free addresses and the first free one, so you can allocate without overlap.

Step 7: Scan Subnets for Hosts

phpIPAM can check which recorded addresses answer (host status checks) and find new hosts in a subnet (discovery). Both are off for each subnet until you turn them on: edit a subnet and switch on Check hosts status and Discover new hosts. The scans run from this virtual machine every 15 minutes, as the www-data user:

cat /etc/cron.d/phpipam

The scan method is set under Administration > phpIPAM settings (Ping by default; fping is installed for faster scans of large subnets). A scan reaches only the networks this virtual machine can route to, for example the virtual network it is in and networks peered with it or reached through a VPN gateway.

Step 8: Serve phpIPAM on Your Own DNS Name

On first boot phpIPAM's site address (and the certificate) is the public IP address Azure reports for the virtual machine. To use a DNS name instead, point an A record at the public IP address, then run:

sudo cloudimg-set-public-address <your-domain>

The command makes a new self-signed certificate for that name, sets phpIPAM's Site URL to https://<your-domain>/, updates the credentials file and the message of the day, and restarts Apache. Run it again with the public IP address to go back. phpIPAM builds its links from the address in your browser, so it also answers on any other name or address that reaches the virtual machine.

The site address, phpIPAM's Site URL, and the certificate made for it

Step 9: Install Your Own TLS Certificate

Apache reads the certificate from /etc/ssl/phpipam/phpipam.crt and the key from /etc/ssl/phpipam/phpipam.key. Set your DNS name first (step 8), because cloudimg-set-public-address replaces the certificate with a new self-signed one. With the DNS name set you can get a free Let's Encrypt certificate. Port 80 must be open to the Internet while certbot runs, and Apache is stopped for the few seconds it needs:

sudo apt-get install -y certbot
sudo certbot certonly --standalone -d <your-domain> -m <your-email> --agree-tos -n \
  --pre-hook 'systemctl stop apache2' --post-hook 'systemctl start apache2' \
  --deploy-hook 'install -m 0644 $RENEWED_LINEAGE/fullchain.pem /etc/ssl/phpipam/phpipam.crt; install -m 0600 $RENEWED_LINEAGE/privkey.pem /etc/ssl/phpipam/phpipam.key'

The deploy hook copies each renewed certificate into place, and certbot's own timer renews it before it expires.

Step 10: Back Up and Upgrade

Back up the database and phpIPAM's configuration file together:

sudo mariadb-dump --single-transaction phpipam > <backup-dir>/phpipam.sql
sudo cp /var/www/phpipam/config.php <backup-dir>/

Copy both files off the virtual machine, for example to Azure Blob Storage. Azure Backup can also take scheduled snapshots of the whole virtual machine. phpIPAM can also export subnets and addresses to spreadsheets from Administration > Import / Export.

Ubuntu's unattended upgrades install security updates every day, Apache, PHP and MariaDB included. To install every pending update yourself:

sudo apt-get update && sudo apt-get -y upgrade

phpIPAM itself is upgraded from the official release on GitHub (https://github.com/phpipam/phpipam/releases). Take a backup first, then unpack the new release next to the old one, copy your config.php into it, install its PHP libraries with Composer, swap the directories and open phpIPAM in the browser: it offers to upgrade the database. The release's UPDATE.md file describes each step. Composer is not installed on the image; use the composer.phar from https://getcomposer.org/download/ for the upgrade.

Server Components

Component Version Notes
phpIPAM 1.9.2 Official release, /var/www/phpipam (web root /var/www/phpipam/public)
Apache 2.4.58 HTTPS on 443, port 80 redirects to HTTPS
PHP 8.3.6 Ubuntu 24.04 packages, mod_php with OPcache
MariaDB 10.11.14 Ubuntu 24.04 packages, 127.0.0.1 only
Ubuntu 24.04 LTS Azure kernel 6.8, unattended security upgrades on

Filesystem Layout

Mount Size What is there
/ 30 GB OS disk (29 GB root partition) Ubuntu, phpIPAM in /var/www/phpipam, the MariaDB data in /var/lib/mysql
/boot 881 MB Kernels
/boot/efi 105 MB EFI system partition
/mnt Azure temporary disk (size depends on the VM size) Scratch space only: Azure may wipe it on a stop, resize or redeploy. Never keep phpIPAM data here

Managing the Services

sudo systemctl status apache2 mariadb --no-pager
sudo systemctl restart apache2

phpIPAM's settings live in its database and are changed from Administration in the web interface. The database connection is in /var/www/phpipam/config.php (readable by root and the web server only).

Scripts and Log Files

Path What it does
/usr/local/sbin/phpipam-firstboot.sh First boot: creates the database, sets the Admin and database passwords, makes the certificate, writes the credentials file, then records /var/lib/cloudimg/phpipam-firstboot.done
/usr/local/sbin/cloudimg-set-public-address Moves the site to another DNS name or address (step 8)
/root/phpipam-credentials.txt The web address and the passwords (root only)
/etc/cron.d/phpipam The host status and discovery scans (step 7)
/var/log/phpipam-firstboot.log The first boot log
/var/log/apache2/ Apache access and error logs
/var/log/mysql/ MariaDB logs

On Startup

On the first boot phpipam-firstboot.service runs once, after MariaDB has started and before Apache: it reads the virtual machine's public address from Azure, creates the database, sets the passwords, makes the TLS certificate and writes the credentials file, then records /var/lib/cloudimg/phpipam-firstboot.done so it never runs again. Apache starts only once that file exists. On later boots Apache, MariaDB and cron start as normal systemd services, and Ubuntu's unattended upgrades run on their usual daily timer.

Troubleshooting

The credentials file is not there yet, or the browser cannot connect. First boot is still running. Wait a minute, then check systemctl status phpipam-firstboot --no-pager and sudo tail /var/log/phpipam-firstboot.log.

"Invalid username or password" with the right password. The user name is Admin, with a capital A. After five failed sign-ins phpIPAM blocks your address for five minutes; wait, then try again.

The browser warns about the certificate. The certificate is self-signed for this virtual machine. Install your own (step 9).

Scans find nothing. Check that Check hosts status or Discover new hosts is on for the subnet, that this virtual machine can route to it, and that the hosts answer ping (Azure virtual machines answer ping only when their network security group allows ICMP).

Security Recommendations

Out of the box only SSH (22), HTTP (80, which redirects to HTTPS) and HTTPS (443) listen beyond the virtual machine; MariaDB listens on loopback only, the web installer is switched off, and Apache and MariaDB cannot reach the Azure metadata and wire server addresses:

Listening ports, the HTTP to HTTPS redirect, the disabled installer and the service address limits

  • Change the Admin password after the first sign in, and give each colleague their own account.
  • Allow SSH and HTTPS only from your own networks in the network security group: phpIPAM holds your network plan.
  • Use a DNS name and a trusted certificate (steps 8 and 9).
  • Leave unattended upgrades on, and apply phpIPAM releases as they are published.
  • Turn on phpIPAM's API (Administration > phpIPAM settings) only if you need it, and create one API key per application.

Support

cloudimg's support team is on hand 24 hours a day by email at support@cloudimg.co.uk, with a guaranteed response within 24 hours. For phpIPAM itself, see the documentation at https://phpipam.net/documents/ and the project on GitHub at https://github.com/phpipam/phpipam.