Jail: cloud

one time
zfs create ship/cloud

create jail
export JAIL=cloud
export JAILHOSTNAME=cloud
export JAILDOMAIN=ahlawat.com
export JAILIP=59
export JAILUSER=X
export JAILUSERID=1000
export JAILUSERVNC=false

/root/FreeBSD/jails/create.sh $JAIL $JAILHOSTNAME $JAILDOMAIN $JAILIP $JAILUSER $JAILUSERID $JAILUSERVNC

iocage exec $JAIL "mkdir /mnt/cloud"
iocage fstab -a $JAIL /mnt/ship/cloud /mnt/cloud nullfs rw 0 0
iocage exec $JAIL "mkdir /mnt/sharad"
iocage fstab -a $JAIL /mnt/data/users/sharad /mnt/sharad nullfs rw 0 0
iocage exec $JAIL "mkdir /mnt/rachna"
iocage fstab -a $JAIL /mnt/data/users/rachna /mnt/rachna nullfs rw 0 0
iocage exec $JAIL "mkdir /mnt/nivi"
iocage fstab -a $JAIL /mnt/data/users/nivi /mnt/nivi nullfs rw 0 0
iocage exec $JAIL "mkdir /mnt/rishabh"
iocage fstab -a $JAIL /mnt/data/users/rishabh /mnt/rishabh nullfs rw 0 0
iocage fstab -l $JAIL

iocage exec $JAIL "pkg install -y sudo apache24 redis ffmpeg php82 php82-bcmath php82-bz2 php82-ctype php82-curl php82-dom php82-exif php82-fileinfo php82-filter php82-ftp php82-gd php82-gmp php82-iconv php82-imap php82-intl php82-ldap php82-mbstring php82-mysqli php82-opcache php82-pcntl php82-pdo php82-pdo_mysql php82-pecl-APCu php82-pecl-imagick php82-pecl-mcrypt php82-pecl-redis php82-posix php82-session php82-simplexml php82-sysvsem php82-xml php82-xmlreader php82-xmlwriter php82-xsl php82-zip php82-zlib"

## apache-openoffice optional

iocage exec $JAIL "sysrc apache24_enable=YES"
iocage exec $JAIL "cp /mnt/config/httpd.conf /usr/local/etc/apache24/"
iocage exec $JAIL "cp /mnt/config/020_mod_ssl.conf /usr/local/etc/apache24/modules.d/"
iocage exec $JAIL "cp /mnt/config/php.ini /usr/local/etc/php.ini"

iocage exec $JAIL "sysrc php_fpm_enable=YES"
iocage exec $JAIL "cp -f /mnt/config/www.conf /usr/local/etc/php-fpm.d/"
iocage exec $JAIL "service php-fpm start"

iocage exec $JAIL "sysrc redis_enable=YES"
iocage exec $JAIL "cp /mnt/config/redis.conf /usr/local/etc/"
iocage exec $JAIL "service redis start"

iocage exec $JAIL "fetch -o /tmp https://download.nextcloud.com/server/releases/latest-28.tar.bz2"
iocage exec $JAIL "tar xjf /tmp/latest-28.tar.bz2 -C /usr/local/www/apache24/data/"
iocage exec $JAIL "chown -R www:www /usr/local/www/apache24/data /mnt/"

iocage exec $JAIL "service apache24 restart"

# php -r "if (new Redis() == true){ echo \"OK \r\n\"; }"

iocage console $JAIL

touch /var/log/nextcloud.log
chown www:www /var/log/nextcloud.log

cd /usr/local/www/apache24/data/nextcloud/
sudo -u www php occ maintenance:install --database "mysql" --database-name "nextcloud" --database-host "db.ahlawat.com:3306" --database-user "nextcloud" --database-pass "mysql__nextcloud" --admin-user "admin" --admin-pass "REPLACEME" --data-dir "/mnt/cloud"

su -m www -c "php occ config:system:set trusted_domains 1 --value=cloud.ahlawat.com"
su -m www -c "php occ config:system:set trusted_domains 2 --value=192.168.0.59"
su -m www -c "php occ config:system:set overwrite.cli.url --value=\"https://cloud.ahlawat.com/\""
su -m www -c "php occ config:system:set htaccess.RewriteBase --value=/"
su -m www -c 'php occ config:system:set filelocking.enabled --value=true'
su -m www -c 'php occ config:system:set memcache.local --value="\OC\Memcache\APCu"'
su -m www -c 'php occ config:system:set memcache.locking --value="\OC\Memcache\Redis"'
su -m www -c 'php occ config:system:set redis host --value="/tmp/redis.sock"'
su -m www -c 'php occ config:system:set redis port --value=0 --type=integer'
su -m www -c "php occ config:system:set dbhost --value=db.ahlawat.com"
su -m www -c "php occ config:system:set dbport --value=3306"
su -m www -c "php occ config:system:set logtimezone --value=America/Los_Angeles"
su -m www -c "php occ config:system:set log_type --value=file"
su -m www -c "php occ config:system:set logfile --value=/var/log/nextcloud.log"
su -m www -c "php occ config:system:set loglevel --value=2"
su -m www -c "php occ config:system:set logrotate_size --value=104847600"

crontab -u www /mnt/config/crontab_add
su -m www -c "php occ background:cron"
su -m www -c "php occ maintenance:update:htaccess"

#Disable SSL offload in jail environment
su -m www -c "php occ app:enable encryption"
su -m www -c "php occ encryption:enable"
su -m www -c "php occ encryption:disable"

#Enable required modules
su -m www -c "php occ app:enable user_ldap"
su -m www -c "php occ app:enable files_external"

#workaround for occ (in shell just use occ instead of su -m www -c "....")
echo "alias occ=~/occ.sh" >> /root/.bash_profile
echo 'su -m www -c php\ ``/usr/local/www/apache24/data/nextcloud/occ\ "$*"``' > ~/occ.sh
chmod 755 ~/occ.sh

Notes:

SQLSTATE[HY001]: Memory allocation error: 1038 Out of sort memory, consider increasing server sort buffer size.
Set:
sort_buffer_size = 4M
in mysql my.cnf

Manual Upgrade Process
# Update Stuck: Parsing response failed - https://github.com/nextcloud/updater/issues/156
cd /usr/local/www/apache24/data/
curl -O https://download.nextcloud.com/server/releases/nextcloud-28.0.1.zip
cd nextcloud
#changed maintenance mode to true (ignore if occ already deleted by failed web upgrade process)
su -m www -c "php occ maintenance:mode --on"
cd ..
mv nextcloud nextcloud.old
unzip nextcloud-28.0.1.zip
cp nextcloud.old/config/config.php nextcloud/config
chown -R www:nogroup nextcloud
cd nextcloud
#changed maintenance mode to false
su -m www -c "php occ maintenance:mode --off"
cd ..
Browsed to main URL - redirected directly to database update procedure 
Now, its updated. After this procedure, you may delete some files:
rm -rf nextcloud.old
rm nextcloud-28.0.1.zip

Login as admin:
check settings overview for other operations
eg.: su -m www -c "php occ db:add-missing-indices"
check logs to fix any errors 

If updater is stuck
cd /usr/local/www/apache24/data/nextcloud/
su -m www -c "php occ maintenance:repair"

Manual Upgrade Process
https://docs.nextcloud.com/server/23/admin_manual/maintenance/manual_upgrade.html
https://docs.nextcloud.com/server/23/admin_manual/maintenance/backup.html

Need to reinstall disabled apps
calendar, contacts, tasks, rainloop, deck, groupfolders, talk, maps, news, splash
( sync CalDAV and CardDAV with DAVx and OpenTasks apps on Android - installed using F-Droid market place )

Disabled plugins: Federation, Monitoring, Nextcloud Announcements, Usage Survey
(need plugins support and recommendation for various administrative operations)

# Careful - these commands may damage DATA
su -m www -c "php occ maintenance:mode --on"
su -m www -c "php occ maintenance:data-fingerprint"
su -m www -c "php occ maintenance:mimetype:update-db"
su -m www -c "php occ maintenance:mimetype:update-js"
su -m www -c "php occ maintenance:theme:update"
su -m www -c "php occ maintenance:repair"
su -m www -c "php occ maintenance:mode --off"

su -m www -c "php occ files:scan --all"


Alternate CalDAV/CardDAV
#NOT INSTALLED - using NextCloud
# baikal:https://sabre.io/baikal/install/
# wget https://github.com/sabre-io/Baikal/archive/0.6.1.tar.gz
# cd /usr/local/www/apache24
# tar -xvzf /mnt/config/0.6.1.tar.gz
# chown -R www:www Baikal-0.6.1
# Composer is a tool for dependency management in PHP - https://getcomposer.org/download/
# pkg install php73-composer php73-simplexml php73-xmlwriter php73-xmlreader
# composer install
# ln -s /usr/local/www/apache24/Baikal-0.6.1/html cal


Showcased here is a capital and operational cost effective approach, using minimal server and networking hardware with multiple virtualized applications for Home and Business. This solution template can be easily scaled out and adapted for larger Enterprise deployments.
drop by the diyIT Matrix public room at #diyit:matrix.ahlawat.com
if you have any IT questions/feedback or to request pro bono consulting for a nonprofit

message me privately at @sharad:matrix.ahlawat.com
or email me at - sharad@ahlawat.com - pgpkey: 68DD6B89
Networking and Security Technologist.
EngineerĀ andĀ an avid Programmer.

https://sharad.ahlawat.com
strive to learn and pass on the knowledge to the next generation
one day humanity will understand the meaning of life and hopefully it will be more than ASCII 42 = "*" regex for whatever you want it to be,
and destiny is more than just a roll of a pair of dice with 42 dots (Lets nail down Quantum Entanglement)

May you Live Long (Intelligently) and Prosper and work on technology that matters.
© 2024 Sharad Ahlawat

No personal identifying data is collected or any form of analytics/metrics reported to a third-party by this website.