New install on Ubuntu 20.04 fails installing Emoncms Core Modules

I’m new to emoncms, so apologies if I’m making rookie errors…I am installing on a VM running Ubuntu 20.04 and have been using the EmonScript out of the box to try and set things up, but every time I run it, I get the same errors at the same point installing the Emoncms Core Modules.

-------------------------------------------------------------
Install Emoncms Core Modules
-------------------------------------------------------------
-- Installing module: dashboard
Cloning into 'dashboard'...
-- Installing module: app
Cloning into 'app'...
-- Installing module: graph
Cloning into 'graph'...
-- Installing module: device
Cloning into 'device'...
-- Installing module: backup
Cloning into 'backup'...
--- UI directory symlink
- Copying default.config.cfg to config.cfg
- Setting config.cfg settings
- creating /etc/php/8.1/mods-available/emoncmsbackup.ini
post_max_size = 3G
upload_max_filesize = 3G
upload_tmp_dir = /var/opt/emoncms/backup/uploads
- phpenmod emoncmsbackup
- creating /var/opt/emoncms/backup directory
- creating /var/opt/emoncms/backup/uploads directory
- restarting apache

-- Installing module: usefulscripts
Cloning into 'usefulscripts'...
-- Installing module: network
Cloning into 'network'...
--- UI directory symlink
-- install default network module config
chown: invalid user: ‘pi:pi’
-- install /etc/sudoers.d/network-sudoers
-- configure /etc/NetworkManager/NetworkManager.conf
/opt/emoncms/modules/network/install.sh: line 34: /etc/NetworkManager/NetworkManager.conf: No such file or directory
/opt/emoncms/modules/network/install.sh: line 48: /etc/NetworkManager/dnsmasq.d/redirect.conf: No such file or directory
-- install /usr/local/bin/wifi-check
-- install wifi-check cron entry
no crontab for root

-- Installing module: sync
Cloning into 'sync'...
--- UI directory symlink
PHP Fatal error:  Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdat>
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(16): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 16

Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php>
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(16): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 16
- installing emoncms_sync.service
Created symlink /etc/systemd/system/multi-user.target.wants/emoncms_sync.service → /lib/systemd/system/emoncms_sync.service.
- Service ActiveState=activating

-- Installing module: postprocess
Cloning into 'postprocess'...
--- UI directory symlink
-- Update Emoncms database
PHP Fatal error:  Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdat>
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(16): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 16

Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'emoncms'@'localhost' (using password: YES) in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php>
Stack trace:
#0 /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php(16): mysqli->__construct()
#1 {main}
  thrown in /opt/openenergymonitor/EmonScripts/common/emoncmsdbupdate.php on line 16

Script output also stored in /root/main.sh.log

The errors start while installing the default network module, not being able to find a user pi:pi then not being able to find the NetworkManager.conf or redirect.conf files.

But the install carries on and gets into more fatal areas where it appears the user I am logged on as ‘emoncms’ their access is denied to mysql while running the emoncmsdbupdate.php on multiple occasions.

After this the install script just ends with no idea if it worked or failed (but presumably failed).

Looking back in the logs I can see the database and user were created in mysql with no issue…

-- Secure MYSQL
-- Create emoncms database
-- Add user:emoncms and assign to database:emoncms

I ran the ./main.sh script using sudo, so it should not have been an authority problem as far as I can tell.

Here is the config file in case I have made the wrong changes…I have marked all the lines I changed below with <<<<<<<<<<

# Edit this config file to suit your local environment if it is not a
# vanilla Raspberry Pi.
#
# Main settings to look atif a non pi environment
# user - Change user to reflect your OS user
# emonSD_pi_env - Set emonSD_pi_env=0 if not a raspberrypi
# install_redis - REDIS is required for feedwriter, service-runner and emoncms_mqtt services
# locations - modify the install and data storage locations

user=emoncms   <<<<<<<<<<
hostname=emoncms   <<<<<<<<<<
emonSD_pi_env=0   <<<<<<<<<<

# Components enabled
apt_get_upgrade_and_clean=true
install_apache=true
install_mysql=true
install_php=true
install_redis=true
# To use mqtt but a different server, just set install_mosquitto_server=false
# manually configure mqtt server settings in settings.ini
install_mosquitto=true
install_mosquitto_server=false   <<<<<<<<<<
install_mosquitto_client=true

install_emoncms_core=true
install_emoncms_modules=true

# RaspberryPi emonSD applicable items - ignored if setting emonSD_pi_env=0
# set to false if not needed

# EmonHub: comment out line above "emoncms_emonpi_modules[config]=stable" if
# you do not wish to have the emoncms emonhub config module installed
install_emonhub=false   <<<<<<<<<<

install_emoncms_emonpi_modules=false   <<<<<<<<<<
install_firmware=false   <<<<<<<<<<
install_emonpilcd=false   <<<<<<<<<<
install_emonsd=false   <<<<<<<<<<
install_docker=true
install_network=true

enable_onewire=true

openenergymonitor_dir=/opt/openenergymonitor
emoncms_dir=/opt/emoncms

emoncms_www=/var/www/emoncms
emoncms_log_location=/var/log/emoncms
emoncms_datadir=/var/opt/emoncms

# usernames and passwords below are for default raspberrypi installation
# these can all be changed to own preference

# MySQL
mysql_user=emoncms   <<<<<<<<<<
mysql_password=**********   <<<<<<<<<<
mysql_database=emoncms   <<<<<<<<<<

# MQTT - change settings.ini after install if server is not local
mqtt_user=emoncms   <<<<<<<<<<
mqtt_password=***********   <<<<<<<<<<

# Default branches
emoncms_core_branch=stable
emonhub_branch=stable
log2ram_branch=rsync_mods

# Core Modules installed in $emoncms_www/Modules
# Configure branches as applicable
declare -A emoncms_modules
emoncms_modules[graph]=stable
emoncms_modules[dashboard]=stable
emoncms_modules[app]=stable
emoncms_modules[device]=stable

# Specific EmonPi / EmonBase Modules installed in $emoncms_www/Modules
# Configure branches as applicable
declare -A emoncms_emonpi_modules
# emoncms_emonpi_modules[config]=stable   <<<<<<<<<<
# emoncms_emonpi_modules[setup]=stable   <<<<<<<<<<

# Modules installed in $emoncms_dir/modules
# Configure branches as applicable
declare -A symlinked_emoncms_modules
# symlinked_emoncms_modules[demandshaper]=stable
symlinked_emoncms_modules[sync]=stable
symlinked_emoncms_modules[backup]=stable
symlinked_emoncms_modules[usefulscripts]=stable
symlinked_emoncms_modules[postprocess]=stable
symlinked_emoncms_modules[network]=master

######################################################
## Only change the repositories if you are a developer.
# git repositories
declare -A git_repo
git_repo[emoncms_core]=https://github.com/emoncms/emoncms.git
# main modules
git_repo[config]=https://github.com/emoncms/config.git
git_repo[graph]=https://github.com/emoncms/graph.git
git_repo[dashboard]=https://github.com/emoncms/dashboard.git
git_repo[app]=https://github.com/emoncms/app.git
git_repo[device]=https://github.com/emoncms/device.git
git_repo[setup]=https://github.com/emoncms/setup.git
# symlinked modules
# git_repo[demandshaper]=https://github.com/emoncms/demandshaper.git
git_repo[sync]=https://github.com/emoncms/sync.git
git_repo[backup]=https://github.com/emoncms/backup.git
git_repo[usefulscripts]=https://github.com/emoncms/usefulscripts.git
git_repo[postprocess]=https://github.com/emoncms/postprocess.git
git_repo[network]=https://github.com/emoncms/network.git
# emonhub
git_repo[emonhub]=https://github.com/openenergymonitor/emonhub.git
# emonpi/rpi specific tools
git_repo[emonpi]=https://github.com/openenergymonitor/emonpi.git
git_repo[log2ram]=https://github.com/openenergymonitor/log2ram.git
git_repo[avrdude-rpi]=https://github.com/openenergymonitor/avrdude-rpi.git
git_repo[RFM2Pi]=https://github.com/openenergymonitor/RFM2Pi
git_repo[emonPiLCD]=https://github.com/openenergymonitor/emonPiLCD

Appreciate any guidance you can give.

On the off chance, I went back and looked at the generated settings.ini file and found it had used all the pre installation default values for the database etc. and not the values I had modified in the config file.

I updated the settings.ini file, then re-ran the script and it worked this time without problem.

Now I get a login screen.

Maybe worth a look at the logic that generates the settings.ini file so others don’t hit the same issue.