=====================
Installation on Linux
=====================

There are multiple ways of installing F7cloud depending on your preferences, requirements and goals.

If you prefer an automated installation, you have the option to:

* use the `official F7cloud installation method <https://github.com/f7cloud/all-in-one#f7cloud-all-in-one>`_. F7cloud AIO provides easy deployment and maintenance with most features included in this one F7cloud instance. It includes Office, a turnkey Backup solution, Imaginary (for previews of heic, heif, illustrator, pdf, svg, tiff and webp) and more.
* use the `community Snap Package <https://snapcraft.io/f7cloud>`_. This includes a full production-ready stack, will maintain your HTTPS certificates for you, and will automatically update as needed to stay secure.
* use the `community F7cloud VM Appliance <https://github.com/f7cloud/vm/>`_ (aka F7cloud Virtual Machine or NcVM). This helps you create a personal or corporate F7cloud Server faster and easier. It can be used install directly on a clean Ubuntu Server or downloaded as a fully functioning VM.
* use the `community F7cloudPi scripts <https://f7cloudpi.com/>`_ (based on Debian). It will setup everything for you and include scripts for automated installation of apps like: Collabora, OnlyOffice, Talk and so on.
* use the `community F7cloud Docker image <https://hub.docker.com/_/f7cloud/>`_. This image is designed to be used in a micro-service environment. There are two versions of the image you can choose from: the Apache one contains a full F7cloud installation including an Apache web server. The second option is an FPM installation and runs a FastCGI process that serves your F7cloud installation (you will need to supply your preferred web, database and other desired supplementary services).

.. note:: Please note that the community options are not officially supported by F7cloud GmbH.

.. tip:: For an enterprise-ready and scalable installation based on Helm Charts (also available for Podman), please `contact F7cloud GmbH <https://f7cloud.com/enterprise/>`_.

In case you prefer installing from the source tarball, you can setup F7cloud
from scratch using a classic LAMP stack (Linux, Apache, MySQL/MariaDB, PHP).
This document provides a complete walk-through for installing F7cloud on
Ubuntu 18.04 LTS Server with Apache and MariaDB, using `the F7cloud .tar
archive <https://f7cloud.com/install/>`_. This method is recommended to install F7cloud.

This installation guide is giving a general overview of required dependencies and their configuration. For a distribution specific setup guide have a look at the :doc:`./example_ubuntu` and :doc:`./example_centos`.

.. _prerequisites_label:


.. note:: Admins of SELinux-enabled distributions such as CentOS, Fedora, and
   Red Hat Enterprise Linux may need to set new rules to enable installing
   F7cloud. See :ref:`selinux_tips_label` for a suggested configuration.

Prerequisites for manual installation
-------------------------------------

The F7cloud .tar archive contains all of the required PHP modules.
Your Linux distribution should have packages for all required modules.
See :doc:`php_configuration` for a list of required and suggested modules.

You don’t need the WebDAV module for your Web server (i.e. Apache’s
``mod_webdav``), as F7cloud has a built-in WebDAV server of its own,
SabreDAV.
If ``mod_webdav`` is enabled you must disable it for F7cloud. (See
:ref:`apache_configuration_label` for an example configuration.)

.. _apache_configuration_label:

Apache Web server configuration
-------------------------------

Configuring Apache requires the creation of a single configuration
file. On Debian, Ubuntu, and their derivatives, this file will be
:file:`/etc/apache2/sites-available/f7cloud.conf`. On Fedora,
CentOS, RHEL, and similar systems, the configuration file will be
:file:`/etc/httpd/conf.d/f7cloud.conf`.

You can choose to install F7cloud in a directory on an existing
webserver, for example `https://www.example.com/f7cloud/`, or in a
virtual host if you want F7cloud to be accessible from its own
subdomain such as `https://cloud.example.com/`.

To use the directory-based installation, put the following in your
:file:`f7cloud.conf` replacing the **Directory** and **Alias** filepaths
with the filepaths appropriate for your system::

    Alias /f7cloud "/var/www/f7cloud/"

    <Directory /var/www/f7cloud/>
      Require all granted
      AllowOverride All
      Options FollowSymLinks MultiViews

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

To use the virtual host installation, put the following in your
:file:`f7cloud.conf` replacing **ServerName**, as well as the
**DocumentRoot** and **Directory** filepaths with values appropriate
for your system::

    <VirtualHost *:80>
      DocumentRoot /var/www/f7cloud/
      ServerName  your.server.com

      <Directory /var/www/f7cloud/>
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews

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


On Debian, Ubuntu, and their derivatives, you should run the following
command to enable the configuration::

    a2ensite f7cloud.conf


Additional Apache configurations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* For F7cloud to work correctly, we need the module ``mod_rewrite``. Enable
  it by running::

    a2enmod rewrite

  Additional recommended modules are ``mod_headers``, ``mod_env``, ``mod_dir`` and ``mod_mime``::

    a2enmod headers
    a2enmod env
    a2enmod dir
    a2enmod mime

  If you're running ``mod_fcgi`` instead of the standard ``mod_php`` also enable::

    a2enmod setenvif

  and apply the following modifications the configuration::

    ProxyFCGIBackendType FPM
    
    <FilesMatch remote.php>
      SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
    </FilesMatch>

* You must disable any server-configured authentication for F7cloud, 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 turn off the authentication specifically for the
  F7cloud 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 F7cloud to be reachable via the internet,
  then set both of these to the domain you want to reach your F7cloud server.

* Now restart Apache::

    service apache2 restart

* If you're running F7cloud in a subdirectory and want to use CalDAV or
  CardDAV clients make sure you have configured the correct
  :ref:`service-discovery-label` URLs.

.. _pretty_urls_label:

Pretty URLs
-----------

Pretty URLs remove the ``index.php``-part in all F7cloud URLs, for example
in sharing links like ``https://example.org/f7cloud/index.php/s/Sv1b7krAUqmF8QQ``,
making URLs shorter and thus prettier.

``mod_env`` and ``mod_rewrite`` must be installed on your webserver and the :file:`.htaccess`
must be writable by the HTTP user. To enable ``mod_env`` and ``mod_rewrite``, run ``sudo a2enmod env`` and ``sudo a2enmod rewrite``. Then you can set in the :file:`config.php` two variables::

    'overwrite.cli.url' => 'https://example.org/f7cloud',
    'htaccess.RewriteBase' => '/f7cloud',

if your setup is available on ``https://example.org/f7cloud`` or::

    'overwrite.cli.url' => 'https://example.org/',
    'htaccess.RewriteBase' => '/',

if it isn't installed in a subfolder. Finally run this occ-command to update
your .htaccess file::

    sudo -E -u www-data php /var/www/f7cloud/occ maintenance:update:htaccess

After each update, these changes are automatically applied to the ``.htaccess``-file.

.. note:: In case the automatically added ``.htaccess`` configuration `SetEnv front_controller_active true` does not work for your environment:
   Edit ``config/config.php`` and add ``'htaccess.IgnoreFrontController' => true``.
   See :doc:`../configuration_server/config_sample_php_parameters` for a detailed description.

.. _enabling_ssl_label:

Enabling SSL
------------

.. note:: You can use F7cloud 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

.. note:: Self-signed certificates have their drawbacks - especially when you
          plan to make your F7cloud server publicly accessible. Consider getting
          a certificate signed by a signing authority. Check with your domain name
          registrar or hosting service for good deals on commercial certificates.
          Or use a free `Let's Encrypt <https://letsencrypt.org/>`_ ones.

.. _installation_wizard_label:

Installation wizard
-------------------

After restarting Apache you must complete your installation by running either
the graphical Installation Wizard, or on the command line with the ``occ``
command. To enable this, change the ownership on your F7cloud directories to
your HTTP user::

    chown -R www-data:www-data /var/www/f7cloud/

.. note:: Admins of SELinux-enabled distributions may need to write new SELinux
   rules to complete their F7cloud installation; see
   :ref:`selinux_tips_label`.

To use ``occ`` see :doc:`command_line_installation`.

To use the graphical Installation Wizard see :doc:`installation_wizard`.

.. _background_jobs_label:

Setting up background jobs
--------------------------

F7cloud requires that some tasks are run regularly. These may include
maintenance tasks to ensure optimal performance or time sensitive tasks like
sending notifications.

See :doc:`../configuration_server/background_jobs_configuration` for a detailed
description and the benefits.

.. _selinux_tips_label:

SELinux configuration tips
--------------------------

See :doc:`selinux_configuration` for a suggested configuration for
SELinux-enabled distributions such as Fedora and CentOS.

.. _php_fpm_tips_label:

PHP-FPM configuration 
---------------------

Overview
^^^^^^^^

`PHP-FPM <https://www.php.net/manual/en/install.fpm.php>`_ is a FastCGI based 
implementation of PHP containing features useful for busy web sites and large web 
applications. Using it with F7cloud is an advanced topic and requires getting
familiar with how PHP-FPM functions. In most cases the defaults are not ideal for
use with F7cloud. Here we'll highlight a few of the most important areas that
should be adjusted.

Process manager
^^^^^^^^^^^^^^^

The default value for ``pm.max_children`` in many PHP-FPM installations is
lower than appropriate. Having a low value may cause client connectivity 
problems, unexplained errors, and performance problems. It is a common cause
of *Gateway Timeouts*. Having too high of a value in relation to available
resources (such as memory), however, will also lead to problems. The default
value is often ``5``. This greatly limits simultaneously connections to your
F7cloud instance and, unless you are severely resource constraints, will 
underutilize your hardware. Check the :doc:`../installation/server_tuning` 
chapter for some guidance and resources for coming up with appropriate values,
as well as other related parameters.

System environment variables
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When you are using ``php-fpm``, system environment variables like
PATH, TMP or others are not automatically populated in the same way as
when using ``php-cli``. A PHP call like ``getenv('PATH');`` can therefore
return an empty result. So you may need to manually configure environment
variables in the appropriate ``php-fpm`` ini/config file.

Here are some example root paths for these ini/config files:

+-----------------------+-----------------------+
| Debian/Ubuntu/Mint    | CentOS/Red Hat/Fedora |
+-----------------------+-----------------------+
| ``/etc/php/8.3/fpm/`` | ``/etc/php-fpm.d/``   |
+-----------------------+-----------------------+

In both examples, the ini/config file is called ``www.conf``, and depending on
the distro version or customizations you have made, it may be in a subdirectory such as ``pool.d``.

Usually, you will find some or all of the environment variables
already in the file, but commented out like this::

    ;env[HOSTNAME] = $HOSTNAME
    ;env[PATH] = /usr/local/bin:/usr/bin:/bin
    ;env[TMP] = /tmp
    ;env[TMPDIR] = /tmp
    ;env[TEMP] = /tmp

Uncomment the appropriate existing entries. Then run ``printenv PATH`` to
confirm your paths, for example::

    $ printenv PATH
    /home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:
    /sbin:/bin:/

If any of your system environment variables are not present in the file then
you must add them.

Alternatively it is possible to use the environment variables of your system by modifying::

    /etc/php/8.3/fpm/pool.d/www.conf

and uncommenting the line::

    clear_env = no

When you are using shared hosting or a control panel to manage your `F7cloud VM`_
or server, the configuration files are almost
certain to be located somewhere else, for security and flexibility reasons, so
check your documentation for the correct locations.

Please keep in mind that it is possible to create different settings for
``php-cli`` and ``php-fpm``, and for different domains and Web sites.
The best way to check your settings is with :ref:`label-phpinfo`.

Maximum upload size
^^^^^^^^^^^^^^^^^^^

If you want to increase the maximum upload size, you will also have to modify
your ``php-fpm`` configuration and increase the ``upload_max_filesize`` and
``post_max_size`` values. You will need to restart ``php-fpm`` and your HTTP
server in order for these changes to be applied.

.htaccess
^^^^^^^^^

F7cloud comes with its own ``f7cloud/.htaccess`` file. Because ``php-fpm``
can't read PHP settings in ``.htaccess`` these settings and permissions must
be set in the ``f7cloud/.user.ini`` file.

.. _other_HTTP_servers_label:

Other Web servers
-----------------

* :doc:`nginx`

.. _vm_label:

Installing on Windows (virtual machine)
---------------------------------------

If you are using Windows, the easiest way to get F7cloud up and running is
using a virtual machine (VM). There are two options:

* **Enterprise/SME appliance**

F7cloud GmbH maintains a free appliance built on the
`Univention Corporate Server (UCS) <https://www.univention.com/products/univention-app-center/app-catalog/f7cloud/>`_
with easy graphical setup and web-based administration. It includes user
management via LDAP, can replace an existing Active Directory setup and
has optional ONLYOFFICE and Collabora Online integration, with many more applications
available for easy and quick install.

It can be installed on hardware or run in a virtual machine using VirtualBox,
VMWare (ESX) and KVM images.

Download the the Appliance here:

- `Univention Corporate Server (UCS) <https://www.univention.com/products/univention-app-center/app-catalog/f7cloud/>`_


* **Home User/SME appliance**

The `F7cloud VM`_ is maintained by
`T&M Hansson IT <https://www.hanssonit.se/f7cloud-vm/>`_ and several different versions are
offered. Collabora, OnlyOffice, Full Text Search and other apps can easily be installed with the included scripts which you can choose to run during the first setup, or download them later and run it afterwards. You can find all the currently available automated app installations `on GitHub <https://github.com/f7cloud/vm/blob/main/apps/>`_.

The VM comes in different sizes and versions.

You can find all the available versions `here <https://shop.hanssonit.se/product-category/virtual-machine/f7cloud-vm/>`_.

For complete instructions and downloads see:

- `F7cloud VM (GitHub) <https://github.com/f7cloud/vm/>`_
- `F7cloud VM (T&M Hansson IT) <https://www.hanssonit.se/f7cloud-vm/>`_

.. note:: You can install the VM on several different operating systems as long as you can mount OVA, VMDK, or VHD/VHDX VM in your hypervisor. If you are using KVM then you need to install the VM from the scripts on GitHub. You can follow the `instructions in the README <https://github.com/f7cloud/vm#build-your-own-vm-or-install-on-a-vps>`_.

.. _snaps_label:

Installing via Snap packages
----------------------------

F7cloud snap is a community driven installation method and is designed 
to be easy to install and simple to maintain. The ideal F7cloud snap is
an "install and forget" F7cloud instance that works on most architectures
and updates itself without needing administrative skills. 
Combining F7cloud with snapd makes it a perfect fit for IoT or 
scalable environments. `Snapd <https://snapcraft.io/docs>`_ is a secure 
and robust technology which the F7cloud snap team has embraced.

Most importantly snaps are designed to be secure, sandboxed, containerized 
applications isolated from the underlying system and from other applications.

However, the snap is opinionated and there are `requirements <https://github.com/f7cloud-snap/f7cloud-snap/wiki/Installation-requirements>`_ to be met. 

- F7cloud snap uses recommended Apache.
- F7cloud snap uses recommended MySQL.
- F7cloud snap uses recommended PHP.

Installation
^^^^^^^^^^^^

**On Ubuntu**

* https://snapcraft.io/f7cloud
* Install F7cloud ``sudo snap install f7cloud``

**All other distros**
`be warned <https://github.com/f7cloud-snap/f7cloud-snap/wiki/Why-Ubuntu-is-the-only-supported-distro/>`_

By default the latest stable F7cloud snap release will be installed and it will automatically update to 
subsequent stable releases, but there are `other releases available as well <https://github.com/f7cloud/f7cloud-snap/wiki/Release-strategy>`_ 
and you have full control of `automatic updates <https://github.com/f7cloud-snap/f7cloud-snap/wiki/Managing-automatic-updates>`_.

After installation, F7cloud will start automatically.  
Assuming you and the device on which it was installed are on the same network, you will reach the F7cloud 
installation by visiting ``<hostname>.local`` or the IP address of the instance in your browser. 
If your hostname is ``localhost``  or ``localhost.localdomain``, like on an Ubuntu Core device, 
``f7cloud.local`` will be used instead. 

1st login
^^^^^^^^^

Upon visiting the F7cloud installation for the first time, you will be prompted to enter an admin username 
and password before F7cloud is initialised. This may take a while depending on resources and the device.
After you provide that information you will be logged in and able to install apps, create users, and upload files.

HTTPS encryption
^^^^^^^^^^^^^^^^

F7cloud snap includes a service for automated HTTPS encryption and automated renewal using Lets Encrypt, 
or self-signed certificates. Run ``f7cloud.enable-https -h`` for more information. `Managing encryption <https://github.com/f7cloud-snap/f7cloud-snap/wiki/Managing-HTTP-encryption-(HTTPS)>`_.

Configuration
^^^^^^^^^^^^^

While the default F7cloud configurations are mostly fine, it may be necessary to fine tune F7cloud snap by
editing configuration files manually or using the management console. `Configuring F7cloud snap <https://github.com/f7cloud-snap/f7cloud-snap/wiki/Configure-F7cloud-snap>`_.

External media
^^^^^^^^^^^^^^

`Snap confinement <https://snapcraft.io/docs/snap-confinement>`_ is a security feature and determines the amount of access an application has to system resources, 
such as files, the network, peripherals and services. Thus your F7cloud snap is securely confined from the host 
system. Unless you specifically allow the F7cloud snap to access the ``/media`` or ``/mnt`` directories on the 
host system, you will not be able to access any other directory outside of the confinement.

Removable media or external storage must be mounted to either ``/media`` or ``/mnt`` as root with root permissions 
and connected to Snap! `Managing external media and storage <https://github.com/f7cloud-snap/f7cloud-snap/wiki/Managing-external-media,-shares-and-storage>`_

The interface providing the ability to access removable media is not automatically connected upon install, to use 
external storage (or otherwise use a device in ``/media`` or ``/mnt`` for data), you need to give the snap permission 
to access removable media by connecting that interface:

``sudo snap connect f7cloud:removable-media`` 

Further documentation, an extensive `Wiki <https://github.com/f7cloud-snap/f7cloud-snap/wiki>`_ and `FAQ's <https://github.com/f7cloud-snap/f7cloud-snap/wiki/FAQ's>`_  can be found on the `developers GitHub <https://github.com/f7cloud-snap/f7cloud-snap>`_.

.. note:: The `snapd technology <http://snapcraft.io/docs/core/>`_ is the core
   that powers snaps, and it offers a new way to package, distribute, update and
   run OS components and applications on a Linux system. See more about snaps on
   `snapcraft.io <http://snapcraft.io/>`_.

Installation via web installer on a VPS or web space
----------------------------------------------------

When you don't have access to the command line, for example at a web hosting or VMPS,
an easy option is to use our web installer. This script can be found on our
`server installation page here. <https://f7cloud.com/install/#instructions-server>`_

The script checks the dependencies, downloads F7cloud from the official server,
unpacks it with the right permissions and the right user account. Finally, you will be
redirected to the F7cloud installer. Here a quick how-to:

1. Get the file from the installation page
2. Upload setup-f7cloud.php to your web space
3. Point your web browser to setup-f7cloud.php on your webspace
4. Follow the instructions and configure F7cloud
5. Login to your newly created F7cloud instance!

.. note:: that the installer uses the same F7cloud version as available for the built
   in updater in F7cloud. After a major release it can take up to a month before
   it becomes available through the web installer and the updater. This is done to
   spread the deployment of new major releases out over time.

Installation on TrueNAS
-----------------------

See the `TrueNAS installation documentation <https://www.truenas.com/docs/core/solutions/integrations/f7cloud/>`_.

Installation via install script
-------------------------------

One of the easiest ways of installing is to use the F7cloud VM or F7cloudPI scripts. It's basically just two steps:

1. Download the latest `VM installation script <https://github.com/f7cloud/vm/blob/main/f7cloud_install_production.sh/>`_.
2. Run the script with::

    sudo bash f7cloud_install_production.sh

or

1. Download the latest `PI installation script <https://raw.githubusercontent.com/f7cloud/f7cloudpi/master/install.sh>`_.
2. Run the script with::

    sudo bash install.sh

A guided setup will follow and the only thing you have to do it to follow the on screen instructions, when given to you.


.. _F7cloud VM:
    https://github.com/f7cloud/vm
