Installing a LAMP stack on Ubuntu should be boring: apt install, start services, load a test page, done.
In reality, it’s common to get hit with errors like:
No such file or directorycommand not foundpermission deniedbad file descriptor- Apache/MySQL won’t start after install
This post is a practical, copy/paste-friendly checklist to get you unstuck, based on SudoGuide’s troubleshooting flow and the typical root causes behind these failures.
What “No such file or directory” usually really means
When you see “No such file or directory” during a LAMP install, it rarely means “your server randomly lost a file.”
It usually means one of these is true:
-
Your package lists are stale (you didn’t run
apt update, or a repo is failing). - Dependencies are broken (a previous install was interrupted and dpkg is half-configured).
- You’re installing the wrong package name / wrong PHP version for your Ubuntu release.
- A config file references a path or module that doesn’t exist (common with Apache ↔ PHP module mismatches).
So the goal isn’t to guess. The goal is to restore your system to a clean package state, install the right components, and verify services.
The “fix it first” command block (most common solution)
If you want the shortest path to “working LAMP,” run this sequence first:
sudo apt update
sudo apt install -f
sudo dpkg --configure -a
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
This matches the “repair apt/dpkg, then install core LAMP packages” approach from the SudoGuide article.
If the install completes cleanly, skip down to Verification.
Step 0: Confirm your Ubuntu version (matters more than you think)
Package availability—especially PHP versions—depends on your Ubuntu release. Confirm it:
lsb_release -ds
Why this matters: people often follow a tutorial targeting a different Ubuntu version and end up installing packages that don’t exist (or mixing PHP versions/modules). The SudoGuide article calls this out as a common cause of “missing file/module” style failures.
Error pattern 1: “Unable to locate package” / missing packages
If you see errors like:
E: Unable to locate package ...- packages that should exist “can’t be found”
Do this:
1) Update package lists:
sudo apt update
2) If apt update shows repository errors, fix/disable the broken repo lines before retrying (this is a frequent underlying cause of “packages can’t be found”).
Then rerun the install:
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
Error pattern 2: “dpkg was interrupted” / broken package state
If you see:
dpkg was interrupted, you must manually run 'sudo dpkg --configure -a'- dependency/configuration errors that won’t go away
Repair your package manager state:
sudo dpkg --configure -a
sudo apt install -f
Then retry installing the stack. This exact dpkg repair workflow is a central part of the SudoGuide troubleshooting path.
Error pattern 3: command not found (but the tutorial says it should exist)
This one is sneaky because it looks like your shell is broken, but it’s usually just “that package/tool isn’t installed yet.”
Two common cases:
A) add-apt-repository: command not found
Install the helper package:
sudo apt update
sudo apt install software-properties-common
SudoGuide specifically flags missing prerequisites like add-apt-repository as a reason installs derail.
B) MySQL hardening command missing
If mysql_secure_installation is missing, it often means MySQL server itself isn’t installed correctly yet. Make sure you installed the server package successfully first:
sudo apt install mysql-server
Then run:
sudo mysql_secure_installation
(That “secure installation” step is widely recommended in standard LAMP setups.)
Error pattern 4: Apache won’t start (often PHP module mismatch)
A classic scenario:
- Apache installs fine
- You install PHP
- Restart Apache and it fails
- Logs/config mention missing
.somodules or paths
The underlying cause is often: Apache is configured to load a PHP module that isn’t actually installed (or you have version conflicts). The SudoGuide article highlights “wrong paths/modules in config” as a frequent reason for “file not found” style errors during LAMP setup.
Start with:
sudo apache2ctl configtest
sudo systemctl status apache2 --no-pager
Then ensure the Apache PHP module package is installed:
sudo apt install libapache2-mod-php
sudo systemctl restart apache2
(If you’re juggling multiple PHP versions, you may also need to disable one module and enable another, but don’t do that unless you know you’re in a multi-version situation.)
Error pattern 5: “Permission denied” (install or web root)
Two common permission issues:
A) Installing without sudo
If you see permission errors during install:
sudo apt update
sudo apt install apache2
B) Writing files into /var/www/html
Ubuntu’s default web root is typically owned by root. If you’re testing with a quick PHP file, write it with sudo:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Error pattern 6: “Bad file descriptor” / weird I/O errors
This is often not “a LAMP problem” at all—it’s a system problem:
- low disk space
- corrupted package downloads
- filesystem issues
SudoGuide frames this as a separate class of failures and recommends system-level checks (disk space, cleanup, reinstall).
At minimum, check disk usage:
df -h
If you’re critically low, free space and retry.
Verification (make sure the whole stack is actually working)
1) Apache is running
sudo systemctl status apache2 --no-pager
You can also test locally:
curl -I http://localhost
2) PHP works via Apache
Create a test file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Then open:
http://YOUR_SERVER_IP/info.php
Important: remove it immediately after testing. Leaving phpinfo() exposed can leak configuration details (extensions, paths, environment info) you don’t want public.
Remove it:
sudo rm /var/www/html/info.php
3) MySQL is alive
sudo systemctl status mysql --no-pager
Debugging checklist (when you’re still stuck)
If something still fails, don’t reinstall blindly—collect signals:
- Repair package state:
sudo dpkg --configure -a-
sudo apt install -f
- Validate Apache config:
-
sudo apache2ctl configtest
-
- Check logs:
sudo journalctl -u apache2 -n 100 --no-pagersudo journalctl -u mysql -n 100 --no-pager
The pattern to remember: LAMP “file not found” errors are usually either package manager state (apt/dpkg) or module/config mismatch (Apache/PHP).
Closing thoughts
Most LAMP install failures are fixable without nuking your server. Treat the error message as a hint, restore your package manager to a healthy state, install the core packages for your Ubuntu release, then verify each layer (Apache → PHP → MySQL).
Source inspiration: SudoGuide’s troubleshooting walkthrough on LAMP install errors for Ubuntu.
Top comments (0)