1. Service Management (Start/Stop/Restart)
| Command | Description | Example | Output/Usage |
|---|---|---|---|
systemctl start httpd | Starts the Apache service | sudo systemctl start httpd | Starts Apache web server |
systemctl stop httpd | Stops the Apache service | sudo systemctl stop httpd | Shuts down Apache |
systemctl restart httpd | Restarts Apache service | sudo systemctl restart httpd | Applies config changes |
systemctl reload httpd | Reloads Apache config without downtime | sudo systemctl reload httpd | Graceful reload |
systemctl status httpd | Shows status of Apache | sudo systemctl status httpd | Running/Failed info |
systemctl enable httpd | Enable Apache to start on boot | sudo systemctl enable httpd | Auto-start at boot |
systemctl disable httpd | Disable Apache at boot | sudo systemctl disable httpd | Stop auto-start |
apachectl graceful | Gracefully restarts Apache | sudo apachectl graceful | No connection drop |
apachectl restart | Restart Apache | sudo apachectl restart | Full restart |
apachectl stop | Stop Apache | sudo apachectl stop | Hard stop |
| Command Name | Description | Example |
|---|---|---|
systemctl start apache2 | Starts the Apache service on Debian/Ubuntu (Systemd). | sudo systemctl start apache2 |
systemctl start httpd | Starts the Apache service on CentOS/RHEL (Systemd). | sudo systemctl start httpd |
service apache2 start | Starts the Apache service on Debian/Ubuntu (SysVinit). | sudo service apache2 start |
service httpd start | Starts the Apache service on CentOS/RHEL (SysVinit). | sudo service httpd start |
systemctl enable apache2 | Enables Apache to start automatically at boot on Debian/Ubuntu (Systemd). | sudo systemctl enable apache2 |
systemctl enable httpd | Enables Apache to start automatically at boot on CentOS/RHEL (Systemd). | sudo systemctl enable httpd |
chkconfig apache2 on | Enables Apache to start at boot on Debian/Ubuntu (SysVinit). | sudo chkconfig apache2 on |
chkconfig httpd on | Enables Apache to start at boot on CentOS/RHEL (SysVinit). | sudo chkconfig httpd on |
systemctl stop apache2 | Stops the Apache service on Debian/Ubuntu (Systemd). | sudo systemctl stop apache2 |
systemctl stop httpd | Stops the Apache service on CentOS/RHEL (Systemd). | sudo systemctl stop httpd |
service apache2 stop | Stops the Apache service on Debian/Ubuntu (SysVinit). | sudo service apache2 stop |
service httpd stop | Stops the Apache service on CentOS/RHEL (SysVinit). | sudo service httpd stop |
systemctl restart apache2 | Restarts the Apache service (stops and starts) on Debian/Ubuntu (Systemd). | sudo systemctl restart apache2 |
systemctl restart httpd | Restarts the Apache service on CentOS/RHEL (Systemd). | sudo systemctl restart httpd |
service apache2 restart | Restarts the Apache service on Debian/Ubuntu (SysVinit). | sudo service apache2 restart |
service httpd restart | Restarts the Apache service on CentOS/RHEL (SysVinit). | sudo service httpd restart |
systemctl reload apache2 | Reloads Apache configuration without stopping the service (graceful restart) on Debian/Ubuntu. | sudo systemctl reload apache2 |
systemctl reload httpd | Reloads Apache configuration on CentOS/RHEL. | sudo systemctl reload httpd |
service apache2 reload | Reloads Apache configuration on Debian/Ubuntu (SysVinit). | sudo service apache2 reload |
service httpd reload | Reloads Apache configuration on CentOS/RHEL (SysVinit). | sudo service httpd reload |
systemctl status apache2 | Checks the status of the Apache service on Debian/Ubuntu (Systemd). | sudo systemctl status apache2 |
systemctl status httpd | Checks the status of the Apache service on CentOS/RHEL (Systemd). | sudo systemctl status httpd |
service apache2 status | Checks the status of the Apache service on Debian/Ubuntu (SysVinit). | sudo service apache2 status |
service httpd status | Checks the status of the Apache service on CentOS/RHEL (SysVinit). | sudo service httpd status |
2. Configuration Checking
| Command | Description | Example | Output/Usage |
|---|---|---|---|
apachectl configtest | Test Apache config syntax | sudo apachectl configtest | Shows Syntax OK or errors |
httpd -t | Another way to test config | sudo httpd -t | Syntax validation |
httpd -S | Show vhost configuration | sudo httpd -S | VHost layout and issues |
apachectl -t -D DUMP_VHOSTS | List all virtual hosts | sudo apachectl -t -D DUMP_VHOSTS | Host/port mapping |
apachectl -t -D DUMP_MODULES | List all loaded modules | sudo apachectl -t -D DUMP_MODULES | Active modules |
apachectl -t -D DUMP_RUN_CFG | Show running config | sudo apachectl -t -D DUMP_RUN_CFG | Runtime configuration |
| Command Name | Description | Example |
|---|---|---|
httpd -d <serverroot> | Sets the ServerRoot directory for configuration files. | httpd -d /usr/local/apache2 |
httpd -f <config> | Specifies a custom configuration file. | httpd -f /etc/httpd/conf/custom.conf |
httpd -C <directive> | Processes a directive before reading config files. | httpd -C "Include /etc/httpd/extra.conf" |
httpd -c <directive> | Processes a directive after reading config files. | httpd -c "LogLevel debug" |
httpd -D <parameter> | Sets a parameter for use with <IfDefine> directives. | httpd -D SSL |
httpd -e <level> | Sets LogLevel during startup for debugging. | httpd -e debug |
httpd -E <file> | Sends startup error messages to a file. | httpd -E /var/log/httpd/startup_errors.log |
httpd -k start | Starts the Apache server. | httpd -k start |
httpd -k restart | Restarts the Apache server. | httpd -k restart |
httpd -k graceful | Gracefully restarts Apache without closing connections. | httpd -k graceful |
httpd -k stop | Stops the Apache server. | httpd -k stop |
httpd -k graceful-stop | Gracefully stops Apache without closing connections. | httpd -k graceful-stop |
httpd -h | Displays a summary of command-line options. | httpd -h |
httpd -l | Lists modules compiled into the server. | httpd -l |
httpd -L | Lists all directives with their arguments and valid locations. | httpd -L |
httpd -S | Shows parsed virtual host settings from the configuration file. | httpd -S |
httpd -t | Tests configuration files for syntax errors. | httpd -t |
httpd -T | Tests configuration files without checking document roots. | httpd -T |
httpd -v | Prints the Apache version and exits. | httpd -v |
httpd -V | Prints the Apache version and build parameters, then exits. | httpd -V |
httpd -X | Runs Apache in single-process debug mode (no forking). | httpd -X |
httpd -M | Lists all loaded modules (static and dynamic). | httpd -M |
3. Apache Files and Paths (Default)
| File/Path | Description | Example |
|---|---|---|
/etc/httpd/conf/httpd.conf | Main Apache config file | Configure ports, modules, logging |
/etc/httpd/conf.d/ | Directory for custom .conf files | Add vhosts here |
/var/www/html/ | Default document root | Store website files here |
/etc/httpd/logs/ or /var/log/httpd/ | Log directory | Access and error logs |
| Command Name | Description | Example |
|---|---|---|
apachectl start | Starts the Apache HTTP daemon. Errors if already running. | sudo apachectl start |
apachectl stop | Stops the Apache HTTP daemon. | sudo apachectl stop |
apachectl restart | Restarts the Apache daemon (stops and starts, checks configuration). | sudo apachectl restart |
apachectl graceful | Gracefully restarts Apache without aborting open connections. | sudo apachectl graceful |
apachectl graceful-stop | Gracefully stops Apache without aborting open connections. | sudo apachectl graceful-stop |
apachectl configtest | Tests configuration files for syntax errors without starting the server. | sudo apachectl configtest |
apachectl status | Displays a full status report using mod_status (requires text-based browser like lynx). | sudo apachectl status |
apachectl fullstatus | Similar to status, provides detailed server status (requires mod_status). | sudo apachectl fullstatus |
4. Manual Testing Commands
| Command | Description | Example | Use |
|---|---|---|---|
curl http://localhost | Test if Apache is serving pages | curl http://localhost | Get default page |
| `netstat -tulnp | grep :80` | Check if port 80 is open | `sudo netstat -tulnp |
| `ss -tuln | grep :80` | Alternative to netstat | `sudo ss -tuln |
| `ps aux | grep httpd` | Check running Apache processes | `ps aux |
5. Installation Commands
| Command | Description | Example |
|---|---|---|
yum install httpd | Install Apache (CentOS/RHEL) | sudo yum install httpd -y |
apt install apache2 | Install Apache (Debian/Ubuntu) | sudo apt install apache2 -y |
dnf install httpd | Fedora/RHEL 8+ installation | sudo dnf install httpd -y |
6. Log Management
| Log File | Description | Example |
|---|---|---|
/var/log/httpd/access_log | Tracks all access requests | sudo tail -f /var/log/httpd/access_log |
/var/log/httpd/error_log | Logs errors | sudo tail -f /var/log/httpd/error_log |
journalctl -u httpd | View Apache logs via systemd | sudo journalctl -u httpd |
7. Module Management
| Command | Description | Example |
|---|---|---|
a2enmod <module> | Enable module (Debian/Ubuntu) | sudo a2enmod rewrite |
a2dismod <module> | Disable module | sudo a2dismod autoindex |
apachectl -M | Show loaded modules | sudo apachectl -M |
| Command Name | Description | Example |
|---|---|---|
a2enmod <module> | Enables a specific Apache module by creating a symlink in mods-enabled. | sudo a2enmod rewrite |
a2dismod <module> | Disables a specific Apache module by removing the symlink from mods-enabled. | sudo a2dismod proxy_http2 |
8. Virtual Host Configuration (Sample Format)
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/example
ErrorLog /var/log/httpd/example_error.log
CustomLog /var/log/httpd/example_access.log combined
</VirtualHost>
Enable with:
sudo systemctl reload httpd
9. Reload Without Downtime
| Command | Description | Example |
|---|---|---|
apachectl graceful | Reload config without killing connections | sudo apachectl graceful |
Summary Table: Most Used Apache Commands
| Purpose | Command | Example |
|---|---|---|
| Start Apache | systemctl start httpd | sudo systemctl start httpd |
| Test Config | apachectl configtest | sudo apachectl configtest |
| Restart Apache | apachectl restart | sudo apachectl restart |
| Check Virtual Hosts | apachectl -S | sudo apachectl -S |
| View Logs | journalctl -u httpd | sudo journalctl -u httpd |
| Enable Auto-start | systemctl enable httpd | sudo systemctl enable httpd |
| Install Apache | apt install apache2 | sudo apt install apache2 |
| Check Modules | apachectl -M | sudo apachectl -M |