Apache Commands You Should Know

Introduction

The Apache web server, serves content from a server to a browser. Apache is widely used on the the web. In this article I will cover most, if not all, of the Apache commands you will need to know.

Start Apache Service

sudo systemctl start apache2 # For Debian-based systems (Ubuntu)
sudo systemctl start httpd # For Red Hat-based systems (CentOS, Fedora)

Stop Apache Service

sudo systemctl stop apache2 # For Debian-based systems (Ubuntu)
sudo systemctl stop httpd # For Red Hat-based systems (CentOS, Fedora)

Restart Apache Service

sudo systemctl restart apache2 # For Debian-based systems (Ubuntu)
sudo systemctl restart httpd # For Red Hat-based systems (CentOS, Fedora)

Reload Apache Configuration

sudo systemctl reload apache2 # For Debian-based systems (Ubuntu)
sudo systemctl reload httpd # For Red Hat-based systems (CentOS, Fedora)

Check Apache Status

sudo systemctl status apache2 # For Debian-based systems (Ubuntu)
sudo systemctl status httpd # For Red Hat-based systems (CentOS, Fedora)

Enable Apache to Start at Boot

sudo systemctl enable apache2 # For Debian-based systems (Ubuntu)
sudo systemctl enable httpd # For Red Hat-based systems (CentOS, Fedora)

Disable Apache to Start at Boot

sudo systemctl disable apache2 # For Debian-based systems (Ubuntu)
sudo systemctl disable httpd # For Red Hat-based systems (CentOS, Fedora)

Test Apache Configuration

apachectl configtest

Check Apache Version

apache2 -v # For Debian-based systems (Ubuntu)
httpd -v # For Red Hat-based systems (CentOS, Fedora)

Stop Apache Gracefully

sudo apachectl graceful

Run Apache in the Foreground (Debug Mode)

sudo apachectl -X

Disable a Site

sudo a2dissite [site-name] # For Debian-based systems (Ubuntu)

Enable a Site

sudo a2ensite [site-name] # For Debian-based systems (Ubuntu)

Check Apache Modules

apache2ctl -M # For Debian-based systems (Ubuntu)
httpd -M # For Red Hat-based systems (CentOS, Fedora)

Enable/Disable Apache Modules

sudo a2enmod [module_name] # Enable a module
sudo a2dismod [module_name] # Disable a module

Conclusion

These commands should help you effectively manage your Apache HTTP Server. Always ensure you have the proper permissions (often requiring sudo) to execute administrative actions.