Linux Commands Every Web Developer Should Know: A Practical Guide for Your First VPS
About the author
John Simiyu, known as Simiyu the Software Developer, is an experienced full-time full-stack software developer with proven, robust skills in web development using PHP, Bootstrap, JavaScript, HTML, MySQL and CSS, Python for automation, and Kotlin and Java for native Android development. He has over 5 years of experience building websites, business systems and mobile apps for clients. He also runs Scolemax Solutions, a Kenyan hosting business, which is mentioned in this article.
Your first time on a Linux server
You buy a VPS, connect to it and see a blinking cursor on a black screen. No buttons, no menus, no files you can click. For many beginners this is the moment they freeze.
The good news is that you do not need to know hundreds of commands. A web developer who knows around thirty well can set up, fix and maintain most servers. In this guide I explain the ones I use most, grouped by the job they do, with examples you can try straight away.
If you have not connected to your server yet, read my article on connecting to a VPS with SSH first, then come back here. The commands in this article work on Ubuntu and most Debian-based systems. Check which operating system your plan uses before you follow the package commands.
Practise safely
Before you start:
- - Practise on a test server, such as a small Scolemax Dev Container, not on a live business website
- Read a command before you press Enter
- Copy and paste carefully, because one wrong character can change the meaning
- Keep a backup of anything important before you change it
The Scolemax homepage lists the entry Dev Container plan, Newbie Devs, at KES 99.99 per month, which makes it a low-cost place to practise. It is a small plan with 0.5 GB RAM, so it is for learning, not for heavy work. Confirm current details on scolemax.com.
1. Finding your way around
- - pwd shows where you are
- ls lists files, and ls -lah shows sizes, owners, dates and hidden files in a readable format
- cd /var/www moves to the folder where websites usually live
- cd ~ takes you to your home folder
- cd - jumps back to the previous folder
- tree shows a folder structure, if it is installed
Tip: press the Tab key to complete file and folder names. It saves typing and prevents spelling mistakes.
2. Working with files and folders
- - mkdir -p sites/demo/logs creates nested folders in one go
- cp -r folder1 folder2 copies a whole folder
- mv old.php new.php renames or moves a file
- touch index.php creates an empty file
- cat file.txt prints a short file
- less file.log lets you scroll through a long file, and q quits
- head -n 20 file.log shows the first 20 lines
- tail -n 50 file.log shows the last 50 lines
- tail -f file.log follows a file live, and Ctrl+C stops it
- nano file.php opens a simple editor, Ctrl+O saves and Ctrl+X exits
3. Searching
- - grep "error" file.log finds lines with a word
- grep -i "error" file.log ignores uppercase and lowercase
- grep -r "db_password" /var/www finds a word inside many files in a folder
- find /var/www -name "*.php" finds files by name
- find /var/www -mtime -1 finds files changed in the last day, which is useful when you suspect a website was altered
4. Permissions: the thing that breaks most websites
Many "403 Forbidden" and "cannot write file" problems come down to permissions. When you run ls -l you see something like this:
-rw-r--r-- 1 www-data www-data 1520 Dec 1 10:00 index.php
The first part shows who can read, write and execute. The three groups are the owner, the group and everyone else. The owner and group are shown next.
- - chmod 644 file.php lets the owner read and write, and everyone else read only. This is typical for files.
- chmod 755 folder lets the owner do everything, and everyone else read and enter. This is typical for folders.
- chown www-data:www-data file.php changes the owner and group
- chown -R www-data:www-data /var/www/mysite changes them for a whole folder
A warning: do not "fix" a problem by running chmod 777. It gives everyone full access to your files, which is a security risk, and it hides the real cause. If a web server cannot write to a folder, give that folder to the correct user and use the least permission needed.
5. Using sudo carefully
Normal users cannot change system settings. sudo runs one command with administrator rights.
- - sudo apt update refreshes the list of available packages
- sudo nano /etc/hosts opens a system file for editing
Think before you use sudo. A command that deletes or changes things will do exactly that, with full power and no safety net. Do not run commands you found online without understanding them.
6. Installing and updating software
On Ubuntu and Debian:
- - sudo apt update checks for new package versions
- sudo apt upgrade installs updates
- sudo apt install nginx installs a program
- sudo apt remove nginx removes it
- apt search keyword looks for a package
Run updates regularly. Many attacks target old, unpatched software, and an updated server is a safer one.
7. Managing services
A service is a program that runs in the background, such as a web server or a database. On most modern Linux systems you manage them with systemctl:
- - sudo systemctl status apache2 shows whether it is running
- sudo systemctl start apache2 starts it
- sudo systemctl stop apache2 stops it
- sudo systemctl restart apache2 stops and starts it again
- sudo systemctl reload apache2 re-reads the settings without a full stop
- sudo systemctl enable apache2 makes it start automatically when the server boots
The name changes with the program, for example nginx, mysql or php8.2-fpm, so check what is installed on your server.
8. Reading logs: your best debugging tool
When a website fails, the log usually tells you why. Common places to look:
- - /var/log/apache2/error.log for Apache errors
- /var/log/nginx/error.log for Nginx errors
- /var/log/syslog for general system messages
- /var/log/auth.log for login attempts
Examples:
sudo tail -n 100 /var/log/apache2/error.log
sudo tail -f /var/log/nginx/error.log
sudo grep "Failed password" /var/log/auth.logThe last command shows failed login attempts. If you see hundreds from many addresses, that is a sign your server is being probed, which is normal for any public server and a good reason to use SSH keys and a firewall.
9. Watching resources
- - df -h shows disk space
- du -sh /var/www/* shows how much space each website folder uses
- free -h shows memory
- top shows running processes live, and q quits
- htop is a friendlier version, if installed
- ps aux | grep php finds running PHP processes
- kill 1234 stops a process by its number, and kill -9 1234 forces it as a last resort
If your server feels slow, check memory and disk first. On a small plan such as an entry-level container, a few busy processes can fill the memory quickly, which is a sign to optimise or upgrade.
10. Basic networking
- - ip a shows your network addresses
- ping -c 4 google.com checks whether the server can reach the internet
- curl -I https://yoursite.com shows the response headers from your site, including the status code
- ss -tulpn shows which programs are listening on which ports
- sudo ufw status shows your firewall status
- sudo ufw allow 22 and sudo ufw allow 80 open specific ports
Careful with the firewall. If you enable it without allowing SSH first, you can lock yourself out of your own server. Always allow your SSH port before enabling it.
11. Combining commands with pipes
The pipe symbol sends the output of one command into another. This is where Linux becomes powerful.
- - ls -l | grep ".php" lists only PHP files
- ps aux | grep apache2 finds Apache processes
- cat access.log | wc -l counts the lines in a log
- history | grep ssh finds old commands that used ssh
- du -sh * | sort -h shows folder sizes from smallest to largest
You can also save output to a file with > and add to a file with >>. For example, df -h > disk-report.txt saves the disk report.
12. Compressing and moving files
- - tar -czf backup.tar.gz /var/www/mysite makes a compressed archive
- tar -xzf backup.tar.gz extracts one
- scp backup.tar.gz user@server:/home/user/ copies a file to another server over SSH
- wget https://example.com/file.zip downloads a file
- unzip file.zip unpacks a zip file, if unzip is installed
Dangerous commands to respect
- - rm -rf deletes files and folders without asking and without a recycle bin. Check the path three times before you press Enter.
- chmod -R 777 makes everything open to everyone
- Any command copied from the internet that you do not understand, especially one that downloads and runs a script in one step
- dd, which can overwrite a whole disk if you choose the wrong target
When you want to delete something, run ls on the same path first to see exactly what will be affected.
Security basics for beginners
- - Use SSH keys instead of passwords where possible
- Keep the system updated
- Use a firewall and open only the ports you need
- Do not run everything as the root user
- Keep your own backups, because provider backups are not a substitute for having your own copy
- Remove services you do not use
A VPS gives you freedom, and freedom comes with responsibility. If you do not want to manage it all yourself, I can set up and secure a server for you.
A small practice plan
- - Day 1: Navigate, create folders and files, edit a file with nano
- Day 2: Practise permissions and see what changes when you run chmod and chown on test files
- Day 3: Install a web server, check its status and read its logs
- Day 4: Use grep, find and pipes on real log files
- Day 5: Make a backup with tar and restore it into a test folder
Repetition is what makes these commands stick. After a week you will type them without thinking.
Common mistakes to avoid
- - Using chmod 777 to make an error disappear
- Running sudo on commands you have not understood
- Editing live system files without a backup
- Enabling a firewall before allowing SSH
- Deleting without checking the path first
- Never reading logs, then guessing at the problem
- Practising on a live production server
Bonus points before you go
- - Bonus 1: Learn to love the up arrow key and Ctrl+R. They bring back old commands and save a lot of typing.
- Bonus 2: Add man command, for example man tar, to see the manual for almost any command.
- Bonus 3: Keep a text file of useful commands that you have learned. It becomes your personal cheat sheet.
- Bonus 4: When something breaks, check the log before you change anything.
- Bonus 5: A small, cheap server is the best classroom. You can break it, reset it and learn without risking a client's website.
Final thoughts
Linux looks intimidating for about a week. After that it becomes the tool you reach for first, because it is fast, scriptable and honest about what it is doing. Start with navigation, permissions, services and logs, and the rest will come naturally.
If you want to practise on a real server, you can look at the Scolemax plans at https://scolemax.com, starting with a Dev Container for learning. If you want help setting up, securing or fixing a server, contact me on WhatsApp at 0739334082 or email consult@johnsimiyuweb.site.
Next, read: How to Set Up a LAMP Server (Apache, PHP, MySQL) on Ubuntu


