danb35 / freenas-iocage-nextcloud

Script to create an iocage jail on FreeNAS for the latest Nextcloud 28 release, including Caddy, MariaDB or PostgreSQL, and Let's Encrypt
GNU General Public License v3.0
250 stars 71 forks source link

Installation fails when using Postgres (pgsql) #219

Open Blingoose opened 2 months ago

Blingoose commented 2 months ago

pgsql installation doesn't work. I'll provide the correct log later.

Blingoose commented 2 months ago

Here is the relevant part from the log:

go: downloading cloud.google.com/go/compute v1.23.0
go: downloading github.com/googleapis/enterprise-certificate-proxy v0.2.5
go: downloading github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
2024/04/28 05:38:35 [INFO] exec (timeout=0s): /usr/local/bin/go build -o /usr/local/bin/caddy -tags nobadger
2024/04/28 05:39:04 [INFO] Build complete: /usr/local/bin/caddy
2024/04/28 05:39:04 [INFO] Cleaning up temporary folder: /tmp/buildenv_2024-04-28-0537.2986694524
+ FILE=latest-29.tar.bz2
+ iocage exec nextcloud fetch -o /tmp https://download.nextcloud.com/server/releases/latest-29.tar.bz2 https://download.nextcloud.com/server/releases/latest-29.tar.bz2.asc
/tmp/latest-29.tar.bz2                                 197 MB 9528 kBps    21s
/tmp/latest-29.tar.bz2.asc                             833  B    9 MBps    00s
+ iocage exec nextcloud fetch -o /tmp https://nextcloud.com/nextcloud.asc
/tmp/nextcloud.asc                                    3100  B   17 MBps    00s
+ iocage exec nextcloud gpg --import /tmp/nextcloud.asc
gpg: Warning: using insecure memory!
gpg: directory '/root/.gnupg' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key D75899B9A724937A: public key "Nextcloud Security <security@nextcloud.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
+ iocage exec nextcloud gpg --verify /tmp/latest-29.tar.bz2.asc
gpg: Warning: using insecure memory!
gpg: assuming signed data in '/tmp/latest-29.tar.bz2'
gpg: Signature made Tue Apr 23 08:14:25 2024 PDT
gpg:                using RSA key 28806A878AE423A28372792ED75899B9A724937A
gpg: Good signature from "Nextcloud Security <security@nextcloud.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 2880 6A87 8AE4 23A2 8372  792E D758 99B9 A724 937A
+ iocage exec nextcloud tar xjf /tmp/latest-29.tar.bz2 -C /usr/local/www/
+ iocage exec nextcloud chown -R www:www /usr/local/www/nextcloud/
+ [ pgsql '=' mariadb ]
+ [ pgsql '=' pgsql ]
+ iocage exec nextcloud sysrc 'postgresql_enable=YES'
postgresql_enable:  -> YES
+ iocage exec nextcloud sysrc 'redis_enable=YES'
redis_enable:  -> YES
+ iocage exec nextcloud sysrc 'php_fpm_enable=YES'
php_fpm_enable:  -> YES
+ [ 0 -eq 1 ]
+ iocage exec nextcloud cp -f /mnt/includes/php.ini /usr/local/etc/php.ini
+ iocage exec nextcloud chown -R www:www /usr/local/etc/php.ini
+ iocage exec nextcloud cp -f /mnt/includes/redis.conf /usr/local/etc/redis.conf
+ iocage exec nextcloud cp -f /mnt/includes/www.conf /usr/local/etc/php-fpm.d/
+ [ 0 -eq 1 ]
+ [ 1 -eq 1 ]
+ iocage exec nextcloud cp -f /mnt/includes/remove-staging.sh /root/
+ [ 0 -eq 1 ]
+ [ 0 -eq 1 ]
+ [ 1 -eq 1 ]
+ echo $'Copying Caddyfile for Let\'s Encrypt DNS cert'
Copying Caddyfile for Let's Encrypt DNS cert
+ iocage exec nextcloud cp -f /mnt/includes/Caddyfile-dns /usr/local/www/Caddyfile
+ iocage exec nextcloud cp -f /mnt/includes/caddy /usr/local/etc/rc.d/
+ [ pgsql '=' mariadb ]
+ iocage exec nextcloud sed -i '' s/yourhostnamehere/nextcloudinstance.com/ /usr/local/www/Caddyfile
+ iocage exec nextcloud sed -i '' s/dns_plugin/cloudflare/ /usr/local/www/Caddyfile
+ iocage exec nextcloud sed -i '' s/api_token/HSkctZtNllWRqisi-uD6nOeqWmCps0Cgm0qWtxqg/ /usr/local/www/Caddyfile
+ iocage exec nextcloud sed -i '' s/jail_ip/192.168.1.23/ /usr/local/www/Caddyfile
+ iocage exec nextcloud sed -i '' s/youremailhere/admin@nextcloudinstance.com/ /usr/local/www/Caddyfile
+ iocage exec nextcloud sed -i '' 's|mytimezone|Asia/Tokyo|' /usr/local/etc/php.ini
+ iocage exec nextcloud sysrc 'caddy_enable=YES'
caddy_enable:  -> YES
+ iocage exec nextcloud sysrc 'caddy_config=/usr/local/www/Caddyfile'
caddy_config:  -> /usr/local/www/Caddyfile
+ iocage restart nextcloud
* Stopping nextcloud
  + Executing prestop OK
  + Stopping services OK
  + Tearing down VNET OK
  + Removing devfs_ruleset: 1000 OK
  + Removing jail process OK
  + Executing poststop OK
No default gateway found for ipv6.
* Starting nextcloud
  + Started OK
  + Using devfs_ruleset: 1000 (iocage generated default)
  + Configuring VNET OK
  + Using IP options: vnet
  + Starting services OK
  + Executing poststart OK
+ iocage exec nextcloud pw usermod www -G redis
+ iocage exec nextcloud chmod 777 /var/run/redis/redis.sock
+ [ '' '==' true ]
+ [ pgsql '=' mariadb ]
+ [ pgsql '=' pgsql ]
+ iocage exec nextcloud cp -f /mnt/includes/pgpass /root/.pgpass
+ iocage exec nextcloud chmod 600 /root/.pgpass
+ iocage exec nextcloud chown postgres /var/db/postgres/
+ iocage exec nextcloud /usr/local/etc/rc.d/postgresql initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locales
  COLLATE:  C
  CTYPE:    C.UTF-8
  MESSAGES: C.UTF-8
  MONETARY: C.UTF-8
  NUMERIC:  C.UTF-8
  TIME:     C.UTF-8
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /var/db/postgres/data13 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... US/Pacific
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/local/bin/pg_ctl -D /var/db/postgres/data13 -l logfile start

+ iocage exec nextcloud su -m postgres -c '/usr/local/bin/pg_ctl -D /var/db/postgres/data13 start'
waiting for server to start....2024-04-28 05:40:03.716 PDT [23491] LOG:  endinglog output to stderr
2024-04-28 05:40:03.716 PDT [23491] HINT:  Future log output will go to log destination "syslog".
 done
server started
+ iocage exec nextcloud sed -i '' 's|mypassword|yPqyBDP2mTGTU0G4XtiDRA==|' /root/.pgpass
+ iocage exec nextcloud psql -U postgres -c 'CREATE DATABASE nextcloud;'
CREATE DATABASE
+ iocage exec nextcloud psql -U postgres -c $'CREATE USER nextcloud WITH ENCRYPTED PASSWORD \'jmI+aBR3io9jUGwbYtiQgA==\';'
CREATE ROLE
+ iocage exec nextcloud psql -U postgres -c 'GRANT ALL PRIVILEGES ON DATABASE nextcloud TO nextcloud;'
GRANT
+ iocage exec nextcloud psql -U postgres -c 'SELECT pg_reload_conf();'
 pg_reload_conf
----------------
 t
(1 row)

+ echo 'PostgreSQL root password is yPqyBDP2mTGTU0G4XtiDRA=='
+ echo 'Nextcloud database password is jmI+aBR3io9jUGwbYtiQgA=='
+ echo 'Nextcloud Administrator password is PMRX95mjfWXjApJo'
+ iocage exec nextcloud mkdir -p /var/log/nextcloud/
+ iocage exec nextcloud chown www:www /var/log/nextcloud
+ [ pgsql '=' mariadb ]
+ [ pgsql '=' pgsql ]
+ iocage exec nextcloud su -m www -c 'php /usr/local/www/nextcloud/occ maintenance:install --database="pgsql" --database-name="nextcloud" --database-user="nextcloud" --database-pass="jmI+aBR3io9jUGwbYtiQgA==" --database-host="localhost:/tmp/.s.PGSQL.5432" --admin-user="admin" --admin-pass="PMRX95mjfWXjApJo" --data-dir="/mnt/files"'
No database drivers (sqlite, mysql, or postgresql) installed.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /usr/local/www/nextcloud/lib/private/Console/Application.php:167
Stack trace:
#0 /usr/local/www/nextcloud/console.php(112): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /usr/local/www/nextcloud/occ(11): require_once('/usr/local/www/...')
#2 {main}{"reqId":"bqYDNOlW36cwk3fJwbQw","level":3,"time":"2024-04-28T12:40:10+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(/usr/local/www/nextcloud/config/config.php): Failed to open stream: No such file or directory at /usr/local/www/nextcloud/lib/private/Config.php#225","userAgent":"--","version":"","data":{"app":"PHP"}}
Command: su -m www -c php /usr/local/www/nextcloud/occ maintenance:install --database="pgsql" --database-name="nextcloud" --database-user="nextcloud" --database-pass="jmI+aBR3io9jUGwbYtiQgA==" --database-host="localhost:/tmp/.s.PGSQL.5432"--admin-user="admin" --admin-pass="PMRX95mjfWXjApJo" --data-dir="/mnt/files" failed!
+ echo 'Failed to install Nextcloud, aborting'
Failed to install Nextcloud, aborting
+ exit 1

Command exit status: 1
Script done on Sun Apr 28 05:40:10 2024
danb35 commented 2 months ago

tl;dr: Unless you really want to use Postgres, you might be better off just using MariaDB. It's been tested more and seems to work pretty well.

The current version of this script installs Postgres 13. But even though that's a currently-maintained version, it doesn't seem to be able to coexist with the php82-pgsql package, which is the reason for the No database drivers (sqlite, mysql, or postgresql) installed. error you're seeing.

So the obvious next step would be to install a newer version of Postgres, like 15. But that leads to other problems I haven't tracked down yet.

Blingoose commented 2 months ago

MariaDB it is. Just out of curiosity, is there any particular reason for not using php83 and let's say MariaDB 10.11?

danb35 commented 2 months ago

MariaDB versions get pretty good long-term support, and 10.6 is what Nextcloud themselves still recommend. I recall having problems using a newer version, but I don't recall what they were. As to PHP 8.3, I frankly hadn't been tracking that. I can see how the script works if I update to it, but it'll probably take me a couple of days.

Blingoose commented 2 months ago

Indeed they recommend 10.6, I didn't pay attention, thanks. I'll try php83 with mdb10.6 and see what's up

danb35 commented 2 months ago

I updated the script this morning to install PHP 8.3 rather than 8.2. With that, MariaDB, and Nextcloud 29, it installs without issues and doesn't give any errors in the admin page other than that HSTS isn't enabled (which is by design). Let me know how it works for you.

Blingoose commented 2 months ago

I'm running the same configuration for about 12 or more hours and it's been flawless. No issues encountered.