Blog

  • Create a database for Nextcloud

    Create a database

    $ sudo mariadb -u root -p
    > CRATE DATABASE nextclouddb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ui;
    > CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'xxxxxxxx';
    > GRANT ALL PRIVILLEGES ON nextclouddb.* TO 'nextclouduser'@'localhost';
    > FLUSH PRIVILEGES;
    > EXIT;

    Here is the example settings

    • Database Name : nextclouddb
    • User Name : nextclouduser
    • Password : xxxxxxxx
  • Install Nextcloud

    Download Nextcloud

    $ cd ~/Downloads
    $ wget https://download.nextcloud.com/server/releases/nextcloud-21.0.0.tar.bz2

    Extract Nextcloud

    $ sudo tar xvjf nextcloud-21.0.0.tar.bz2 -C /var/www

    Configure Apache2

    $ sudo a2enmod rewrite
    $ sudo a2enmod headers
    $ sudo a2enmod dir
    $ sudo a2enmod env
    $ sudo a2enmod mime

    Setup nextcloud.conf

    nextcloud.conf file would be like below.

    Alias /nextcloud "/var/www/nextcloud/"
    
    <Directory /var/www/nextcloud/>
      Require all granted
      AllowOverride All
      Options FollowSymLinks MultiViews
    
      <IfModule mod_dav.c>
        Dav off
      </IfModule>
    </Directory>
    $ sudo cp nextloud.conf /etc/apache2/sites-available
    $ sudo a2ensite nextcloud.conf
    $ sudo systemctl reload apache2
  • Configure php.ini

    Write a page to output the phpinfo

    Make a file named phpinfo.php and place it in the document root. The contents of the file is below.

    <?php phpinfo(); >

    Display phpinfo

    Visit

    http://192.168.10.108/phpinfo.php

    IP address should be modified to yours.

    Find out the item “Loaded Configuration File”. In this section, you can find the path of php.ini that is loaded on the system.

    Edit php.ini

    $ sudo vi /etc/php/7.4/fpm/php.ini
    memory_limit = 1024M
    upload_max_filesize = 128M
    post_max_size = 1024M
    max_execution_time = 3600

    Restart php-fpm

    $ sudo systemctl restart php7.4-fpm
  • Let’s Encrypt

    Install Certbot

    $ sudo apt install certbot python3-certbot-apache

    Add a Certification

    $ sudo certbot --apache -d www.lama-lab.mydns.jp/

    Renew Certbot

    Make a script to renew the certification.

    $ sudo vi /etc/cron.daily/certbot-renew

    In the certbot-renew script, you should write like that.

    #!/bin/sh
    certbot renew --post-hook "systemctl reload apache2"

    Then you must change the permission.

    $ sudo chmod 755 /etc/cron.daily/certbot-renew
  • Install Redis

    Install Redis module

    $ sudo apt install php-redis

    Enable socket communications

    $ sudo vi /etc/redis/redis.conf

    In redis.conf file

    port 0
    unixsocket /var/run/redis/redis-server.sock
    unixsocketperm 770

    Redis Bug fix

    Redis have a bug on loading the service. So fix the bug by editing the service file.

    $ sudo vi /etc/systemd/system/redis.service

    Edit the redis.service file like following.

    [service]
    ExecStartPost=/bin/sh -c "echo $MAINPID > /var/run/redis/redis.pid"

    Reload deamon

    $ sudo systemctl daemon-reload

    Permission modify

    $ sudo usermod -aG redis www-data
    $ sudo chown -R redis:www-data /var/run/redis

    Reload redis-server

    $ sudo systemctl restart redis-server

    Check the configuration

    $ sudo redis-cli -s /var/run/redis/redis-server.sock
    >monitor

    If you got “OK”, settings are correct.

  • Install PHP

    Install PHP

    $ sudo apt install php

    Check the version of PHP

    $ php -v

    Install PHP libraries

    $ sudo apt install php7.4-curl php7.4-xml php7.4-common php7.4-json php7.4-mbstring php7.4-zip php7.4-mysql php7.4-GD php7.4-fileinfo php7.4-bz2 php7.4-intl php7.4-imagick

    Install PHP modules

    $ sudo apt install php-apcu redis redis-server
  • Install MariaDB

    Install MariaDB

    $ sudo apt install mariadb-server

    Initialize MariaDB

    $ sudo mysql_sequre_installation

    Notice: First root password is not set.(none). So you should only type Enter when you are prompted to enter that.

    On all other questions, it is recommended to answer “yes”.

  • Add a new HDD

    Search the HDD

    $ sudo fdisk -l

    Make partition

    $ sudo gdisk /dev/sda

    Make a file system

    $ sudo mkfs -t ext4 /dev/sda1

    Mount the file system

    Use autofs.

    Check

    $ df -T
  • Setup AutoFS

    Install autofs

    $ sudo apt install autofs
    $ sudo systemctl enable autofs
    $ sudo systemctl start autofs

    Edit /etc/auto.master

    $ sudo vi /etc/auto.master
    /misc /etc/auto.misc  <-comment in this line.
    #+auto.master  <-comment out this line.

    Search External HDD

    $ sudo blkid /dev/sda1

    Copy the UUID

    Edit auto.misc

    $ sudo vi /etc/auto.misc

    In this file,

    hdd  -fstype=ext4, rw :/dev/disk/by-uuid/xxx-xxx-xxxx

    Enable Autofs

    $ sudo systemctl enable autofs --now

    Debug Configuration

    $ sudo systemctl stop autofs
    $ sudo automount -fv

  • MyDNS

    Resister your information

    Visit MyDNS site https://www.mydns.jp/ and resister your information.

    Information

    • ID: mydnsxxxxxx
    • Pass: XXXXXXXXX
    • Domain: lama-lab.mydns.jp

    Records

    • * = A
    • * = AAAA
    • www = A
    • www = AAAA

    IP Notification

    $ sudo vi /etc/cron.hourly/mydns

    The contents of the file is

    wget -q -O - http://[ID]:[Pass]@ipv4.mydns.jp/login.html
    wget -q -O - http://[ID]:[Pass]@ipv6.mydns.jp/login.html

    Change the permission of the file

    $ sudo chmod u+x /etc/cron.hourly/mydns