Apache HTTP Server

The Apache HTTP Server, colloquially called Apache, is a free and open-source cross-platform web server software. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation.

Virtual Hosts

The term Virtual Host refers to the practice of running more than one web site (such as company1.example.com and company2.example.com) on a single instance of Apache. Virtual hosts can be IP-based, meaning that you have a different IP address for every web site, or name-based, meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user.

See: Apache Virtual Host Setup on Debian Buster
See: XAMPP Setup

Apache Configuration

apache.conf

.htacces

Configuration Directives

VirtualHost

ServerName

ServerAlias

ServerPath

Apache Commands

Status

See the virtual hosts status on Apache:

/usr/sbin/apache2ctl -S

Get the Apache version number:

/usr/sbin/apache2 -v

Use the status command to check Apache. This gives a nice overview of the current status of the application, and notifications about problems and any actions that may be required.

sudo systemctl status apache2 --no-pager

NOTE: --no-pager tells systemctl to just print the details and bypass going into the “edit mode”. You can press q to exit edit mode.

Start and Stop

Stop Apache from running:

sudo systemctl stop apache2

Start Apache running (when it is stopped):

sudo systemctl start apache2

Stop and then start Apache again:

sudo systemctl restart apache2

For configuration changes, Apache can often reload without dropping connections:

sudo systemctl reload apache2

By default, Apache is configured to start automatically when the server boots. If this is not desired, disable this behavior:

sudo systemctl disable apache2

To re-enable Apache to start at boot:

sudo systemctl enable apache2

Enable or Disable a Site

A website (virtual host) must be enabled for Apache to recognize it.
To enable a site, its configuration file (apache.conf) must be symlinked to the /etc/apache2/sites-available directory.

sudo ln -s ../../../path/to/apache.conf /etc/apache2/sites-available/myapp.conf

The site can then be enabled with:

sudo a2ensite myapp

Test the configuration:

sudo apachectl configtest

Reload Apache to make it pick-up the new enabled site.

sudo systemctl restart apache2

The site can be disabled by running:

sudo a2dissite myapp

Then restart Apache.

More Resources