Category: Raspberry Pi

About Raspberry Pi

  • Create Database for WordPress

    Database infomation

    • Database name : lamalab_db
    • User name : lamalab_user
    • Password : XXXXXXXX
    • Character set : utf8mb4

    Create Database

    $ sudo mysql -u root -p
    > CREATE DATABASE lamalab_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    > GRANT ALL PRIVILEGES ON lamalab_db.* TO 'lamalab_user'@'localhost' IDENTIFIED BY 'XXXXXXXX';
    > FLUSH PRIVILEGES;
    > EXIT;
  • Configure Nginx

    Make directories

    $ sudo mkdir /etc/nginx/global
    $ sudo mkdir /etc/nginx/sites-available
    $ sudo mkdir /etc/nginx/sites-enable

    Configure Nginx

    Edit /etc/nginx/nginx.conf

    $ sudo vi /etc/nginx/nginx.conf
    # Generic startup file.
    user http;
     
    #usually equal to number of CPUs you have. run command "grep processor /proc/cpuinfo | wc -l" to find it
    worker_processes  auto;
    worker_cpu_affinity auto;
     
    error_log  /var/log/nginx/error.log;
    #pid        /run/nginx.pid;
     
    # Keeps the logs free of messages about not being able to bind().
    #daemon     off;
     
    events {
        worker_connections  1024;
    }
     
    http {
    #   rewrite_log on;
     
        include mime.types;
        default_type       application/octet-stream;
        access_log         /var/log/nginx/access.log;
        sendfile           on;
    #   tcp_nopush         on;
        keepalive_timeout  3;
    #   tcp_nodelay        on;
        gzip               on;
        #php max upload limit cannot be larger than this       
        client_max_body_size 5G;
        index              index.php index.html index.htm;
     
        # Upstream to abstract backend connection(s) for PHP.
        upstream php {
           #this should match value of "listen" directive in php-fpm pool
           server unix:/run/php-fpm/php-fpm.sock;
           #server 127.0.0.1:9000;
        }
     
        include sites-enabled/*;
    }

    Edit restriction.conf

    $ sudo vi /etc/nginx/global/restriction.conf
    # Global restrictions configuration file.
    # Designed to be included in any server {} block.</p>
    location = /favicon.ico {
    	log_not_found off;
    	access_log off;
    }
    
    location = /robots.txt {
    	allow all;
    	log_not_found off;
    	access_log off;
    }
    
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    # If this option is enabled, nextcloud can only upload up to 20MiB.
    #location ~ /\. {
    #	deny all;
    #	access_log off;
    #	log_not_found off;
    #}
  • Setup AutoFS

    You can use AutoFS to mount HDD dynamically.

    Install AutoFS

    $ sudo yay -S autofs

    Configure AutoFS

    $ sudo su
    # _ID=$(blkid --output value --match-tag PARTUUID /dev/sda1)
    # printf "%s%s\n" "extHDD --fstype=auto PARTUUID="\"${_ID}\"" > /etc/autofs/auto.misc
    # exit
    1. the first line, change user to root.
    2. the second line, input /dev/sda1’s partition UUID to variable _ID.
    3. the third line, write out _ID infomation to auto.misc file.
    4. the fourth line, exit to root.

    Start and Enable AutoFS

    $ sudo systemctl start autofs
    $ sudo systemctl enable autofs

    Check the configuration

    $ sudo ls /misc/extHDD
  • Add a new HDD

    Install gdisk

    $ sudo pacman -S gdisk

    Search HDD drives

    $ sudo fdisk -l

    Make partitions

    $ sudo gdisk /dev/sda

    Make a file system

    $ sudo mkfs -t ext4 /dev/sda1

    Check the partitions

    $ sudo df -T
  • Add required PHP modules

    Install required PHP modules

    $ sudo pacman -S php-gd php-imagick php-intl php-sodium

    Enable required PHP modules

    Edit /etc/php/php.ini file

    $ sudo vi /etc/php/php.ini

    uncomment following modules

    curl, dom, exif, fileinfo, hash, imagick, json, mbstring, mysqli, openssl, pcre, sodium, xml, zip, bcmath, filter, gd, iconv, intl, mcrypt, simplexml, xmlreader, zlib
    ssh2, ftp, sockets

    Restart PHP-FPM

    $ sudo systemctl restart php-fpm

    Install Ghostscript

    $ sudo pacman -S ghostscript
  • Install PHP and PHP-FPM

    Install PHP

    $ sudo pacman -S php

    Install PHP-FPM

    PHP-FPM (PHP FastCGI Process Manager) is a PHP implementation of CGI that is useful for heavy-loaded system.

    Install PHP-FPM

    $ sudo pacman -S php-fpm

    Start and Enable PHP-FPM

    $ sudo systemctl start php-fpm
    $ sudo systemctl enable php-fpm
  • Install Database server

    Install MariaDB

    MariaDB is a Open Source Database server.

    $ sudo pacman -S mariadb

    Setup MariaDB server

    $ sudo mysql_install_db --user=mysql --basedir=/usr 
    --datadir=/var/lib/mysql

    Start and Enable Database server

    $ sudo systemctl start mariadb
    $ sudo systemctl enable mariadb

    Secure Installation

    For security issue, secure installation script should be run at first before using MariaDB.

    $ sudo mysql_secure_installation

    Notice: The first root password is set empty. So If you are requested the root password, you should only hit a Enter key.

    On all questions, you would answer “yes” for safety.

  • Dynamic DNS

    MyDNS.jp

    I use MyDNS.jp for Dynamic DNS server.

    IP Notification

    Install required softwares

    $ sudo pacman -S cronie wget

    Setup IP Notification script

    $ sudo vi /etc/cron.hourly/mydns
    #!/bin/sh
    wget -q -O- http://[ID]:[PASS]@ipv4.mydns.jp/login.html > /dev/null 2>&1
    wget -q -O- http://[ID]:[PASS]@ipv6.mydns.jp/login.html > /dev/null 2>&1

    Notice: Here [ID] is your ID, [PASS] is your Password.

    Change the permission of the script.

    $ sudo chmod 755 /etc/cron.hourly/mydns

    Set crontab hourly.

    $ sudo crontab -e
    58 * * * * /etc/cron.hourly/mydns

    Notice: DON’T include “.” character in your cron script file name. If it is included, the script would not work properly.

    Auto Notify on reboot

    To notifiy IP address on reboot automatically, edit cron tab like bellow.

    $ sudo crontab -e
    @reboot sleep 45; /etc/cron.hourly/mydns

    Here, a sleep timer is set to 45 seconds. This timer is required because mydns script should be loaded after the network system has started completely.
    Though this timer value is system dependent, in my experient, 40 to 50 would be a nice value.

  • PPPoE pass-through

    Setup PPPoE pass-through to connect to external with regular port via IPv6 environment.

    Install PPP

    Now a days, using PPP and PPPoE module is a trend for PPPoE pass-through.

    $ sudo pacman -S ppp

    Create connection configuration file

    $ sudo vi /etc/ppp/peers/dsl-provider
    plugin pppoe.so
    
    # Network interface
    eth0
    
    # Login name
    name "<<LOGIN NAME>>"
    
    usepeerdns
    persist
    defaultroute
    hide-password
    noauth

    Notice: Here, <<LOGIN NAME>> is your login name of your provider. And the login name should be double quated.

    Create secrets file

    $ sudo vi /etc/ppp/chap-secrets
    "<<LOGIN NAME>>" * "<<PASSWORD>>"

    Notice: Here, <<LOGIN NAME>> is your login name and <<PASSWORD>> is your password of your provider. The login name and the password should be double quoated.

    Link to provider

    $ sudo ln -s /etc/ppp/peers/dsl-provider
      /etc/ppp/peers/provider

    Notice: You must use absolute path to make a link.

    Connect and Disconnect

    Connect

    $ sudo pon

    Disconnect

    $ sudo poff provider

    Connect on boot

    Edit /etc/modules-load.d/ppp_generic.conf

    $ sudo vi /etc/modules-load.d/ppp_generic.conf

    Add the following line.

    ppp_generic

    Enable ppp@provider service.

    $ sudo systemctl enable ppp@provider.service
  • Setup Web server

    Setup Web server for Web service.

    Install Nginx

    Install Nginx. Nginx is a high performance web server.

    $ sudo pacman -S nginx
    $ sudo systemctl start nginx
    $ sudo systemctl enable nginx

    Configure firewall

    $ sudo ufw allow http
    $ sudo ufw reload

    Check the webserver

    Browse the webserver on a web browser. The IP address should replaced your servers one.

    http://192.168.10.109