apache commands cheat sheet

Apache Commands Cheat Sheet

Apache is a popular web server used by millions of websites and organizations. It offers tons of features and commands to help you easily get your work done. It can be difficult to remember all its directives and commands. So it is advisable to keep a simple cheat sheet of commonly used commands handy. In this article, we will create an Apache commands cheat sheet to help you.

Apache Commands Cheat Sheet

Here are the most commonly used Apache commands for your quick reference in Ubuntu/Debian systems. If you get a ‘permission denied’ error for any of the following commands, try running them by adding sudo keyword at the beginning.

1. Check Apache Version

You can easily check your Apache server’s version with the following command.

$ apache2 -v

If you want to detailed information about your Apache server, use -V option.

$ apache2 -V

2. Test Apache Configuration

After you make changes to your Apache server’s configuration file, you can run the following command to test Apache configuration.

$ apachectl -t

It will point out syntax errors in your configuration file so that you don’t restart Apache server with an erroneous configuration file.

3. Enable & Disable Virtual Hosts

If you want to enable a virtual host for website, say, example.com, you need to place its configuration file at /etc/apache2/sites-available and use a2ensite command to create a symlink to the configuration file, at /etc/apache2/sites-enabled. For example, if you have /etc/apache2/sites-available/example.com.conf file then run the following command to enable it.

$ a2ensite example.com

Similarly, if you want to disable the above virtual host, use a2dissite command.

$ a2dissite example.com

4. Enable & Disable Configuration File

Similarly, you can also enable or disable configuration files with a2enconf and a2disconf commands respectively. These configuration files are generally placed at /etc/apache2/sites-available.

Here is an example command to enable phpmyadmin configuration file.

$ a2enconf phpmyadmin 

Similarly, here is the command to disable this configuration file.

$ a2disconf phpmyadmin 

5. Enable & Disable Apache Modules

Apache supports wide range of modules, packages & libraries to extend its functionality. The modules are installed at /etc/apache2/mods-available. When you enable a module, a symlink to the module will be created at /etc/apache2/mods-enabled.

You can use a2enmod command to enable Apache module, and a2dismod to disable the module. Here is an example to enable Apache’s mod_rewrite module.

$ a2enmod rewrite 

Here is the command to disable mod_rewrite.

$ a2dismod rewrite 

6. Start, Stop, Restart Apache Server

You can use systemctl utility to restart Apache server easily. Here are the common commands to manage Apache server.

Start Server

$ systemctl start apache2

Stop Server

$ systemctl stop apache2

Restart Server

$ systemctl restart apache2

Reload Apache Configuration Without Restart

$ systemctl reload apache2

If you want to view more commands that are available for Apache server, run the following command.

$ apache2 -h

In this article, we have learnt many commonly used commands for Apache server.

Also read:

How to Clone Git Repository to Specific Folder
How to Switch Python Version in Ubuntu/Debian
How to Disable HTTP Methods in Apache
MySQL Datetime vs Timestamp
How to Remove Line from File Using Python

2 thoughts on “Apache Commands Cheat Sheet

Leave a Reply

Your email address will not be published.