Manage the Apache Daemon
Start the Web Server
sudo systemctl start apache2
Stop the Web Server
sudo systemctl stop apache2
Stop and restart the Web Server
sudo systemctl restart apache2
Reload the Configuration
sudo systemctl reload apache2
Disable Autostart
Under Ubuntu, Apache Web Server starts after a reboot of Ubuntu per default. To deactivate this autostart:
sudo systemctl disable apache2
Enable Autostart
To enable the autostart after an Ubuntu reboot, use:
sudo systemctl enable apache2
Web Site Files
Per default Apache Web Server running on Ubuntu looks for the web site files under path /var/www.
The example web page It Works! finds its data under /var/www/html.
By using the technology of Virtual Hosts you can run multiple independent web sites with one single Apache Web Server running on one Ubuntu server.
It makes sense to create appropriate subfolders in /var/www/ for each virtual host you plan to configure. Example: /var/www/yourdomain.tld.
As per best practice we create an additional subfolder for each subdomain, i.e. for a subdomain named www we create /var/www/yourdomain.tld/www, etc.
Setting up the VirtualHost Configuration File
The VirtualHost configurations files are stored in folder /etc/apache2/sites-available/.
The best practice approach is to create separate virtual host configuration files for each domain although Apache allows multiple virtual hosts in one single configuration file.
Activation and Deactivation of VirtualHost configuration
Activate
After setting up the web site and defining the configuration file as needed, the virtual hosts configuration needs to be activated:
sudo a2ensite yourdomain.conf
To load the new configuration into Apache:
sudo systemctl reload apache2
Deactivate
sudo a2dissite yourdomain.conf
Test the Configuration
sudo apache2ctl configtest
Additional Configuration
Activate
sudo a2enconf filename.conf
Deactivate
sudo a2disconf filename.conf
Modules
Activate
sudo a2enconf modulename
Deactivate
sudo a2disconf moduleame
Reference of selected Apache files and folders
| /var/www | Default folder for the site files (e.g. .html files and others). |
| /etc/apache2 | Folder for Apache Web Server configuration files |
| /etc/apache2/apache2.conf | Main configuration file |
| /etc/apache2/ports.conf | File with listening ports |
| /etc/apache2/sites-available | Virtual hosts configuration files; to enable each configuration file, they need to have a link from folder ../sites-enabled |
| /etc/apache2/sites-enabled | Once a virtual host gets enabled, this folder contains a link to the respective configuration file in ../sites-available |
| /etc/apache2/conf-available and /etc/apache2/conf-enabled | Folder which includes the available additional configuration files (in conf-available). Folder conf-enabled contains a link to the configuration file in conf-available. |
| /etc/apache2/mods-available and /etc/apache2/mods-enabled | Folder which includes the available modules (in mods-available). Folder mods-enabled contains a link to the configuration file in conf-available |
| /var/log/apache2/access.log | Log file collecting all requests to web server |
| /var/log/apache2/error.log | Log file collecting error messages |
Modules
The functionality of the core Apache Web Server can be extended with modules. Some of the modules are provided by the Apache development team, but in addition there are also modules provided by third-party developers. To learn how to install and how to configure a module, refer to the specific module's description as details may depend on the specific module.
Typical steps are as follows:
- Install Module
- Activate Module
- Restart Apache
Related articles