Error Koneksi Database setelah Update ke 4.2.2

Error Koneksi Database setelah Update ke 4.2.2

SMA GNBS Official發表於
Number of replies: 13
Saya barusaja melakukan update versi moodle ke 4.2.2 tetapi tiba-tiba muncul pesan seperti ini error database

Mohon kiranya bisa diberi solusi...
評比平均分數: -
In reply to SMA GNBS Official

Re: Error Koneksi Database setelah Update ke 4.2.2

Leon Stringer發表於
Core developers的相片 Particularly helpful Moodlers的相片

I just updated the Moodle version to 4.2.2 but suddenly a message like this appeared

When I upgraded to Moodle 4.2 I got this Error: Database connection failed message. I had to edit config.php changing $CFG->dbhost = 'localhost' to $CFG->dbhost = '127.0.0.1'. This fixed the error, but I don't know why – possibly an SELinux change on CentOS Stream 9.

In reply to Leon Stringer

Re: Error Koneksi Database setelah Update ke 4.2.2

Howard Miller發表於
Core developers的相片 Documentation writers的相片 Particularly helpful Moodlers的相片 Peer reviewers的相片 Plugin developers的相片
Doesn't that force Moodle to connect using TCP/IP rather that through a socket?
In reply to Howard Miller

Re: Error Koneksi Database setelah Update ke 4.2.2

Leon Stringer發表於
Core developers的相片 Particularly helpful Moodlers的相片

Howard: Possibly. Basically I've been installing Moodle with SELinux enforcing using the same steps for years. Since 4.2 (which coincides with me using CentOS Stream 9) $CFG->dbhost = 'localhost' no longer works. As far as I can tell it's SELinux blocking it but I can't work out the incantations to allow it.

But $CFG->dbhost = '127.0.0.1' does work. As you say this would indicate it's using TCP/IP in which case I'd expect to need setsebool -P httpd_can_network_connect_db 1 (as I do for Moodle with PostgreSQL), but actually it works without that command. It's currently a mystery, maybe I'll work it out at some point.

In reply to Leon Stringer

Re: Error Koneksi Database setelah Update ke 4.2.2

Visvanath Ratnaweera發表於
Particularly helpful Moodlers的相片 Translators的相片
Leon, localhost and 127.0.0.1 are both TCP/IP, localhost just resolves to 127.0.0.1.

$ host localhost
localhost has address 127.0.0.1
If $CFG->dbhost = '127.0.0.1' does work and not $CFG->dbhost = 'localhost' it must be some SELinux magic. I haven't touched SELinux since I left RedHat many, many years ago. So don't know the answer.
In reply to Visvanath Ratnaweera

Re: Error Koneksi Database setelah Update ke 4.2.2

Howard Miller發表於
Core developers的相片 Documentation writers的相片 Particularly helpful Moodlers的相片 Peer reviewers的相片 Plugin developers的相片
It does - but that doesn't prove that adodb treats them they same way. I'm not 100% sure, so I'll leave it there...

For example... see...

評比平均分數:Useful (1)
In reply to Howard Miller

Re: Error Koneksi Database setelah Update ke 4.2.2

Visvanath Ratnaweera發表於
Particularly helpful Moodlers的相片 Translators的相片
Wait! There is this "GRANT ALL PRIVILEGES ON database.* TO 'dbuser'@'localhost' ..." thing. What happens if somebody does it with 'dbuser'@'127.0.0.1'?
In reply to Leon Stringer

Re: Error Koneksi Database setelah Update ke 4.2.2

Ken Task發表於
Particularly helpful Moodlers的相片
CentOS 9 stream is kinda different beast!  Got one of those and am discovering things! :|

@Leon ... what's in your /etc/resolv.conf file?

What does:
nmap -P0 localhost
show?

'SoS', Ken



In reply to Ken Task

Re: Error Koneksi Database setelah Update ke 4.2.2

Ken Task發表於
Particularly helpful Moodlers的相片
@all ..
The other thing ... all computers on internet (workstation or server) should have an /etc/hosts file ... DNS is normally set to do files first (/etc/hosts) then DNS.

So what's in /etc/hosts other than IPv6 for localhost localdomain.

I've had to add a line for the IPv4 IP address of the server so that apache knows about itself.

'SoS', Ken

In reply to Ken Task

Re: Error Koneksi Database setelah Update ke 4.2.2

Leon Stringer發表於
Core developers的相片 Particularly helpful Moodlers的相片

I don't think it's a networking issue as the following connects:

mysql -u moodleuser -p -h localhost moodledb

But $CFG->dbhost = 'localhost' does not (Error: Database connection failed).

My /etc/resolv.conf is nameserver 192.168.124.1.

# nmap -P0 localhost 
Starting Nmap 7.92 ( https://nmap.org ) at 2023-09-18 18:10 BST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000014s latency).
Other addresses for localhost (not scanned): ::1
Not shown: 995 closed tcp ports (reset)
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https
631/tcp  open  ipp
3306/tcp open  mysql
In reply to Leon Stringer

Re: Error Koneksi Database setelah Update ke 4.2.2

Ken Task發表於
Particularly helpful Moodlers的相片
@Leon ... what of /etc/hosts file?
and there is grants for the DB server/user set to 'localhost' as well.
??????
'SoS', Ken


In reply to Leon Stringer

Re: Error Koneksi Database setelah Update ke 4.2.2

Leon Stringer發表於
Core developers的相片 Particularly helpful Moodlers的相片

I've hopefully resolved this. I have CentOS Stream 9 but installed MariaDB's own RPM, because Moodle 4.2 needs ≥ 10.6.7. It looks like the MariaDB executable doesn't seem to get labelled with a suitable type (note the bin_t below):

# ls -lhZ /usr/sbin/mariadbd
-rwxr-xr-x. 1 root root system_u:object_r:bin_t:s0 26M May  5 17:08 /usr/sbin/mariadbd

So I ran the following to change this to mysqld_exec_t:

# semanage fcontext -a -t mysqld_exec_t /usr/sbin/mariadbd
# restorecon -v /usr/sbin/mariadbd

Then restarted the service and could now connect.

I say "hopefully resolved" as I made some changes when I first had a go at troubleshooting this. Next time I set up a VM I'll find out if anything else is needed.