THU.JUN.18
2026
23:34:34
← back to modules MODULE · 01 · PHP
0 / 10 chapters complete · 0%

Apache Config

Learn enough Apache to debug "why isn't my site loading" forever. Ten minutes of investment, lifetime of payoff.
Apache's config = main file + modules folder + sites folder. Available/enabled pattern everywhere. Helper commands do the symlinks. Always validate before reloading.

The config tree

/etc/apache2/
├── apache2.conf          # main config
├── ports.conf            # which ports to listen on
├── mods-available/       # ALL installed modules
├── mods-enabled/         # modules ACTUALLY loaded (symlinks)
├── sites-available/      # ALL defined sites
└── sites-enabled/        # sites ACTUALLY served (symlinks)

Pattern: things in -available are sitting there inert. Symlinking to -enabled activates them. Like apps installed vs apps pinned to home screen.

The helper commands (don't make symlinks by hand)

sudo a2ensite SITENAME       # enable a site
sudo a2dissite SITENAME      # disable a site
sudo a2enmod MODULE          # enable a module
sudo a2dismod MODULE         # disable a module
sudo systemctl reload apache2  # apply the change

"a2" = "Apache 2". "en"/"dis" = enable/disable. Then site/mod. Predictable.

See what modules are currently loaded:
apache2ctl -M | sort
Scroll through the list. Notice php8, rewrite, etc.

The default site (where your Alias lives)

/etc/apache2/sites-available/000-default.conf handles http://localhost/ AND your /home/erictey/server/ Alias.

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/html

    Alias /server /home/erictey/server

    <Directory /home/erictey/server>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        DirectoryIndex index.php
    </Directory>

    ErrorLog \${APACHE_LOG_DIR}/error.log
    CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Quick decode:

  • VirtualHost *:80 — applies to requests on port 80 from any IP
  • DocumentRoot — default folder Apache serves
  • Alias /server — "when URL contains /server, look in this folder instead"
  • Require all granted — allow anyone to access (otherwise Apache denies by default)
  • AllowOverride All — lets .htaccess files override Apache settings
  • DirectoryIndex — what to serve when no specific file is requested

Always validate before you reload

One typo and Apache won't start. The error messages often point three lines away from the real problem.

sudo apache2ctl -t

Look for Syntax OK. Anything else gives you a line number to fix.

The log files (your new best friends)

  • /var/log/apache2/error.log — PHP errors, denied requests, startup messages
  • /var/log/apache2/access.log — every successful request
Open a second SSH window and tail the error log while the first window does stuff:
sudo tail -f /var/log/apache2/error.log

Then in your browser, hit a non-existent URL like http://192.168.0.19/nope.php. Watch the log light up.

Press Ctrl+C to bounce out of tail.

Reading the log is the single most underused superpower in web dev. Get cozy with this command — it solves like 90% of "why isn't this working" mysteries.

Useful modules to know exist

sudo a2enmod rewrite        # clean URLs (.htaccess routing)
sudo a2enmod ssl            # HTTPS
sudo a2enmod headers        # set custom HTTP headers
sudo a2enmod expires        # cache control for static files
sudo a2enmod proxy          # reverse proxy to other apps
sudo systemctl restart apache2

Build: Aliases for Your Workflow

Goal: stop typing the same long Apache commands twenty times a day.

  1. SSH into Lubuntu
  2. Open your bash config: nano ~/.bashrc
  3. Scroll to bottom, add:
    alias areload='sudo systemctl reload apache2'
    alias arestart='sudo systemctl restart apache2'
    alias acheck='sudo apache2ctl -t'
    alias alog='sudo tail -f /var/log/apache2/error.log'
  4. Save and exit nano
  5. Apply: source ~/.bashrc
  6. Try: acheck — should print "Syntax OK"
  7. Try: acheck && areload — your new "I edited config" reflex

Stretch: add an alias aerr='sudo tail -n 50 /var/log/apache2/error.log' to see the last 50 error log lines without following.