Testing Syntax Errors in Apache Config
If you spend any time mucking around config files in Linux you are likely to run into some syntax errors sooner or later. Recently I was setting up cgit on Debian 8 and was banging my head against the wall for a few minutes trying to figure out why apache was so unhappy.
Symptoms
The key issue was when I restarted apache2 like I normally would after adding a new configuration it spat out an angry message at me.root@nuc:/etc/apache2# sudo service apache2 restart Job for apache2.service failed. See 'systemctl status apache2.service' and 'journalctl -xn' for details.
Troubleshooting
The first place that I would look is the error logs. However, in this particular case they were not very helpful.root@nuc:/etc/apache2# tail -f /var/log/apache2/error.log [Mon May 01 21:00:11.922943 2017] [mpm_prefork:notice] [pid 20454] AH00169: caught SIGTERM, shutting down
root@nuc:/etc/apache2# systemctl status apache2.service ● apache2.service - LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2) Drop-In: /lib/systemd/system/apache2.service.d └─forking.conf Active: failed (Result: exit-code) since Mon 2017-05-01 21:05:58 PDT; 1min 45s ago Process: 20746 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS) Process: 20697 ExecReload=/etc/init.d/apache2 reload (code=exited, status=1/FAILURE) Process: 20920 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)May 01 21:05:58 nuc apache2[20920]: Starting web server: apache2 failed! May 01 21:05:58 nuc apache2[20920]: The apache2 configtest failed. … (warning). May 01 21:05:58 nuc apache2[20920]: Output of config test was: May 01 21:05:58 nuc apache2[20920]: apache2: Syntax error on line 219 of /etc/apache2/apache2.conf: Syntax error on line 22 of /etc/a… section May 01 21:05:58 nuc apache2[20920]: Action ‘configtest’ failed. May 01 21:05:58 nuc apache2[20920]: The Apache error log may have more information. May 01 21:05:58 nuc systemd[1]: apache2.service: control process exited, code=exited status=1 May 01 21:05:58 nuc systemd[1]: Failed to start LSB: Apache2 web server. May 01 21:05:58 nuc systemd[1]: Unit apache2.service entered failed state. Hint: Some lines were ellipsized, use -l to show in full.
/etc/apache2/apache2.conf
file. Looking at that line we can see that it is simply loading all of the other config files in sites-enabled
which means that before it even gets to load my new cgit config file it fails.
Help
So now that we have done some basic troubleshooting. It's time to dig into the manual for further information. I know that the config file is failing to load, and knowing my fat fingers it is very likely a config error on my part. Before reading 200 pages of documentation on the apache website we should take a look at the built in help to see if we can find something of value.root@nuc:/etc/apache2# apache2 -help Usage: apache2 [-D name] [-d directory] [-f file] [-C "directive"] [-c "directive"] [-k start|restart|graceful|graceful-stop|stop] [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X] Options: -D name : define a name for use in <IfDefine name> directives -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile -C "directive" : process directive before reading config files -c "directive" : process directive after reading config files -e level : show startup errors of level (see LogLevel) -E file : log startup errors to file -v : show version number -V : show compile settings -h : list available command line options (this page) -l : list compiled in modules -L : list available configuration directives -t -D DUMP_VHOSTS : show parsed vhost settings -t -D DUMP_RUN_CFG : show parsed run settings -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG -t -D DUMP_MODULES : show all loaded modules -M : a synonym for -t -D DUMP_MODULES -t : run syntax check for config files -T : start without DocumentRoot(s) check -X : debug mode (only one worker, do not detach)
-t
flag.
Solution
root@nuc:/etc/apache2# apache2 -t -f sites-available/git.levlaz.org.conf apache2: Syntax error on line 22 of /etc/apache2/sites-available/git.levlaz.org.conf: </VirtualHost> without matching <VirtualHost> section
</VirtualHost>
closing bracket. Fixing this syntax error resolved the issue. The main takeaway for me is that the best part about most Linux tools is that they usually give you everything you need in order to succeed. We were able to troubleshoot and resolve this issue without resorting to google and running random commands that stranger posted on the internet 5 years ago.
Thank you for reading! Share your thoughts with me on bluesky, mastodon, or via email.
Check out some more stuff to read down below.
Most popular posts this month
- 2024
- Reinstalling Windows at 1am
- SQLite DB Migrations with PRAGMA user_version
- My Custom Miniflux CSS Theme
- How to Disable Wayland in Debian Testing
Recent Favorite Blog Posts
This is a collection of the last 8 posts that I bookmarked.
- The AGI economy is coming faster than you think from Freethink
- Rolling the ladder up behind us from Xe Iaso's blog
- In Praise of “Normal” Engineers from charity.wtf
- Reports of Bluesky's death have been greatly exaggerated from The Torment Nexus
- What Would a Kubernetes 2.0 Look Like from matduggan.com
- We Can Just Measure Things from Armin Ronacher's Thoughts and Writings
- The Gentle Singularity from Sam Altman
- Whale Watching from https://popagandhi.com/
Articles from blogs I follow around the net
Pluralistic: Daniel de Visé's 'The Blues Brothers' (21 Jun 2025)
Today's links Daniel de Visé's 'The Blues Brothers': Far more than production gossip – an unmissable portrait of a turning point in American comedy and music. Hey look at this: Delights to delectate. Object permanence: 2005, 2010, 2015, 20…
via Pluralistic: Daily links from Cory Doctorow June 21, 2025Hiding metrics from the web
In 2012, artist Ben Grosser released a browser extension called Facebook Demetricator. Once installed, it hid all metrics from Facebook’s interface: likes, comments, notifications, unread messages, and so on. “What’s going on here is that these quantifica…
via Manual do Usuário June 21, 2025It's like surfing
The weird thing about engineering management is that you feel kinda useless. Yet if you stop, projects stop.
via swizec.com RSS Feed June 21, 2025Generated by openring