Skip to content
Joey Wang
Menu

Search

DevOps and Reliability

Optimizing a 1C1G Ubuntu Cloud Server

A production-tested checklist for making a 1 vCPU, 1GB RAM Ubuntu server stable: swap, kernel tuning, service removal, and MySQL/PHP-FPM limits.

· 2 min read

devops #ubuntu#linux#performance#devops

Audio summary

A cloud server with 1 CPU and 1GB RAM is common for personal projects, landing pages, and small sites. Default Ubuntu is not tuned for that: high memory usage, random freezes, OOM kills, and poor performance under small traffic spikes are the usual result. This is the set of changes I use to make Ubuntu stable and predictable on a 1C1G box.

The core principle: reduce, don’t tune blindly

On a 1C1G server, optimization is mostly about removing unnecessary components, not endless parameter tuning: fewer background services, fewer resident daemons, predictable memory usage, and swap enabled unconditionally.

1. Enable swap

Many cloud images ship without swap, which is dangerous on a low-memory machine.

sudo fallocate -l 512M /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Verify:

free -h

It prevents sudden OOM kills, absorbs short memory spikes, and makes the system noticeably more stable under load.

2. Adjust kernel memory behavior

Reduce aggressive swapping and cache pressure:

sudo tee /etc/sysctl.d/99-1c1g.conf <<EOF
vm.swappiness=10
vm.vfs_cache_pressure=200
vm.dirty_ratio=10
vm.dirty_background_ratio=5
EOF

sudo sysctl -p /etc/sysctl.d/99-1c1g.conf

3. Install earlyoom so the system fails fast instead of freezing

sudo apt update
sudo apt install -y earlyoom
sudo systemctl enable --now earlyoom

This kills memory-hogging processes before the kernel panics and the whole box hangs.

4. Remove services Ubuntu enables but a cloud server doesn’t need

Disable them:

sudo systemctl disable --now \
  snapd \
  fwupd \
  multipathd \
  iscsid \
  packagekit \
  unattended-upgrades

Remove snap completely if unused:

sudo apt purge -y snapd
sudo rm -rf /snap /var/snap /var/lib/snapd /var/cache/snapd

Memory saved: 100-200MB.

5. Limit systemd journal size

Unbounded logs silently eat disk and memory:

sudo mkdir -p /etc/systemd/journald.conf.d

sudo tee /etc/systemd/journald.conf.d/limit.conf <<EOF
[Journal]
SystemMaxUse=50M
RuntimeMaxUse=20M
EOF

sudo systemctl restart systemd-journald

6. Optimize MySQL for low memory

MySQL is often the largest memory consumer on a box like this.

Edit:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Add under [mysqld]:

innodb_buffer_pool_size = 128M
innodb_log_buffer_size = 8M
max_connections = 20
performance_schema = OFF
table_open_cache = 400

Restart:

sudo systemctl restart mysql

7. Tune PHP-FPM conservatively

For PHP 8.x:

sudo nano /etc/php/8.3/fpm/pool.d/www.conf

Recommended settings:

pm = dynamic
pm.max_children = 2
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1

8. What healthy looks like

free -h

Expected: available memory at or above 450-550MB, swap usage under 100MB, no frequent CPU spikes, no OOM events.

A 1C1G Ubuntu server can be perfectly stable if it’s treated correctly. The key is not more hardware, it’s intentional minimalism: fewer services, bounded memory per process, and swap as a backstop rather than a crutch.