How to install moodle with database on a different server

How to install moodle with database on a different server

by Daniel Lombardo -
Number of replies: 10

Hi

I am installing Moodle across 2 Centos virtual machines. 1 for application + data, and the other for MySQL

  • mysql55
  • centos 6.4
  • php5.3.3
  • moodle25

Application server IP: 192.168.6.162

Database server IP: 192.168.6.163

I am unable to get past the Database connection:

Using these details for install.php:

Database host: 192.168.6.163
Database name: moodle
Database user: unique-user
Database password: *********
Tables prefix: default
Unix socket: ON

Error: Database connection failed

It is possible that the database is overloaded or otherwise not running properly.

The site administrator should also check that the database details have been correctly specified in config.php

Warning: mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on '192.168.6.163' (13) in /var/www/html/moodle/lib/dml/mysqli_native_moodle_database.php on line 76

Oh and here are the MySQL user settings for the unique user:

mysql> CREATE DATABASE moodle;
Query OK, 1 row affected (0.00 sec)

mysql> ALTER DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO unique-user@192.168.6.162 IDENTIFIED BY '********';
Query OK, 0 rows affected (0.00 sec)

Please note that I have also tried using the root user and letting install.php create the database automatically - without success - same error in fact. Also tried with Unix socket off.

Additionally, I have tried creating the config.php with nano manually in the terminal. Of course including all the appropriate details for the connection - alas same error message (bar the last part). Tried search the web and forums for this error message - nothing has solved my crisis.

Last words

Advice overcoming this current error and going onward with the installation would be greatly helpful for me. I have limited knowledge of Linux servers but I am enjoying the command line extremely. I have found this page in the docs to be very helpful: http://docs.moodle.org/25/en/CentOS_Linux_installation although I suggest updating the repos by including Webtatic (http://www.webtatic.com/packages/mysql55/) instead of manually downloading the mysql upgrades. Then install using yum - it's sure to be easier to update later, too.

Thanks so much.

D

Average of ratings: -
In reply to Daniel Lombardo

Re: How to install moodle with database on a different server

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Daniel,
unfortunately the Docs are not really up to date: they do not mention that CentOS 6 has SELinux enabled by default and under that default context Apache is not able to open connections regardless the firewall being set off.

Being your IP addresses private, you could disable both the firewall and SELinux - details e.g. in http://www.howtoforge.com/perfect-server-centos-6.4-x86_64-apache2-dovecot-ispconfig-3-p3 - or you can implement changes* for SELinux and open the TCP/3306 port in the MySQL Server firewall**.

HTH,
Matteo

* Allow Apache connections towards DB and external SMTP as well as making Moodle HTTP calls work (read more e.g. at http://wiki.centos.org/TipsAndTricks/SelinuxBooleans):
# setsebool -P httpd_can_network_connect on
# setsebool -P httpd_can_network_connect_db on

** Allow MySQL port to be open to the LAN by appending one line to the iptables configuration:

# vi /etc/sysconfig/iptables
...
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
# service iptables restart

Average of ratings: Useful (1)
In reply to Matteo Scaramuccia

Re: How to install moodle with database on a different server

by Daniel Lombardo -

Thank you Matteo

I'm going for your starred steps because I would prefer not to bother the domain administrator and it seems more specific to my issue.

However, I don't quite know what to do with this (there is no 'iptables' config file exactly):

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

I appended it to 'iptables-config' - when I restarted iptables I got this error:

/etc/sysconfig/iptables-config: line 57: -A: command not found

 

In reply to Matteo Scaramuccia

Re: How to install moodle with database on a different server

by Daniel Lombardo -

Ok, well I put that line into iptables.old where it seems like it should live.

Didn't get me past the Database connection problem though.

I also disabled SELinux and Centos Firewall.

In reply to Daniel Lombardo

Re: How to install moodle with database on a different server

by Ken Task -
Picture of Particularly helpful Moodlers

While I too like command line, did find that while learning it was nice to have an aid in learning and have yet another way to accomplish something (if I were to be 'lazy' on some days).  Thus the following suggestion:

install webmin on both servers.  http://www.webmin.com/

Download and install the .tar.gz. using wget on the server from a terminal session.

One reason for doing so ... once webmin is installed and one uses Webmin Servers Index from say the front end box (ie, the one with apache on it), one can update both with one click of a button.

Plus, it gives a place to start with somethings like iptables.

IMHO, in this day an age, probably never a good idea to completely disable firewalls ... even when the servers are internal to a private LAN/WAN.

Webmin can be restricted to accepting connections from only certain IP addresses and/or users.

And Webmin checks for it's own updates ... no repo setup needed to keep it up to date ... just have to login from time to time and click a button.

'spirit of sharing', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: How to install moodle with database on a different server

by Daniel Lombardo -

Thanks, Ken. Webmin is nice. I see that it schedules database backups. Great tip and worth exploring.

It also sets up NFS, which reminds me, that is one of my missions; to have the moodledata on a 3rd server. I already have one prepared with CentOS. These instructions are helping me understand how to do the mount: http://www.centos.org/docs/2/rhl-rg-en-7.2/s1-nfs-server-config.html

Using NFS seems the right thing to do, but I've heard of Samba for this purpose as well.

 

In reply to Daniel Lombardo

Re: How to install moodle with database on a different server

by Ken Task -
Picture of Particularly helpful Moodlers

Welcome!

What sort of connectivity are you planning between your app server and what will be the moodledata server via NFS?   Something extremely fast?

A mount point on the Moodle code/app server to the moodledata server via NFS had better *never* fail.

'spirit of sharing', Ken

In reply to Ken Task

Re: How to install moodle with database on a different server

by Daniel Lombardo -

Hi Ken

Thanks for taking an interest. It would be on yet another VM server with pretty much the same configuration as the others. Are there certain things that could cause that to fail?

We may cluster the application server later if it's found to be a bottleneck, that's why I am flirting with the NFS. I was hoping that even if I don't cluster immediately, having /moodledata/ on another server will win something back in performance and provide good log data to analyse if more optimization is found to be needed. Seeing as I already have that third VM there to play with.

Is there an alternative way to mount or access /moodledata/ that is speedy and less risky than NFS? One that is compatible with a clustered application server.

In reply to Daniel Lombardo

Re: How to install moodle with database on a different server

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Daniel,
you can make a quick test by disabling the firewalls to be sure that there will be no firewall issue on MySQL server side:

  1. Disable SELinux on both servers
  2. Restart the two servers to be sure that SELinux will be disabled. To check that SELinux is really disabled: # sestatus
  3. Disable Firewall on both server: # service iptables stop
  4. Test the connection

As said in my first post, disabling firewalls is not the right choice but for troubleshooting purposes, being on a private - i.e. somewhat trust-able - network, it could be an option to do it just for the time required for the test.

If the test will be unsuccessful I strongly suggest to ask for the help of the IT Administrators to avoid potential issues with the IT Security Team.

Matteo

Average of ratings: Useful (1)
In reply to Matteo Scaramuccia

Re: How to install moodle with database on a different server

by Daniel Lombardo -

Thank you, Matteo. Your troubleshooting steps provided me with some success - broadening my understanding and furthering my efforts. I aim to report here on the configuration that finally works for me and is considered secure by the network administrator.

The time you took to offer support in this thread is greatly appreciated.