[RESOLVED] FreePBX cannot connect to Asterisk via AMI

Hi all,
I am quite experienced in UNIX/Linux and “pure” Asterisk, but started to work with FreePBX only recently, so that your help would be appreciated.
I have Asterisk 13.9.1 + FreePBX 12.0.76.3 running on CentOS 6.8. The system was not installed by me, but I need to make it running. It is worth noting that it worked some time ago, so that installation failures could not be the issue.
The blocking issue is that FreePBX permanently fails to connect to Asterisk via AMI; however, its GUI and database are accessible.

Here are the outputs:
In GUI: Asterisk Manager Interface (astman) failure
In console:

[[email protected] ~]# amportal a reload

Please wait...

Error(s) have occured, the following is the retrieve_conf output:
exit: 1
[FATAL] Unable to connect to Asterisk Manager from /var/lib/asterisk/bin/retrieve_conf, aborting

In logs:

[[email protected] ~]# tail -f /var/log/asterisk/full
[2016-07-10 00:56:13] NOTICE[8364] manager.c: 127.0.0.1 failed to authenticate as 'admin'

[[email protected] ~]# tail -f /var/log/asterisk/freepbx.log
[2016-Jul-10 00:56:14] [CRITICAL] (admin/bootstrap.php:139) - Connection attmempt to AMI failed
[2016-Jul-10 00:57:12] [CRITICAL] (admin/bootstrap.php:139) - Connection attmempt to AMI failed

Here is the configuration that I checked and found to be correct (or it contained errors, but now is correct):

[[email protected] ~]# more /etc/asterisk/manager.conf

[general]
enabled = yes
port = 5038
bindaddr = 127.0.0.1
displayconnects=no ;only effects 1.6+

[admin]
secret=Zxcv$321
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
<output truncated>

[[email protected] ~]# more /etc/amportal.conf
#
# --- CATEGORY: Asterisk Manager ---
#

# Asterisk Manager Host
# Default Value: localhost
ASTMANAGERHOST=127.0.0.1

# Asterisk Manager Password
# Default Value: amp111
AMPMGRPASS=Zxcv$321

# Asterisk Manager Port
# Default Value: 5038
ASTMANAGERPORT=5038

# Asterisk Manager Proxy Port
# Default Value:
ASTMANAGERPROXYPORT=

# Asterisk Manager User
# Default Value: admin
AMPMGRUSER=admin

# Asterisk Manager Write Timeout
# Default Value: 5000
ASTMGRWRITETIMEOUT=5000
<output truncated>

AMI itself seems to be operational:

[[email protected] ~]# telnet 127.0.0.1 5038
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Asterisk Call Manager/2.8.0

… and Asterisk is running (processes, ports, signaling and voice is OK):

[[email protected] ~]# netstat -anp | grep aster
tcp        0      0 127.0.0.1:5038              0.0.0.0:*                   LISTEN      2181/asterisk
udp        0      0 10.33.3.42:5060             0.0.0.0:*                               2181/asterisk
udp        0      0 10.33.3.42:4956             0.0.0.0:*                               2181/asterisk
udp        0      0 0.0.0.0:34406               0.0.0.0:*                               2181/asterisk
unix  2      [ ACC ]     STREAM     LISTENING     13515  2181/asterisk       /var/run/asterisk/asterisk.ctl
unix  3      [ ]         STREAM     CONNECTED     84496  2181/asterisk
unix  3      [ ]         STREAM     CONNECTED     84495  2181/asterisk
unix  3      [ ]         STREAM     CONNECTED     84494  2181/asterisk       /var/run/asterisk/asterisk.ctl
unix  3      [ ]         STREAM     CONNECTED     84493  9113/rasterisk

[[email protected] ~]# ps -ef | grep aster
root      2173     1  0 Jul06 ?        00:00:00 /bin/sh /usr/sbin/safe_asterisk
asterisk  2181  2173  1 Jul06 ?        00:56:54 /usr/sbin/asterisk -f -U asterisk -vvvg -c
asterisk  5059  5057  0 00:09 ?        00:00:00 /usr/sbin/httpd
asterisk  5060  5057  0 00:09 ?        00:00:00 /usr/sbin/httpd
asterisk  5061  5057  0 00:09 ?        00:00:00 /usr/sbin/httpd
asterisk  5062  5057  0 00:09 ?        00:00:00 /usr/sbin/httpd
asterisk  5063  5057  0 00:09 ?        00:00:01 /usr/sbin/httpd
asterisk  5064  5057  0 00:09 ?        00:00:00 /usr/sbin/httpd
asterisk  5065  5057  0 00:09 ?        00:00:00 /usr/sbin/httpd
asterisk  5066  5057  0 00:09 ?        00:00:00 /usr/sbin/httpd
asterisk  5721  5057  0 00:18 ?        00:00:00 /usr/sbin/httpd
asterisk  5936  5057  0 00:21 ?        00:00:00 /usr/sbin/httpd
root      9113  9041  0 Jul06 pts/0    00:00:01 rasterisk rvvv
asterisk  9942  9941  0 01:20 ?        00:00:00 /bin/sh -c [ -x /var/www/html/admin/modules/dashboard/scheduler.php ] && /var/www/html/admin/modules/dashboard/scheduler.php
asterisk  9943  9942  0 01:20 ?        00:00:00 php /var/www/html/admin/modules/dashboard/scheduler.php
root      9948  9780  0 01:20 pts/1    00:00:00 grep aster

Full server reboot does not help.

What else should be checked / corrected to make FreePBX connect to Asterisk?
Many thanks in advance.

Resolved. It looks like amportal picks AMI password from database, not from /etc/manager.conf file.

So, the following helped:

[[email protected] rc2.d]# amportal a m
mysql> UPDATE freepbx_settings SET value='correct_password' WHERE keyword='AMPMGRPASS';