Apache2 webserver

From WickyWiki


Installation

sudo apt-get install apache2


Configuration

General settings: apache2.conf

File: /etc/apache2/apache2.conf

Make sure you keep an original if you feel you should change things, however, you can make every setting you want in the site-specific files.

sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf-backup

General settings (legacy): httpd.conf

File: /etc/apache2/httpd.conf

Many examples on the web will point you to httpd.conf, you should use apache2.conf instead.

Specific site settings: sites-available

Directory: /etc/apache2/sites-available/

Create a copy for each site in this folder, that is one file per domain and port. Examples of different sites and urls:

  • http://newsite.org (http default port is 80)
  • http://newsite2.org (different domain)
  • https://newsite2.org (https default port is 443)
  • http://newsite2.org:8080 (custom port)
  • Probably you have some example site settings 'default':

File: /etc/apache2/sites-available/default

You can start your configuration by making a copy of the example:

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/http_newsite.org

Here is a simple example site:

<VirtualHost *:80>
	Servername newsite.org
	DocumentRoot /var/www/
	<Directory /var/www/>
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>
</VirtualHost>

A client accessing http://newsite.org will be shown the file /var/www/index.html

See also Apache2 configuration for SOGo and MediaWiki.

Enabled sites: sites-enabled

Directory: /etc/apache2/sites-enabled/

Create a link to the file in 'sites-available' for each site that you want enabled. You can use the tool a2ensite for that.

Enable:

sudo a2ensite http_newsite.org

Disable:

sudo a2dissite http_newsite.org

Standard location for websites

Directory: /var/www/

Apache service restart

After any configuration changes you have to restart apache2 for them to take effect:

sudo service apache2 restart

Tips

  • 'Redirect permanent' is cashed client-side (browser) and clients can not be updated. Each browser's cash would need to be cleared before a change to the 'Redirect permanent' is successful. This is quite impractical, better stick to 'Redirect temp' and save yourself some trouble.

...

Redirect temp /index.html http://wilbertvolkers.dyndns.org/mediawiki/

...

  • Generally you should think of cashing of DNS and client-browsers when your settings don't seem to work.
  • Add the following to apache2.conf to suppress a warning when you reload Apache2 stating that no fully qualified servername could be found:
sudo gedit /etc/apache2/apache2.conf
...
ServerName localhost
..

Further reading and examples