Hyper Open Edge Cloud

How To Add a Apache Configuration File

How To Add a Matomo Configuration file to run Apache server
  • Last Update:2022-05-12
  • Version:001
  • Language:en

Agenda

  1. Create a new apache configuration file 
  2. Edit file "software.cfg"
  3. Edit file "matomo-instance.cfg.in"
  4. The content of file "apache-httpd.conf.in"
  5. Edit file "buildout.hash.cfg"
  6. Verification

This tutorial will teach you how to add an Apache web server configuration file to make the matomo work normally.

Prerequisites

Create a new apache configuration file 

Create file named "apache-httpd.conf.in" in directory "~/srv/projet/slapos/software/matomo"
How the template file works are same as the matomo configuration template file we added before, slapos will generate a real file in instance according to this template file, and we need to move this real file to a specific directory for it to take effect (this specific path is defined in LAMP).
 

Edit file "software.cfg"

Add a new keyword for instance of matomo about location of the configuration file, this parameter will be passed to the instance configuration file so that we can use it .

Then add a new download section named "template-apache-httpd", it extends Download-Base section.

context = ....
          key matomo_apache_httpd template-apache-httpd:target
....
#download apache-httpd.conf.in
[template-apache-httpd]
<= matomo-download

Add some parameters needed in file "matomo-instance.cfg.in"

Add some php-configuration and other parameters, those parameters will be passed to the Apache configuration file by keyword context in section [matomo-apache-httpd] we add later
# parameters required by the configuration instance
[instance-parameter]
#php.ini parameters
php.memory_limit = 512M
php.date.timezone = Europe/Paris
php.upload_max_filesize = 10240M
php.post_max_size = 10240M
php.session.cookie_secure = True
php.max_execution_time = 1800
php.max_input_time = 3600
php.output_buffering = 'Off'
php.max_file_uploads = 100

[slap-parameter]
instance.cli-url = ${apache-php-configuration:url}

Add a recipe section in file "matomo-instance.cfg.in"

Add the receive section for apache configuration file we added.

The output file should be put in ${directory: apache.d}, which has been set as the root directory of the apache configuration file in LAMP. And in variable context we add the section instance-parameter we mentioned before.

[matomo-apache-httpd]
recipe = slapos.recipe.template:jinja2
template = {{ matomo_apache_httpd }}
rendered = ${directory:apache.d}/matomo.conf
context =
  section parameter_dict apache-php-configuration

Register the file in "part-list"

To make the configuration file work, we need to register it in keyword part-list of section a new custom-application-deployment in file software.cfg, the content in this section will be read by stack LAMP so the file will be valid.
# give the location of the instance-matomo.cfg fil
# Without it the instance-matomo.cfg file will not be executed
[custom-application-deployment]
path = ${template-matomo-instance:output}
part-list = matomo-apache-httpd

The content of file "apache-httpd.conf.in"

<VirtualHost *:{{ parameter_dict['port'] }}>
  ServerAdmin admin@example.com
  DocumentRoot {{ parameter_dict['document-root'] }}/matomo

  SetEnvIf Origin "^http(s)?://(.+\.)?(app\.officejs\.com)$" ORIGIN_DOMAIN=$0
  Header always set Access-Control-Allow-Origin "%{ORIGIN_DOMAIN}e" env=ORIGIN_DOMAIN
  Header always set Access-Control-Allow-Credentials "true" env=ORIGIN_DOMAIN
  Header always set Access-Control-Allow-Methods "PROPFIND, PROPPATCH, COPY, MOVE, DELETE, MKCOL, LOCK, UNLOCK, PUT, GETLIB, VERSION-CONTROL, CHECKIN, CHECKOUT, UNCHECKOUT, REPORT, UPDATE, CANCELUPLOAD, HEAD, OPTIONS, GET, POST" env=ORIGIN_DOMAIN
  Header always set Access-Control-Allow-Headers "Overwrite, Destination, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Authorization" env=ORIGIN_DOMAIN
  Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"

  <Directory {{ parameter_dict['document-root'] }}>
      Options +FollowSymlinks
      AllowOverride All
      Require all granted
      SetEnv HOME {{ parameter_dict['document-root'] }}
      SetEnv HTTP_HOME {{ parameter_dict['document-root'] }}
      Dav off

  </Directory>
  ErrorLog "{{ parameter_dict['log-dir'] }}/matomo-error.log"
  CustomLog "{{ parameter_dict['log-dir'] }}/matomo-access.log" combined

</VirtualHost>
You can find all information about apache server configuration in official website of apache

Add an auto-update section

Create a new section in file "buildout.hash.cfg" corresponding to file we added.
[template-apache-httpd]
filename = apache-httpd.conf.in
md5sum =

Check output configuration file

Run the command in terminal to rebuild
cd ~/srv/project/slapos/software/matomo
../../update-hash
slapos node software --all
slapos node instance --all

Now, there will be a output file "matomo.conf", in path "~/srv/project/runner/slappartX/etc/apache.d/matomo.conf".

This path is been setting as directory of configuration file of apache webrunner in LAMP, so when we put configuration file here, it will work.

X is the slappart where you apache server runs on, if you are not sure, check it with the command

slapos node status
You can use linux command find to check if configuration output file exist:
find ~/srv/project/runner/ -name instance-matomo.cfg
Normally, you will get the result like this:
/srv/slapgrid/slappart9/srv/project/runner/instance/slappart2/etc/apache.d/matomo.conf

Normally, we can access the web pages of matomo by browser. Rerun the bash script to get the URL information.

cd ~/srv/project
./request-matomo-instance.sh

You will find parameters like these:

{'backend-url': 'https://[2001:67c:1254:102::76fd]:9988/',
 'mariadb-url-list': "['mysql://nextcloud:insecure@10.0.25.127:2099/nextcloud']",
 'monitor-base-url': 'https://softinst169422.host.vifib.net',
 'monitor-setup-url': 'https://monitor.app.officejs.com/#page=settings_configurator&url=https://softinst169422.host.vifib.net/public/feeds&username=admin&password=G1SdcxYEKCt9Gnx5',
 'url': 'https://softinst169424.host.vifib.net'}

Copy the url to your browser and you will see the welcome page of matomo.