Random Bright, Funny, Info, Deep Thoughts, AI Chats, and More

[
[
[

]
]
]

When slimming down Ubuntu, the approach differs slightly depending on whether you want to save disk space (deleting files) or RAM (stopping background processes). Since you create web pages in HTML and PHP, you likely want to keep your environment functional for development while stripping away the “desktop fluff.”
Here is a breakdown of what you can safely remove.
1. Saving Disk Space (The “Bloatware”)
Ubuntu comes with several pre-installed suites that occupy significant space.
* LibreOffice: If you use cloud tools or lightweight editors, this saves about 500MB–1GB.
   * sudo apt purge libreoffice*
* Thunderbird: The default mail client.
   * sudo apt purge thunderbird*
* Default Games & Media: Solitaire, Mines, and Cheese (webcam app).
   * sudo apt purge gnome-games gnome-chess cheese
* Snap Packages: Snaps are known for consuming significant disk space because they store multiple versions of the same app.
   * The Nuclear Option: Remove the snapd daemon entirely and switch to .deb or Flatpaks.
* Unused Languages: Use a tool like localepurge to remove manual pages and software translations for languages you don’t speak.
2. Saving RAM (Background Processes)
To lower your idle RAM usage, you need to target services that start on boot.
* Apt-Daily Services: These check for updates in the background. You can disable them and run updates manually.
* Gnome Software / Update Notifier: These sit in the tray and consume memory.
* Bluetooth: If you are on a desktop with a wired mouse/keyboard, disable the Bluetooth daemon.
   * sudo systemctl disable bluetooth.service
* Evolution Data Server: Even if you don’t use Evolution mail, these processes (evolution-calendar-factory, etc.) often run in the background to sync calendars.
* Tracker / Miner: These index your files for the search bar. They are notorious for high CPU and RAM spikes.
   * systemctl –user mask tracker-extract-3 tracker-miner-fs-3
3. System Maintenance Commands
Run these regularly to clear out “hidden” junk that accumulates over time.
| Command | What it does |
|—|—|
| sudo apt autoremove | Removes packages that were installed as dependencies but are no longer needed. |
| sudo apt clean | Clears the local repository of retrieved package files (.deb). |
| journalctl –vacuum-time=3d | Clears all system logs older than 3 days (logs can grow to several GBs). |
4. The “Developer’s Choice” for Maximum Savings
If your primary goal is creating HTML/PHP pages and you find Ubuntu too heavy, consider these structural changes:
* Switch the Desktop Environment: GNOME (default) uses roughly 800MB–1.2GB of RAM at idle. Switching to XFCE (Xubuntu) or Lubuntu (LXQt) can drop idle RAM usage to 400MB–600MB.
* Use a Headless Setup: Since you work with PHP, you might consider Ubuntu Server with a lightweight window manager like i3 or Openbox. This removes all the “hand-holding” GUI elements entirely.
>
A Quick Warning
Do not remove: python3, perl, or kernel-image. Ubuntu’s internal tools rely heavily on Python; removing it will break the OS desktop interface.
Would you like me to generate a Bash script that automates the cleanup of these logs and temp files for you?
Here is a bash script designed to handle the “heavy lifting” of cleaning up your Ubuntu system. It targets the caches, logs, and temporary files we discussed to free up space immediately.
1. The Cleanup Script
You can save this as clean.sh, give it execution permissions with chmod +x clean.sh, and run it with sudo ./clean.sh.
#!/bin/bash

echo “Starting deep clean…”

# 1. Clear APT cache and unnecessary dependencies
apt-get autoremove -y
apt-get autoclean -y
apt-get clean

# 2. Vacuum systemd journal logs (keep only last 2 days)
journalctl –vacuum-time=2d

# 3. Clear Thumbnail cache (can grow large if you have many images)
rm -rf ~/.cache/thumbnails/*

# 4. Clear Snapd cache (removes old versions of apps)
set -eu
snap list –all | awk ‘/disabled/{print $1, $3}’ |
    while read snapname revision; do
        snap remove “$snapname” –revision=”$revision”
    done

echo “Cleanup complete!”

2. Strategic “Deep Cuts” for RAM
Since you develop in PHP/HTML, you might want to visualize how your RAM is currently being distributed. If you run a local LAMP/LEMP stack, that is likely where a bulk of your memory goes.
To further reduce RAM usage specifically for your workflow:
* Disable Apache/MySQL on Boot: If you only develop occasionally, don’t let the web server run 24/7.
   * sudo systemctl disable apache2 (or nginx)
   * sudo systemctl disable mysql
   * Manual start when needed: sudo systemctl start apache2
* Remove “Whoopsie”: This is the Ubuntu error reporting daemon. It’s almost never needed for web development.
   * sudo apt purge whoopsie
3. Monitoring Your Gains
After running the cleanup and disabling services, use these two tools to verify your progress:
* ncdu: Run sudo apt install ncdu then type ncdu /. It provides a visual, navigable tree of your disk usage so you can find exactly which folder is “eating” your SSD.
* htop: Run htop to see a real-time list of processes using RAM. Look for “gnome-shell” or “snapd”—if they are high, you know where to focus your next removals.
Would you like me to help you configure a lightweight PHP development environment (like using Docker or a lighter web server) to replace a heavy full-stack install?
Since you’re looking for a more efficient setup for your HTML and PHP work, switching to a lightweight stack can save hundreds of megabytes of RAM compared to a standard “thick” installation.
Here is how you can transition to a more optimized environment.
1. Swap Apache for Nginx
Apache is powerful but uses a “process-based” model that consumes more RAM per connection. Nginx uses an “event-driven” model, which is significantly lighter.
To swap them:
* Stop Apache: sudo systemctl stop apache2
* Install Nginx: sudo apt install nginx
* Install PHP-FPM: Instead of the standard PHP module, use php-fpm (FastCGI Process Manager), which only runs PHP when a request actually comes in.
2. Using Docker for “On-Demand” Development
Instead of having PHP, MySQL, and a Web Server running as permanent system services, you can use Docker. This allows you to:
* Spin up your dev environment only when you are coding.
* Completely “turn off” the environment to reclaim 100% of the RAM when you’re finished.
* Ensure your production server matches your local environment.
A Simple docker-compose.yml for PHP
You can place this in your project folder:
version: ‘3.8’
services:
  web:
    image: nginx:alpine
    ports:
      – “8080:80”
    volumes:
      – ./src:/usr/share/nginx/html
  php:
    image: php:8.2-fpm-alpine

Note: Using the Alpine versions of these images saves a massive amount of disk space (Alpine is ~5MB vs ~200MB for standard Linux images).
3. Lightweight IDE Alternatives
If you are currently using VS Code or JetBrains, those are built on Electron or Java and are heavy RAM consumers.
| Tool | RAM Usage | Best For |
|—|—|—|
| Sublime Text | ~100MB | Extremely fast HTML/PHP editing. |
| Geany | ~50MB | Full “IDE-lite” features with almost no overhead. |
| Micro / Vim | <20MB | Editing directly in the terminal (Maximum RAM saving). |
4. Final Cleanup: Remove Unused Kernels
Ubuntu keeps old versions of the Linux Kernel every time you update. These take up about 100MB–300MB each in the /boot partition.
To safely remove old kernels:
sudo apt-get purge $(dpkg -l ‘linux-image-*’ | sed ‘/^ii/!d;/’”$(uname -r | sed “s/\(.*\)-\([^0-9]*\)/\1/”)”‘/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/’)

Would you like me to show you how to configure Nginx specifically to handle your PHP files using the lighter PHP-FPM service?
To move from a heavy Apache setup to a lightweight Nginx + PHP-FPM (FastCGI Process Manager) configuration, follow these steps. This setup is significantly more RAM-efficient because Nginx handles the static HTML and hands off only the PHP processing to a separate, optimized service.
1. Install the Essentials
First, install Nginx and the PHP-FPM module.
sudo apt update
sudo apt install nginx php-fpm

Note: Replace php-fpm with your specific version (e.g., php8.2-fpm) if you have a specific requirement for your projects.
2. Configure Nginx to talk to PHP
Nginx does not “speak” PHP natively. It acts as a reverse proxy that sends .php requests to the PHP-FPM socket.
* Open your default site configuration:
   sudo nano /etc/nginx/sites-available/default
* Find the index line and add index.php:
   index index.php index.html index.htm;
* Scroll down to the location ~ \.php$ section and uncomment the lines to match this:
<!– end list –>
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    # Ensure this matches your installed version:
    fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
}

3. Performance Tuning (The RAM Saver)
By default, PHP-FPM spawns several “worker” processes. For a local development machine, you can limit these to save memory.
* Edit the pool configuration:
   sudo nano /etc/php/8.2/fpm/pool.d/www.conf
* Locate the pm (process manager) settings and change them to ondemand:
   pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s

   This tells PHP to only spawn a process when you visit a page and kill it after 10 seconds of inactivity.
4. Test and Restart
sudo nginx -t
sudo systemctl restart nginx
sudo systemctl restart php8.2-fpm

Summary of Benefits
| Feature | Apache (Old) | Nginx + PHP-FPM (New) |
|—|—|—|
| Idle RAM | High (Processes stay open) | Low (Processes die when idle) |
| Static Files | Slower | Blazing fast (Nginx specialty) |
| PHP Handling | Embedded module | Separate service (Better isolation) |
Would you like me to create a simple PHP info script for you to test if the connection between Nginx and PHP is working correctly?
To confirm that Nginx and PHP-FPM are communicating properly, we will create a standard phpinfo() file. This page displays your server’s configuration and confirms that the FastCGI handshake is active.
1. Create the Test File
By default, Nginx serves files from /var/www/html. Create a new file there named info.php:
echo “<?php phpinfo(); ?>” | sudo tee /var/www/html/info.php

2. Verify in your Browser
Open your web browser and navigate to:
http://localhost/info.php
What to look for:
* Server API: It should say FPM/FastCGI. If it says “Apache,” you likely still have Apache running on port 80.
* Document Root: It should show /var/www/html.
3. Securing Your Environment (Important)
Once you confirm everything is working, you should delete this file. Leaving a phpinfo file on a server is a security risk because it tells potential attackers exactly which versions of software and modules you are running.
sudo rm /var/www/html/info.php

4. Advanced: Speed Up Your Workflow
Since you frequently create HTML and PHP pages, you might find it annoying to use sudo every time you want to save a file in /var/www/html. You can change the ownership of that folder to your own user:
# Replace ‘username’ with your actual Ubuntu username
sudo chown -R $USER:$USER /var/www/html

Now you can drag and drop your .html and .php files directly into that folder or save them from your code editor without permission errors.
Would you like me to help you set up “Virtual Hosts” so you can host multiple projects at different local addresses like project1.test and project2.test?
To complete your lightweight development environment, we’ll add MariaDB. It is a drop-in replacement for MySQL that is generally considered more performance-oriented and open-source friendly.
To keep your RAM usage low, we will install it and then configure it to “hibernate” or use a smaller footprint, as default database settings are often tuned for high-traffic servers, not local development.
1. Install MariaDB
Run the following command to install the server and the PHP-MySQL bridge:
sudo apt install mariadb-server php-mysql

2. Secure and Initialize
Run the security script to set your root password and remove insecure default settings:
sudo mysql_secure_installation

(Follow the prompts to set a password and remove anonymous users/test databases.)
3. The “RAM-Saver” Configuration
By default, MariaDB allocates a significant amount of memory for caching (Buffer Pools). Since your local PHP projects likely have small databases, we can shrink this.
* Open the config file: sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
* Add or edit these lines under the [mysqld] section:
   # Reduce memory for the InnoDB engine
innodb_buffer_pool_size = 16M
innodb_log_buffer_size = 1M

# Lower maximum connections (default is often 151)
max_connections = 20

# Disable performance schema (saves ~40MB+ RAM)
performance_schema = OFF

* Restart the service: sudo systemctl restart mariadb
4. Managing Databases without “Heavy” Tools
Instead of installing phpMyAdmin (which adds another layer of PHP/Nginx overhead), consider these lighter options:
* Adminer: A single .php file that does almost everything phpMyAdmin does. You just drop adminer.php into your project folder.
* DBeaver (Community): A desktop application that connects to your database. It uses RAM only when the app is open, rather than running a web-based management tool 24/7.
* Command Line: The most RAM-efficient way.
   * mariadb -u root -p
5. Summary of your “Lean” Stack
You now have a fully functional development environment optimized for your Ubuntu system:
| Component | Choice | Why? |
|—|—|—|
| Web Server | Nginx | Event-driven, very low idle RAM. |
| PHP Engine | PHP-FPM | Runs “on-demand” and kills idle processes. |
| Database | MariaDB | Tuned for low memory with performance schema off. |
| Workflow | Server Blocks | Keeps your files organized in your /home folder. |
Would you like me to create a “Project Starter” bash script that creates a new site folder, sets up the Nginx config, and adds the hosts entry all in one command?


Discover more from NathanLegakis.com

Subscribe to get the latest posts sent to your email.

Leave a Reply

Discover more from NathanLegakis.com

Subscribe now to keep reading and get access to the full archive.

Continue reading