Skip to content
tranmh edited this page Jan 9, 2022 · 26 revisions

Server

configured with https://scp.strato.de/
Name: wsj-schach 
IP: 212.227.209.166 
Core: 1 vCore 
RAM: 0.5 GB 
SSD: 20 GB	
OS: Ubuntu 20.04

Packages

apt-get install php apache2 mysql-server htop sendmail vim php7.4-mysqli
systemctl enable mysql
systemctl status apache2
apt-get install php-mysql
apt-get install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
systemctl restart apache2

Database and files from Idefix (Joomla 3.10.x)

scp -rp /var/www/j25wsj/htdocs/* [email protected]:/var/www/html/
scp -rp /var/mysqlbackup/cms/j25wsj_*.sql [email protected]:/var/mysqlbackup/cms/

chown -R www-data:www-data /var/www/html
chmod -R 777 /var/lib/php/sessions

MySQL create database and user

mysql> create database cms;
mysql> create user 'cms'@'localhost' IDENTIFIED BY 'XXX'; # /var/www/html/configuration.php
mysql> grant all privileges on cms.* to 'cms'@'localhost';
mysql> flush privileges;

MySQL database import

root@localhost:/var/mysqlbackup/cms# cat j25wsj_*.sql > all.sql

mysql> use cms;
mysql>  SET autocommit=0 ;
mysql> source /var/mysqlbackup/cms/all.sql; commit;

	Zeile 375: ERROR 1062 (23000): Duplicate entry 'sc wei�e' for key 'j25wsj_finder_terms.idx_term'
	Zeile 376: ERROR 1062 (23000): Duplicate entry 'ga�mann linda' for key 'j25wsj_finder_terms.idx_term'
	Zeile 383: ERROR 1062 (23000): Duplicate entry 'fessler' for key 'j25wsj_finder_terms.idx_term'
	Zeile 384: ERROR 1062 (23000): Duplicate entry 'claussen' for key 'j25wsj_finder_terms.idx_term'
	Zeile 388: ERROR 1062 (23000): Duplicate entry 'zu fu�' for key 'j25wsj_finder_terms.idx_term'
	Zeile 389: ERROR 1062 (23000): Duplicate entry 'da� sich' for key 'j25wsj_finder_terms.idx_term'
	Zeile 390: ERROR 1062 (23000): Duplicate entry 'die spielausschussmitglieder' for key 'j25wsj_finder_terms.idx_term'
	Zeile 409: ERROR 1062 (23000): Duplicate entry '2018 in weissenhorn' for key 'j25wsj_finder_terms.idx_term'
	Zeile 410: ERROR 1062 (23000): Duplicate entry 'alles bereuen ausser' for key 'j25wsj_finder_terms.idx_term'
	Zeile 414: ERROR 1062 (23000): Duplicate entry 'jooss' for key 'j25wsj_finder_terms.idx_term'
	Zeile 415: ERROR 1062 (23000): Duplicate entry 'anla�' for key 'j25wsj_finder_terms.idx_term'
	Zeile 419: ERROR 1062 (23000): Duplicate entry 'felix meissner' for key 'j25wsj_finder_terms.idx_term'
	Zeile 420: ERROR 1062 (23000): Duplicate entry 'grossmeister' for key 'j25wsj_finder_terms.idx_term'
	Zeile 424: ERROR 1062 (23000): Duplicate entry 'da� es nur' for key 'j25wsj_finder_terms.idx_term'
http://212.227.209.166/administrator/ with error, if something is missing.

PHP Warning:  session_start(): Failed to read session data: user (path: /var/lib/php/sessions) in /var/www/html/libraries/joomla/session/handler/native.php on line 260

Create an admin account

INSERT INTO `j25wsj_users`
   (`name`, `username`, `password`, `params`, `registerDate`, `lastvisitDate`, `lastResetTime`)
VALUES ('Administrator2', 'admin2',
    'd2064d358136996bd22421584a7cb33e:trd7TvKHx6dMeoMmBVxYmg0vuXEA4199', '', NOW(), NOW(), NOW());
INSERT INTO `j25wsj_user_usergroup_map` (`user_id`,`group_id`)
VALUES (LAST_INSERT_ID(),'8');

login with password secret and change the password for admin2:

http://212.227.209.166/administrator/index.php?option=com_admin&view=profile&layout=edit

php.ini

mkdir /var/www/tmp
chown -R www-data:www-data /var/www/tmp

root@localhost:/etc/php/7.4/apache2# diff php.ini php.ini.orig_2021-12-28
215c215
< output_buffering = Off
---
> output_buffering = 4096
694c694
< post_max_size = 200M
---
> post_max_size = 8M
842c842
< upload_tmp_dir = /var/www/tmp
---
> ;upload_tmp_dir =
846c846
< upload_max_filesize = 200M
---
> upload_max_filesize = 2M

systemctl restart apache2

configuration.php

root@localhost:/var/www# mkdir logs
root@localhost:/var/www# chown -R www-data:www-data logs

root@localhost:/var/www/html# vi configuration.php
        public $log_path = '/var/www/logs';
        public $tmp_path = '/var/www/tmp';

htaccess

root@localhost:/var/www/html# apache2ctl -M
# "rewrite_module (shared)" was not seen
root@localhost:/var/www/html# a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
  systemctl restart apache2
root@localhost:/var/www/html# systemctl restart apache2
root@localhost:/var/www/html# apache2ctl -M
# "rewrite_module (shared)" is now listed

vi /etc/apache2/sites-enabled/000-default.conf
<Directory /var/www/html>
        Options +Includes -Indexes +MultiViews
        AllowOverride All
</Directory>

<VirtualHost *:80>
        RewriteEngine on

ssh authorized_keys from Idefix

scp /root/.ssh/authorized_keys [email protected]:/root/.ssh/

Apache2 log rotation

The default one seems to be good enough:

cat /etc/logrotate.d/apache2
/var/log/apache2/*.log {
    daily
    missingok
    rotate 14
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
                if invoke-rc.d apache2 status > /dev/null 2>&1; then \
                    invoke-rc.d apache2 reload > /dev/null 2>&1; \
                fi;
    endscript
    prerotate
        if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
            run-parts /etc/logrotate.d/httpd-prerotate; \
        fi; \
    endscript
}

Test

  • Visit the frontend test all sites.
  • Visit the backend as admin2 and modify one existing page, save and check if you can see the changes on frontend.

Update to Joomla! 4

Follow https://docs.joomla.org/Joomla_3.x_to_4.x_Step_by_Step_Migration we were hit by error 'Class 'JDispatcher' not found'. So no update to Joomla 4.0.5 yet.

Mail forwarding of root user

 echo "[email protected], /root/mailbox" > /root/.forward

Time

date
#timedatectl list-timezones
timedatectl set-timezone Europe/Berlin
date

systemctl status systemd-timesyncd
vi /etc/systemd/timesyncd.conf
# add 
# NTP=ntp.uni-osnabrueck.de
# FallbackNTP=ntp.ubuntu.com
timedatectl set-ntp 1
systemctl restart systemd-timesyncd
sleep 10
systemctl status systemd-timesyncd

Backup

We use the default backup client feature of Strato in scp.strato.de. You can see it at the cyber proctection console.

Wöchentlich vollständig, täglich inkrementell.

Aufbewahrungsdauer

  • Monatlich: 6 Monate
  • Wöchentlich: 4 Wochen
  • Täglich: 7 Tage
systemctl status acronis_mms
# backup log:
vi /var/lib/Acronis/BackupAndRecovery/MMS/mms.0.log

Apache with PHP-FPM

see also https://tecadmin.net/setup-apache-php-fpm-ubuntu-20-04/

sudo apt update 
sudo apt install apache2 libapache2-mod-fcgid -y

sudo apt install php7.4 php7.4-fpm -y
a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm

vim /etc/apache2/sites-available/000-default.conf
#add the following lines:
<FilesMatch \.php$>
	# 2.4.10+ can proxy to unix socket
	SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>

# we use the php.ini, which was already configured with apache2
mv /etc/php/7.4/fpm/php.ini /etc/php/7.4/fpm/php.ini_orig_2021-12-29
ln -s /etc/php/7.4/apache2/php.ini /etc/php/7.4/fpm/php.ini

systemctl restart apache2
systemctl restart php7.4-fpm

# tests:
systemctl status php7.4-fpm
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
# you should see "Server API FPM/FastCGI"

SSL

Follow https://serverspace.io/support/help/how-to-get-lets-encrypt-ssl-on-ubuntu/

sudo ufw allow 80
sudo ufw allow 443
sudo apt install letsencrypt
sudo systemctl status certbot.timer
sudo certbot certonly --standalone --agree-tos --preferred-challenges http -d wsj-schach.de
apt install python3-certbot-apache
sudo certbot --apache --agree-tos --preferred-challenges http -d wsj-schach.de

# check 1
# https://www.ssllabs.com/ssltest/analyze.html?d=wsj-schach.de # using browser
# visit https://wsj-schach.de/ and http://wsj-schach.de/
# forward http://wsj-schach.de to https://wsj-schach.de works

# check 2
# need to change template to point to https://css.svw.info instead of http://css.svw.info
vi /var/www/html/templates/svw2/index.php
# change 
# $doc->addStyleSheet("http://css.svw.info/yaml412/css/svw.css");
# to 
# $doc->addStyleSheet("https://css.svw.info/yaml412/css/svw.css");

# check 3
# want have forward http://www.wsj-schach.de to https://wsj-schach.de, add the following lines to:
vi /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
...
RewriteEngine on
RewriteCond %{SERVER_NAME} =wsj-schach.de [OR]
RewriteCond %{SERVER_NAME} =www.wsj-schach.de
RewriteRule ^ https://wsj-schach.de%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
systemctl restart apache2

# FIXME: still do not support https://www.wsj-schach.de in Firefox, Chrome accepts it with warning:
Redirecting navigation www.wsj-schach.de -> wsj-schach.de because the server presented a certificate valid for wsj-schach.de but not for www.wsj-schach.de. To disable such redirects launch Chrome with the following flag: --disable-features=SSLCommonNameMismatchHandling

Limiting Disk Size

journalctl --disk-usage
vi /etc/systemd/journald.conf
# SystemMaxUse=100M
journalctl --vacuum-time=10d
journalctl --vacuum-size=100M
journalctl --disk-usage

du -sh /var/lib/mysql
vi /etc/mysql/mysql.conf.d/mysqld.cnf
# binlog_expire_logs_seconds      = 864000
# max_binlog_size   = 100M
systemctl restart mysql.service
du -sh /var/lib/mysql

Useful links