The following blog post contains a list of useful commands that can be used when configuring an Apache web server. The file paths in this article assume you are running Apache on Ubuntu.
Many of these commands may need to be run as a user with sudo
privileges if you encounter Permission Denied
errors. Remember to test your configuration changes and restart Apache for them to take effect!
Test current configuration
apachectl configtest
Stop Apache
apachectl stop
Start Apache
apachectl start
Restart Apache
service apache2 restart
Reload Apache
systemctl reload apache2
Enable a site (from sites-available)
a2ensite example.com.conf
Disable a site (from sites-available)
a2dissite example.com.conf
Check which Apache modules are enabled
apache2ctl -M
List enabled modules
ls /etc/apache2/mods-enabled/
List available modules
ls /etc/apache2/mods-available/
Enable a module
a2enmod expires
// expires module for caching as an example
a2enmod headers
// headers module as an example
Disable a module
a2dismod expires
// expires module for caching as an example
a2dismod headers
// headers module as an example
List all available ports
lsof -iTCP -sTCP:LISTEN -P