Apache

Useful Common Apache Commands for Ubuntu and Debian

In this tutorial you will learn useful apache commands for Ubuntu and Debian. Apache HTTP server is the most popular web server in the world and It is a free. If you are a developer or system administrator may be you use the Apache command regularly.

In this guide we will learn most important and frequently used Apache commands.

1. Check Apache Version

Use -v command-line option to check the running Apache version on Ubuntu and other Debina-based systems.

$ apache2 -v
Server version: Apache/2.4.41 (Ubuntu) Server built: 2021-06-17T18:27:53

To view the detailed infomation use capital letter -V with apache2 command.

$ apache2 -V

2. Test Apache Configuration

Use the following command to check the syntax for all the Apache2 configuration files.

$ sudo apachectl -t
Syntax OK

If all the configuration files are correct, You will see “Syntax Ok” in the results.

3. Enable and Disable Virtual Hosts

For virtual host all configuration file found in /etc/apache2/sites-available directory.

Now enable the website using a2ensite, which simply creates a symlink of that file to /etc/apache2/sites-enabled.

Apache loads all the files from this directory to the environment. For example, if you have created a file named example.com.conf. Then use the following command.

$ sudo a2ensite example.com

Similariy use a2dissite command to disbale the sites, which is already disabled.

$ sudo a2dissite example.com

4. Enable and Disable Configurations

Run the below command to enable or disable the apache configuration file.

$ sudo a2enconf phpmyadmin

To deactivate the configuration just disable it by a2disconf command like:

$ sudo a2disconf phpmyadmin

5. Enable and Disable Modules

Follow below command to disable and enable apache modules.

$ sudo a2enmod rewrite

To disable rewrite module, run:

$ sudo a2dismod rewrite

6. Manage Apache2 Service

The latest operating systems have opted the system for managing services. You can use the systemctl command-line utility for managing the Apache service on your system. The following commands will stop, start, and restart the apache2 service on your system.

$ sudo systemctl stop apache2
$ sudo systemctl start apache2
$ sudo systemctl restart apache2

The changes in configuration files can be reloaded in the running environment with reload option. This will not restart the Apache service.

$ sudo systemctl reload apache2

Use the following command to enable and disable the apcahe2 service.

$ sudo systemctl enable apache2
$ sudo systemctl disable apache2

7. Show Apache Command Help

For more help use the -h options on command line.

sudo apache2 -h
Output
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  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 -D DUMP_INCLUDES: show all included configuration files
  -t                 : run syntax check for config files
  -T                 : start without DocumentRoot(s) check
  -X                 : debug mode (only one worker, do not detach)

Follow this link to install apache web server.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment