In this tutorial, we will discuss some commonly used commands for managing Apache servers on Ubuntu and Debian-based systems. This includes how to enable/disable a virtual host, module, or configuration file in the Apache server.

1. Check Apache Version

Use -v command-line option to check the running Apache version on Ubuntu and other Debina-based systems. To view the detailed infomation use capital letter -V with apache2 command.

2. Test Apache Configuration

After making any changes in Apache configuration files, You must run a check for the syntax. Use the following command to check the syntax for all the Apache2 configuration files. If all the configuration files are correct, You will see “Syntax Ok” in the results.

3. Enable and Disable Virtual Hosts

The website configuration files keep information about the Apache Virtual Hosts. In the case of Debian-based systems, the actual file is created under /etc/apache2/sites-available directory. Then, we 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. Similariy use a2dissite command to disbale the sites, which is already disabled.

4. Enable and Disable Configurations

The original configuration files are stored under /etc/apache2/sites-available/ directory. Apache read the configuration files from /etc/apache2/sites-enabled/ directory, So you need to create symbolic link of files to site-enabeld directory. The a2enconf command creates a symbolic link for the configuration file and a2disconf removes the symbolic link. For example to create symbolic link for the configuration file phpmyadmin.conf run: To deactivate the configuration just disable it by a2disconf command like:

5. Enable and Disable Modules

All the Apache module files are stored under /etc/apache2/mods-available/ directory. All the active modules are symlinked to /etc/apache2/mods-enabled/ directory. Use a2enmod command to enable a module in Apache server and a2dismod to disable the module. For example to enable rewrite module, type: To disable rewrite module, run:

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. The changes in configuration files can be reloaded in the running environment with reload option. This will not restart the Apache service. Use the following command to enable or disable the apcahe2 service.

7. Show Apache Command Help

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

Conclusion

In this beginners guide, you have learned about basic commands to manage Apache server via command line.