Apache Config
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.
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
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.
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.
- SSH into Lubuntu
- Open your bash config:
nano ~/.bashrc - 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' - Save and exit nano
- Apply:
source ~/.bashrc - Try:
acheck— should print "Syntax OK" - 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.