Accessing Moodle from other MACs/PCs

Accessing Moodle from other MACs/PCs

by matt nelson -
Number of replies: 13
In a home intranet set-up, I would like to access Moodle installed on one computer by other computers. I understand the solution is to setup one's own DNS server and point the site to it.

Would anyone guide on what AMPPS, MAMP or Moodle files should be changed to achieve this and how to do it?

thanks!
Average of ratings: -
In reply to matt nelson

Re: Accessing Moodle from other MACs/PCs

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Even the DNS is not necessary. If you can ping it from the client say ping the.ip.of.mc, then try http://the.ip.of.mc in the browser of the same client. The condition is in the server in Moodle's config.php you have set $CFG->wwwroot='http://the.ip.of.mc';.
In reply to matt nelson

Re: Accessing Moodle from other MACs/PCs

by Ken Task -
Picture of Particularly helpful Moodlers
Mr. V is correct and might be the easiest way ... but consider that IP addresses given to workstations in a home network come from DHCP server of home router and could be re-cycled without warning - thus your 'moodle server' has a new IP address. :|

Am sure there are multiple ways of setting up a home network, but
you might want to read/understand the following resource:
https://www.techtarget.com/searchnetworking/tip/Tips-for-setting-up-a-home-network

Assuming you don't want to wreck your upstream access to the internet
for your smart devices ... like your phone and any TCP/IP device you have
in your home right now ... like security cameras/printers etc.

You don't really need a DNS server.

Every computer on the internet has a hosts file and using that hosts file
one can map an IP address with a FQDN (fully qualified domain name).
In your case, I would imagine that IP range is 192.168.0 or 1.0-254.
For you moodle server, static IP address not in the range of DHCP server
IP addresses.

Example of /etc/hosts from a Mac:

cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1    localhost
255.255.255.255    broadcasthost
::1             localhost
192.168.1.245 sandboxmdl.lan sandboxmdl

The last entry above ... note that it does NOT have .com, .net, .org or other
but a top level domain (.lan) which isn't routable and really shouldn't leak to
the upstream internet.

You do need to access your home router to see the range of IP addresses
it's DHCP server is currently doling out. For the computer that will be
your 'moodle server' needs a static TCP/IP setup and wired connection
so it can be accessed and not conflict with any other device you
might use on your home network.

The machine that will be your Moodle server .. is it a laptop or table top?
Best if it will remain at home ... all the time.  And that it be networked
by wire plugged into your home router.  Static private IP address.

For the machine running AMPP or MAMP, or whatever ...
set the networking to a static IP address ... check that it can still get
to the internet.

In AMPP/MAMP moodle the config.php file.  Leave the port for 8080 or 81
whatever it's using ... port 80/443 used by browser for outside surfing.

In the moodle itself ... search and replace.  Moodle has been using
the wwwroot variable in config.php for internal links.  Those have
to be changed to match the static IP/Hostname.

So using my hostile example above:
config.php file would have http://sandboxmdl.lan
And search and replace would use that to replace whatever is in the DB.

Now if one expects to use smart phone/fablet or the moodle app or other device like that to access the home moodle, they might not work using sandboxmdl.lan in a hosts flie.

Got a machine you aren't using?  Slap Ubuntu Linux on it ... set it up with non-conflicting static IP address and you can then run DNS server if you like - along with your Moodle on that Ubuntu server.

Big advantage there ... don't have to use MAMP ... can use git to install the moodle and update/upgrade it easily.

Networking/Server fun and games!

Proof that host file trick works ...
Not in DNS:
dig sandboxmdl.lan
will get ANSWER: 0
;; QUESTION SECTION:
;sandboxmdl.lan.            IN    A

But look what happens with ping:

ping sandboxmdl.lan
PING sandboxmdl.lan (192.168.1.245): 56 data bytes

sandboxmdl.lan is resolved to 192.168.1.245 due to host file.

'SoS', Ken

In reply to Ken Task

Re: Accessing Moodle from other MACs/PCs

by matt nelson -
Thank you for the detailed reply. It is very helpful.
I have lots of student assignments on my local, therefore want to be cautious changing anything, although I have taken a backup.
These are the changes I will make, just wish to confirm.

1. Assign static IP to my moodle MAC computer. (fyi - I currently access moodle with "http://localhost:8888/moodle403/")

2. Change entry in moodle config.php - I have added a copy of my current config.php in the end.
i.e., a. Change 'http://localhost:8888/moodle403'; to $CFG->wwwroot = 'http://[StaticIP]:8888/moodle403'
and b. $CFG->dbhost = 'localhost'; to. $CFG->dbhost = [StaticIP]:8888

I suppose I don't have to make changes to the '$CFG->dataroot'

3. MAMP interface has the ports as 8888 for all. So not changing.

4. Change host file on moodle server to include - [Static IP] moodle403. (see below)
---
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
[Static IP] moodle403
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 AcronisDriveSearchPlugin
-----

Did I miss anything, before I change the router entry of my moodle MAC to Static and check whether I can reach internet.

many thanks!
-----
my config.php file in MAMP <?php // Moodle configuration file

unset($CFG);
global $CFG;
$CFG = new stdClass();

$CFG->dbtype = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost = 'localhost';
$CFG->dbname = 'moodle403';
$CFG->dbuser = 'moodle';
$CFG->dbpass = 'moodle';
$CFG->prefix = 'mdl_';
$CFG->dboptions = array (
'dbpersist' => 0,
'dbport' => '',
'dbsocket' => '1',
'dbcollation' => 'utf8mb4_unicode_ci',
);

$CFG->wwwroot = 'http://localhost:8888/moodle403';
// $CFG->wwwroot = 'http://192.168.0.199:8888/moodle403';
$CFG->dataroot = '/Applications/MAMP/data/moodle403';
$CFG->admin = 'admin';

$CFG->directorypermissions = 0777;

require_once(dirname(__FILE__) . '/lib/setup.php');
In reply to matt nelson

Re: Accessing Moodle from other MACs/PCs

by matt nelson -
based on the changes I made based on the above steps I laid out, moodle errors out - 

Error

error/generalexceptionmessage

MAMP UI still says local host. or anything else I am missing?

this is my hosts file and php.config

##

# Host Database

#

# localhost is used to configure the loopback interface

# when the system is booting.  Do not change this entry.

##

10.0.0.106      moodle403

127.0.0.1       localhost

255.255.255.255 broadcasthost

::1             localhost



?php  // Moodle configuration file


unset($CFG);

global $CFG;

$CFG = new stdClass();


$CFG->dbtype    = 'mysqli';

$CFG->dblibrary = 'native';

$CFG->dbhost    = '10.0.0.106:8888';

$CFG->dbname    = 'moodle403';

$CFG->dbuser    = 'moodle';

$CFG->dbpass    = 'moodle';

$CFG->prefix    = 'mdl_';

$CFG->dboptions = array (

  'dbpersist' => 0,

  'dbport' => '',

  'dbsocket' => '1',

  'dbcollation' => 'utf8mb4_unicode_ci',

);


$CFG->wwwroot   = 'http://10.0.0.106:8888/moodle403';

// $CFG->wwwroot   = 'http://192.168.0.199:8888/moodle403';

$CFG->dataroot  = '/Applications/MAMP/data/moodle403';

$CFG->admin     = 'admin';

$CFG->directorypermissions = 0777;

require_once(dirname(__FILE__) . '/lib/setup.php');





In reply to matt nelson

Re: Accessing Moodle from other MACs/PCs

by Ken Task -
Picture of Particularly helpful Moodlers
In config.php DB host remains localhost.
You are changing how apache/nginx launches and how they will respond.
So MAMP shouldn't be running when making those changes.
Make the changes, then launch keeping an eye on if it shows errors upon launch.

And since this is NOT a normal thing,  please 'thimk!' before changing things.
Remote support, while possible (and am not volunteering either!), is beyond the scope of MAMP and these forums, etc.

Like I said ... FUN AND GAMES! smile
'SoS', Ken

In reply to matt nelson

Re: Accessing Moodle from other MACs/PCs

by Ken Task -
Picture of Particularly helpful Moodlers
Don't have MAMP Pro myself.
So I see it does have a dialog box for 'name' and it says 'localhost' ... looks like it's grayed out ... can you change?

What happens if you change localhost to Moodle403.lan?

Not if that changes the DB host in config.php file ... that's no good.

Like I said ... FUN AND GAMES!

'SoS', Ken

In reply to matt nelson

Re: Accessing Moodle from other MACs/PCs

by Ken Task -
Picture of Particularly helpful Moodlers
You need to Google for Class A network TCP/IP or Class B network TCP/IP or Class C network TCP/IP

Most home networks use a Class C private IP ... normally 192.168.0 or 1 .x with a flat subnet mask (255.255.255.0).
That gives the home network 254 IP addresses.   For most homes that's plenty of IP addresses.

A 10. private IP network is a Class A TCP/IP network - non-routable unless in a Wide Area private network ... like that of Google or Apple or even M$ internal network.
A 10. network depending upon subnet mask could reach 16777214 usable IP addresses.

So do you live in an apartment complex that has a private network and each apartment has free networking?   Depending upon the size of that complex, they could be using a 10.

Anyhoo ... lots to learn, isn't there! smile
Keep tinkering!

'SoS', Ken



In reply to matt nelson

Re: Accessing Moodle from other MACs/PCs

by Ken Task -
Picture of Particularly helpful Moodlers
Howard's suggestion might be the best one yet! smile
Question would be, however, if the home network router is doing DHCP for 192.168.x.x can a computer using static 10. be seen?   A route from 192.168.x.x would have to be made to see the 192.168.x.x network and think that would involve the home network router ... that black box that goes to the internet. smile

'SoS', Ken
In reply to matt nelson

Re: Accessing Moodle from other MACs/PCs

by Ken Task -
Picture of Particularly helpful Moodlers
First ... this one ... "lots of student assignments on my local, therefore want to be cautious changing anything, although I have taken a backup"

I take those are restored courses from some other server .. right?
What we are changing is the networking pieces of all of this.  Not the data in the DB.

DB host/server *stays* localhost ... no need to have it change config.
DataRoot stays the same.

* Host file:
This line:
[Static IP] moodle403

make it the last line in hosts file.
And by default, macs have a .lan domain so in host file:
 
From Terminal on a Mac: ifconfig
And look at the top for a section on what 192. IP address it pulled from DHCP
Then:
dig -x that.ip.address

You will probably see something like: 

;; ANSWER SECTION:
151.1.168.192.in-addr.arpa. 0    IN    PTR    Kens-MBP-2.lan
 
See the .lan above?

So in your host file:
192.168.0.199 moodle403.lan moodle403

Another computer on your network would need it's host file have the same
mapping for http://moodle403.lan access to work.

Apache in MAMP

File: httpd.conf

Default is ServerName localhost:8888
to
ServerName moodle403.local:8888

Don't think there are other places, but MAMP does come with phpmyadmin, adminer, and some other stuff ... so you might need to check those configs as well.

On that mac *never* turn on Web Sharing in the OS.

Fun and Games!   Like I said! smile
'SoS', Ken

In reply to Ken Task

Re: Accessing Moodle from other MACs/PCs

by matt nelson -
Thank you!

I was able to connect with a fixed IP address from other Macs. summarizing the steps.

a. Installed the latest stable version from moodle4mac.
b. Assigned a fixed IP address to the Mac where moodle was installed in the router.
c. Modified and replaced the config.php  entry for $CFG->wwwroot   = 'http://[Fixed IP Address:8888]/moodle403';
d. sudo nano /etc/hosts  and added an entry at the end -   [Fixed IP Address]    Moodle403
e. Went to other computers and repeated  step d
f. logged into moodle with http://[Fixed IP Address:8888]/moodle403/admin/tool/replace/
g. find - http://localhost:8888/moodle403 and replace with http://[Fixed IP Address:8888]/moodle403/
h. once done start using http://[Fixed IP Address:8888]/moodle403/. to login from all your computers.

note: you may need to open firewall to allow  httpd.