Blog

  • Setup WordPress

    Download and extract WordPress

    $ wget https://wordpress.org/latest.tar.gz
    $ sudo mv latest.tar.gz /misc/extHDD/
    $ sudo tar xvzf latest.tar.gz
    $ sudo mv /misc/extHDD/wordpress /misc/extHDDwww.lama-lab.mydns.jp/
    $ sudo chown http:http /misc/extHDDwww.lama-lab.mydns.jp/ -R

    Accomplish Setup

    Visit

    http://www.lama-lab.mydns.jp

    And input all database infomation. Then all is done!!

  • Configure Nginx for WordPress

    Deploy config files

    WordPress config file

    $ sudo vi /etc/nginx/global/wordpress.conf
    location / {
    	# This is cool because no php is touched for static content.
    	# include the "?$args" part so non-default permalinks doesn't break when using query string
    	try_files $uri $uri/ /index.php?$args;
    }
    
    location ~ \.php$ {
    	#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    	include fastcgi_params;
    	fastcgi_intercept_errors on;
    	fastcgi_pass php;
    	#The following parameter can be also included in fastcgi_params file
    	fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    	expires max;
    	log_not_found off;
    }

    Site specific config file

    $ sudo vi /etc/nginx/sites-available/www.lama-lab.mydns.jp.conf
    # Redirect everything to the main site. We use a separate server statement and NOT an if statement - see http://wiki.nginx.org/IfIsEvil
     
    server {
            server_name  _;
            return 302 $scheme://www.lama-lab.mydns.jp$request_uri;
    }
     
    server {
        server_name www.lama-lab.mydns.jp/;
        root /misc/extHDDwww.lama-lab.mydns.jp/;
     
        access_log /var/log/nginx/www.lama-lab.mydns.jp.access.log;
        error_log /var/log/nginx/www.lama-lab.mydns.jp.error.log;
    
        index index.php;
     
        include global/restrictions.conf;
     
        # Additional rules go here.
     
        # Only include one of the files below.
         include global/wordpress.conf;
    #    include global/wordpress-ms-subdir.conf;
    #    include global/wordpress-ms-subdomain.conf;
    
        listen 80;
        listen [::]:80;
    }

    Enable the Web site

    $ sudo ln -s /etc/nginx/sites-available/www.lama-lab.mydns.jp.conf /etc/nginx/sites-enabled/www.lama-lab.mydns.jp.conf
    $ sudo systemctl restart nginx
    $ sudo systemctl restart php-fpm
  • 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.