Configure Apache for Manual Installation on Linux

Introduction

This document describes the basic configuration of your Apache webserver for the use with ownCloud. It assumes that you already have successfully installed the Apache Webserver. Please read the Apache Documentaion for more or enhanced configuration options.

Configure Apache

On Debian, Ubuntu, and their derivatives, Apache installs with a useful configuration. All you have to do is create an /etc/apache2/sites-available/owncloud.conf file with these lines in it, replacing the Directory and other file paths with your own file paths:

Alias /owncloud "/var/www/owncloud/"

<Directory /var/www/owncloud/>
  Options +FollowSymlinks
  AllowOverride All

 <IfModule mod_dav.c>
  Dav off
 </IfModule>
</Directory>

Then create a symlink to /etc/apache2/sites-enabled:

ln -s /etc/apache2/sites-available/owncloud.conf /etc/apache2/sites-enabled/owncloud.conf

Additional Apache Configurations

  • For ownCloud to work correctly, we need the module mod_rewrite. Enable it by running: a2enmod rewrite. Additionally recommended modules are mod_headers, mod_env, mod_dir, mod_mime, and mod_unique_id. To enable them, run the following commands:

      a2enmod headers
      a2enmod env
      a2enmod dir
      a2enmod mime
      a2enmod unique_id
    If you want to use the the OAuth2 app, then mod_headers must be installed and enabled.
  • You must disable any server-configured authentication for ownCloud, as it uses Basic authentication internally for DAV services. If you have turned on authentication on a parent folder (via, e.g., an AuthType Basic directive), you can disable the authentication specifically for the ownCloud entry. Following the above example configuration file, add the following line in the Directory section

    Satisfy Any
  • When using SSL, take special note of the ServerName. You should specify one in the server configuration, as well as in the CommonName field of the certificate. If you want your ownCloud to be reachable via the internet, then set both of these to the domain you want to reach your ownCloud server.

  • Now restart Apache

    service apache2 restart
  • If you’re running ownCloud in a sub-directory and want to use CalDAV or CardDAV clients, make sure you have configured the correct Service Discovery URLs.

Apache Mod_Unique_Id Configuration

The use of mod_unique_id enables an administor to trace requests via logfiles.

mod_unique_id provides a magic token for each request which is guaranteed to be unique across "all" requests under very specific conditions.

If you enable the module, there is nothing else that you have to do, as ownCloud automatically includes the UNIQUE_ID environment variable, which the module makes available, in ownCloud’s log file.

To confirm that it’s working though, check that the UNIQUE_ID environment variable is being set, by running phpinfo() (as in the screenshot below).

phpinfo() showing that Apache is sending the UNIQUE_ID value from mod_unique_id

Next, compare the value set for UNIQUE_ID in the output of phpinfo() with the value in ownCloud’s log file, to ensure that they’re the same. In the example below, you can see an example log entry, where ownCloud is logging the unique id provided by Apache, as the value for the first key reqId in the record.

{
	"reqId": "XDyankIou@F-GwxW82dx7QAAAAo",
	"level": 3,
	"time": "2019-01-14T14:20:14+00:00",
	"remoteAddr": "127.0.0.1",
	"user": "--",
	"app": "PHP",
	"method": "GET",
	"url": "\/index.php\/apps\/files\/?dir=\/Documents&fileid=26",
	"message": "..."
}

Enable SSL

You can use ownCloud over plain HTTP, but we strongly encourage you to use SSL/TLS to encrypt all of your server traffic, and to protect user’s logins and data in transit.

Apache installed under Ubuntu comes already set-up with a simple self-signed certificate. All you have to do is to enable the ssl module and the default site. Open a terminal and run:

a2enmod ssl
a2ensite default-ssl
service apache2 reload
Self-signed certificates have their drawbacks - especially when you plan to make your ownCloud server publicly accessible. You might want to consider getting a certificate signed by a commercial signing authority. Check with your domain name registrar or hosting service for good deals on commercial certificates.
Please read the Using Let’s Encrypt SSL Certificates if you want to use free of charge certificates for Apache.

Multi-Processing Module (MPM)

Apache prefork has to be used. Don’t use a threaded MPM like event or worker with mod_php, because PHP is currently not thread safe.

If you want to use a threaded MPM, look at a FastCGI configuration where PHP is running in its own memory space. ownCloud limit´s its support to Apache prefork only.