Useful Commands to Manage Apache Web Server in Linux

In this tutorial, we will describe some of the most commonly used Apache (HTTPD) service management commands that you should know as a developer or system administrator and you should keep these commands at your fingertips. We will show commands for both Systemd and SysVinit.

Read Also: 10 Most Used Nginx Commands Every Linux User Must Know

Make sure that, following commands are must be executed as a root or sudo user and should work on any Linux distribution such as CentOS, RHEL, Fedora Debian, and Ubuntu.

Install Apache Server

To install Apache web server, use your default distribution package manager as shown.

$ sudo apt install apache2	    [On Debian/Ubuntu]
$ sudo yum install httpd	    [On RHEL/CentOS]
$ sudo dnf install httpd	    [On Fedora 22+]
$ sudo zypper install apache2	    [On openSUSE]

Check Apache Version

To check the installed version of your Apache web server on your Linux system, run the following command.

$ sudo httpd -v
OR
$ sudo apache2 -v
Sample Output
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09

If you want to display the Apache version number and compile settings, use the -V flag as shown.

$ sudo httpd -V
OR
$ sudo apache2 -V
Sample Output
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09
Server's Module Magic Number: 20120211:24
Server loaded:  APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

Check Apache Configuration Syntax Errors

To check your Apache configuration files for any syntax errors run the following command, which will check the validity of the config files, prior to restart the service.

$ sudo httpd -t
OR
$ sudo apache2ctl -t
Sample Output
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using tecmint.com. 
Set the 'ServerName' directive globally to suppress this message
Syntax OK

Start Apache Service

To start the Apache service, run the following command.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl start httpd     [On Systemd]
$ sudo service httpd start 	 [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl start apache2   [On Systemd]
$ sudo service apache2 start     [On SysVInit]

Enable Apache Service

The previous command only starts the Apache service for the meantime, to enable it auto-start at system boot, run the following command.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl enable httpd     [On Systemd]
$ sudo chkconfig httpd on 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl enable apache2   [On Systemd]
$ sudo chkconfig apache2 on       [On SysVInit]

Restart Apache Service

To restart Apache (stop and then start the service), run the following command.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl restart httpd     [On Systemd]
$ sudo service httpd restart 	   [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl restart apache2   [On Systemd]
$ sudo service apache2 restart     [On SysVInit]

View Apache Service Status

To check the Apache service run time status information, run the following command.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl status httpd     [On Systemd]
$ sudo service httpd status 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl status apache2   [On Systemd]
$ sudo service apache2 status     [On SysVInit]

Reload Apache Service

If you have made any changes to the Apache server configuration, you can instruct the service to reload its configuration by running the following command.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl reload httpd     [On Systemd]
$ sudo service httpd reload 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl reload apache2   [On Systemd]
$ sudo service apache2 reload     [On SysVInit]

Stop Apache Service

To stop the Apache service, use the following command.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl stop httpd       [On Systemd]
$ sudo service httpd stop 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl stop apache2     [On Systemd]
$ sudo service apache2 stop     [On SysVInit]

Show Apache Command Help

Last but not least, you can get help about the Apache service commands under systemd by running the following command.

$ sudo httpd -h
OR
$ sudo apache2 -h		
OR
$ systemctl -h apache2	
Sample Output
Usage: httpd [-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  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)

You can find more information about systemctl by consulting: How to Manage ‘Systemd’ Services and Units Using ‘Systemctl’ in Linux.

You might also like to read these following Apache related articles.

  1. 5 Tips to Boost the Performance of Your Apache Web Server
  2. How to Monitor Apache Web Server Load and Page Statistics
  3. How to Administrate the Apache Web Server Using “Apache GUI” Tool
  4. How to Change Apache HTTP Port in Linux
  5. 13 Apache Web Server Security and Hardening Tips
  6. Protect Apache Against Brute Force or DDoS Attacks Using Mod_Security and Mod_evasive Modules

That’s all for now! In this article, we’ve explained the most commonly used Apache/HTTPD service management commands that you should know, including starting, enabling, restarting and stopping Apache. You can always reach us via the feedback form below for any questions or comments.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 Comments

Leave a Reply
  1. Thanks for sharing this awesome blog post on the management of apache webserver in Linux. I think it is the most comprehensive article that I have read on this topic. I am currently writing an eBook on server management for Cloudways and I think I can take it as reference to the article.

    Reply
    • @Vince

      Oh, that’s great. We appreciate such recognition and above all using our work as a reference. Many thanks for the feedback.

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.