
Mohon kiranya bisa diberi solusi...
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.
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.
$ host localhostIf $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.
localhost has address 127.0.0.1
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
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.