The Ultimate Ubuntu VM Baseline Setup Guide
Setting up a robust, production-ready Ubuntu Virtual Machine requires more than just a few apt install commands. This guide provides a battle-tested sequence for Ubuntu 22.04 LTS (Jammy) and 24.04 LTS (Noble), covering LVM expansion, modern Docker standards, and a high-performance PHP 8.3 stack.
📋 Prerequisites
- Target OS: Ubuntu 22.04 or 24.04 LTS
- Access: Sudo-capable user (example:
joos) - Environment: Server VM (Proxmox, ESXi, DigitalOcean, etc.)
1) Passwordless Sudo (Developer Experience)
To streamline management on dev boxes, create a dedicated sudoers drop-in file.
⚠️ Note: Use this for development/personal environments only.
sudo tee /etc/sudoers.d/99-joos-nopasswd >/dev/null <<'EOF' joos ALL=(ALL) NOPASSWD:ALL EOF sudo chmod 0440 /etc/sudoers.d/99-joos-nopasswd sudo visudo -c
2) Expand Storage (LVM & Filesystem)
If you increased your disk size in the hypervisor, use these commands to make that space usable by the OS.
# Extend the Logical Volume to use 100% of free space sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv # Grow the EXT4 filesystem (Default) sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv # Grow the XFS filesystem (If applicable) # sudo xfs_growfs / # Verify results df -h
3) System Baseline & Localization
Sync your clock and update the core package manager.
# Set Timezone & NTP sudo timedatectl set-timezone Asia/Ho_Chi_Minh sudo timedatectl set-ntp on # Update & Install Essentials sudo apt update && sudo apt -y upgrade sudo apt -y install software-properties-common ca-certificates curl gnupg git unzip zip nano
4) Webmin & HAProxy 3.0
Install the latest administration and load-balancing tools.
Webmin Control Panel
curl -o webmin-setup-repo.sh https://raw.githubusercontent.com/webmin/webmin/master/webmin-setup-repo.sh sudo sh webmin-setup-repo.sh sudo apt-get update sudo apt-get install -y --install-recommends webmin # Default access: # https://&lt;server-ip&gt;:10000HAProxy 3.0 (Official PPA)
sudo add-apt-repository ppa:vbernat/haproxy-3.0 -y sudo apt update sudo apt -y install haproxy
5) Modern Docker Installation
As of 2026, Docker uses the
/etc/apt/keyringsmethod. Avoid the legacydocker.iopackages in the default Ubuntu repos for the best experience.# 5.1 Remove conflicting legacy packages (if any) sudo apt remove -y docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc || true # 5.2 Add GPG Key and Repo sudo apt update sudo apt -y install ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null # 5.3 Install Engine & Plugins sudo apt update sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin # 5.4 Run Docker without sudo sudo usermod -aG docker $USER # Important: Log out and back in for group changes to take effect # (or run: newgrp docker)
6) PHP 8.3 & Composer Stack
Using Ondřej Surý’s PPA is the common approach for keeping PHP current on Ubuntu.
sudo add-apt-repository ppa:ondrej/php -y sudo apt update # Install PHP 8.3 & Common Production Extensions sudo apt -y install php8.3 php8.3-cli php8.3-fpm php8.3-dev \ php8.3-mbstring php8.3-curl php8.3-intl php8.3-xml php8.3-zip \ php8.3-gd php8.3-imagick php8.3-opcache php8.3-mysql php8.3-sqlite3 \ php8.3-ldap php8.3-bcmath php8.3-mongodb php8.3-redis php8.3-apcu # Global Composer Install cd /tmp curl -sS https://getcomposer.org/installer -o composer-setup.php sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
7) Supervisor (Queue Management)
Essential for Laravel background workers and long-running processes.
sudo apt -y install supervisor # Example Worker Config: /etc/supervisor/conf.d/laravel-worker.conf # [program:laravel-worker] # command=php /path/to/artisan queue:work # autostart=true # autorestart=true # user=www-data
8) MySQL & Apache Server
Reliable, server-hardened installation for the web layer.
# MySQL Installation sudo apt -y install mysql-server mysql-client sudo mysql_secure_installation # Apache Installation sudo apt -y install apache2 apachetop sudo systemctl enable --now apache2
🛑 Important: Legacy PHP Warning
Do not attempt to install PHP 5.6 or 7.x directly on modern Ubuntu 24.04. This will likely break system dependencies.
- The Solution: Run legacy applications inside Docker containers using official PHP images.
🛡️ Final Security Steps
Don’t forget to lock down your server before going live:
- Enable UFW:
sudo ufw allow 22,80,443/tcp && sudo ufw enable - SSH: Disable password authentication in
/etc/ssh/sshd_config. - Fail2Ban:
sudo apt install fail2banto prevent brute force.
