1. Pack Data & Configuration
1.1 Create a Directory for Storing Backup Files
mkdir /home/backup
1.2 Pack Website Files
# backup wordpress data
tar -cjvf /home/backup/wordpress.tar.bz2 /var/www/wordpress
# backup Nextcloud data
tar -cjvf /home/backup/nextcloud.tar.bz2 /var/www/nextcloud
1.3 Pack MySQL Data
# backup wordpress database
mysqldump -u root -p db_wordpress > /home/backup/db_wordpress.dump
# backup nextcloud database
mysqldump -u root -p db_nextcloud > /home/backup/db_nextcloud.dump
1.4 Pack Configuration
# backup caddy v1 configuration
tar -cjvf /home/backup/caddy_config.tar.bz2 /etc/caddy \
/etc/systemd/system/caddy.service \
`which caddy`
# backup v2ray configuration
tar -cjvf /home/backup/v2ray_config.tar.bz2 /etc/v2ray \
/etc/systemd/system/v2ray.service \
`which v2ray`
# backup php configuration
tar -cjvf /home/backup/php_config.tar.bz1 /etc/php*
1.5 Pack Backup Directory
# change the name to whatever you want
tar -cjvf /home/bakup_from_old_server.tar.bz2 /home/backup
2. Migrate Data to Another Server
2.1 Transfer the File with 'scp'
scp -P PORT /home/backup_from_old_server.tar.bz2 root@NEW_SERVER:/home
2.2 Or Transfer File with 'rsync'
rsync -av --progress \
-e 'ssh -p PORT' /home/backup_from_old_server.tar.bz2
root@NEW_SERVER:/home
# rsync needs to be installed on the new server
3. Install & Configure Apps on New Server
3.1 Caddy v2
3.1.1 Install Caddy v2
dnf update
dnf install 'dnf-command(copr)'
dnf copr enable @caddy/caddy
dnf update && dnf install caddy -y
3.1.2 Configure Caddyfile & sites
coming soon or never...
3.2 Remi PHP v8.1
# Rocky Linux default php8.1 module from AppStream
# has conflict issues between php-common and php-pecl-imagick
# the 2rd one is necessary for some WordPress themes
dnf install \
dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf module list php
dnf module reset php
dnf module enable php:remi-8.1
dnf install php php-fpm php-cli php-intl
php-zip php-mysqlnd php-gd php-xml \
php-posix php-apcu php-pecl-imagick
# configure php-fpm
sed -i \
-e '/^user\ =/s/^.*$/user = caddy/1' \
-e '/^group =/s/^.*$/group = caddy/1' \
-e '/^listen.acl_users.*/s/^.*$/listen.acl_group = caddy/1' \
/etc/php-fpm.d/www.conf
# start php-fpm service
systemctl enable php-fpm
systemctl restart php-fpm
3.3 MySQL or MariaDB
3.3.1 Install MySQL
# MySQL is installed in this case
dnf install mysql-server
systemctl enable mysqld && systemctl start mysqld
3.3.2 Create MySQL Databases & Users
# connect to MySQL
mysql -u root -p
# In this case, database for WordPress is 'db_wordpress',
# Database for nextcloud is 'db_nextcloud';
# User for WordPress is 'user_wordpress',
# User for NextCloud is 'user_nextcloud'.
# Password for user_wordpress is 'password_wp'
# Password for user_nextcloud is 'password_nc'
mysql> create database db_wordpress default character set utf8mb4 collate utf8mb4_unicode_ci;
mysql> create user 'user_wordpress'@'localhost' identified by 'password_wp';
mysql> grant all on db_wordpress.* to 'user_wordpress'@'localhost' identified by 'password_wp';
mysql> grant all privileges on db_wordpress.* to 'user_wordpress'@'localhost' with grant option;
mysql> create database db_nextcloud default character set utf8mb4 collate utf8mb4_unicode_ci;
mysql> create user 'user_nextcloud'@'localhost' identified by 'password_nc';
mysql> grant all on db_nextcloud.* to 'user_nextcloud'@'localhost' identified by 'password_nc';
mysql> grant all privileges on db_nextcloud.* to 'user_nextcloud'@'localhost' with grant option;
mysql> flush privileges;
FLUSH PRIVILEGES;
4. Restore Data File
4.1 Unpack Backup File
tar -xjvf /home/backup_from_old_server.tar.bz2 -C /home/
4.2 Genenate Caddy Configuration
4.3 Modify PHP Configuration
vi /etc/php.ini
# Before
file_uploads => Off
max_file_uploads => 2
memory_limit => 128M
upload_max_filesize => 2M
# After
file_uploads => On
max_file_uploads => 20
memory_limit => 512M
upload_max_filesize => 5G
4.4 Restore MySQL Data
mysql -u root -p db_wordpress < /home/backup/db_wordpress.dump
mysql -u root -p db_nextcloud < /home/backup/db_nextcloud.dump
4.5 Restore v2ray Configuration & command
cp /home/backup/usr/local/bin/v2ray /usr/local/bin
chmod +x /usr/local/bin/v2ray
cp -r /home/backup/etc/v2ray /etc/
cp /path/to/backup/v2ray.service /etc/systemd/system
systemctl daemon-reload
systemctl enable v2ray && systemctl start v2ray
5. Configure Firewall & SELinux
5.1 Firewalld
5.1.1 Enable Firewalld Service
systemctl enable firewalld
systemctl restart firewalld
5.1.2 Check Current Configuration
firewall-cmd --list-all
5.1.3 Open Port 443 on firewall
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
firewall-cmd --list-all | grep 443
5.2 Selinux
5.2.1 Enable Selinux
sed -i \
'/^SELINUX=/s/^SELINUX=.*/SELINUX=enforcing/1' /etc/selinux/config
setenforce 1
getenforce
5.2.2 Configure Selinux for NextCloud
# modify the path to fit your situation
nc_path='/path/to/nextcloud'
semanage fcontext -a -t httpd_sys_rw_content_t $nc_path/data(/.*)?
semanage fcontext -a -t httpd_sys_rw_content_t $nc_path/config(/.*)?
semanage fcontext -a -t httpd_sys_rw_content_t $nc_path/apps(/.*)?
semanage fcontext -a -t httpd_sys_rw_content_t $nc_path/.htaccess
semanage fcontext -a -t httpd_sys_rw_content_t $nc_path/.user.ini
semanage fcontext -a -t \
httpd_sys_rw_content_t \
$nc_path/3rdparty/aws/aws-sdk-php/src/data/logs(/.*)?
restorecon -Rv $nc_path
5.2.3 Configure Selinux for WordPress
wp_path='/path/to/wordpress'
semanage fcontext -a -t \
httpd_sys_rw_content_t $wp_path/wp-content(/.*)?
php_files='
xmlrpc.php
wp-blog-header.php
readme.html
wp-signup.php
index.php
wp-cron.php
wp-config-sample.php
wp-login.php
wp-settings.php
license.txt
wp-mail.php
wp-links-opml.php
wp-load.php
wp-activate.php
wp-trackback.php
wp-comments-post.php
'
for i in `echo $php_files`;
do
semanage fcontext -a -t httpd_sys_rw_content_t $i;
done
restorecon -Rv $wp_path
6. Verify Server Status
6.1 Caddy Status
systemctl status caddy
6.2 V2ray Status
systemctl status v2ray
6.3 MySQL Status
systemctl status mysqld
6.4 Open NextCloud & WordPress URL with Lynx
dnf install lynx -y
lynx https://your.wordpress.url
lynx https://your.nextcloud.url