How to access Moodle from any computer in a small LAN or Intranet

How to access Moodle from any computer in a small LAN or Intranet

by David Delgado -
Number of replies: 21
It is easy, but I post this because I know there are some people having problems to get this. The tipical situation is any computer running Moodle in Windows (tipically a Windows XP) and many other computers trying to access Moodle in it.

They are having problems to give access to their Moodle in their LAN just because they use the default "localhost" or "127.0.0.1" as the IP for Moodle and the Apache web server.

The IP is the identifier for any computer in the network. "localhost" or "127.0.0.1" is a default IP for any computer (it means something like "me"). The real IP is the 4 numbers identifying the computer in the network (it means something like your social security card number). It could be 192.168.0.1, for example.

To make Moodle work in an Intranet or small LAN (Local Area Network), such as a home network of office network, is a 3 step process:

1) Get the IP of the computer running Moodle inside the LAN. In Windows, you can get this quickly: "Start Menu" / Run... / command (hit enter and a black command prompt is opened), and then in the command prompt type ipconfig (hit enter). The IP is the 4 numbers next to "IP address". For example: 192.168.0.1

2) At the directory where you installed Moodle, edit config.php and set your

$CFG->wwwroot = 'http://IP/moodle';

where IP is the IP you got in step 1. Save it and now Moodle will know his real IP.

3) At the directory where your Apache web server is installed, there should be a subdirectory called conf. Edit your httpd.conf file there and set your

ServerName IP

where IP is the IP you got in step 1. Save it and now your Apache web server will know his real IP.

After following this 3 step process, any computer in your network should be able to use your Moodle server. Pretty easy! smile

Just a little thing: be sure that the computer running Moodle has an static IP address (one that does not change). Many admins use dynamic IP addresses by default (they change everytime you login), using a process called called DHCP. If you cannot get an static IP from your network admin, you will have to repeat the 3 steps any time you login in your computer.

Perhaps another question for the FAQ, Martin? smile
Average of ratings: Useful (3)
In reply to David Delgado

Re: How to access Moodle from any computer in a small LAN or Intranet

by David Delgado -
Just one more thing: of course, to access Moodle from any computer in the network, you just have to put this internet adress in your browser:

http://IP/moodle

where IP is the IP got in step 1. For example:

http://192.168.0.1/moodle
In reply to David Delgado

Re: How to access Moodle from any computer in a small LAN or Intranet

by Janne Mikkonen -

You can also use hosts -files and there's no need to remember the IP's

In WinXP host -file is located:
C:\WINDOWS\system32\drivers\etc

And Linux:
/etc

Basic syntax is:

IP number Name:
192.168.0.1  mymoodle.jeps

- Janne -

Average of ratings: Useful (1)
In reply to Janne Mikkonen

Re: How to access Moodle from any computer in a small LAN or Intranet

by David Delgado -
Good point, the problem is that you should put the host file in any computer in the network, wich could be a problem to maintain. But you can do it, if you want to make it easier for everyone to remember the name of your Moodle server.
In reply to David Delgado

Re: How to access Moodle from any computer in a small LAN or Intranet

by reg burns -

Can't you just use computernames to bring up a webpage?  I know you can when browsing shares in a workgroup.  Browse to something like http://computername/moodle/ and it should work right, even without the hosts file.  Doesn't it broadcast to do this?  That's not a big deal on a small or isolated network (we had 40 PC's broadcasting away quite successfully in the first place I worked, although with switches).

To get your computername go to the command prompt and type "echo %computername%" without the quotes and it will return your computername.

Also, if you want to use an lmhosts file then you can maintain the file centrally.  I don't think you can do that with a hosts file but lmhosts you can.  Here's how (full instructions are in C:\WINDOWS\system32\drivers\etc\lmhosts.sam).

Inlcude this in the clients lmhosts file and make the proper substitutions for the IP address and servernames (make sure tabs are right between columns) located here C:\WINDOWS\system32\drivers\etc\lmhosts

192.168.0.1     Servername     #PRE    #needed for the include statement
#INCLUDE //servername//share/lmhosts

*Note in the above line you'll need to make the // forwards slashes into \ backslashes.  I couldn't figure out how to remove a link even through editing the html source so I couldn't get the UNC path to display right.

You *might* also need to add the share to the following registry key /machine/system/currentcontrolset/services/lanmanserver/parameters/nullsessionshares

Then on your server share out a folder called "share" in the example (any name will do as long as you substitute in the right places) and put a file called lmhosts there containing this.

192.168.0.1     Webservername  #PRE   #needed to resolve webserver address

In reply to reg burns

Re: How to access Moodle from any computer in a small LAN or Intranet

by Williams Castillo -
Personally, I use the conputer names.... and it works neat and simple!

However, I'm not a netadmin so I would like to hear reasons why I should avoid this.

Thanks!
Will
In reply to Williams Castillo

Re: How to access Moodle from any computer in a small LAN or Intranet

by Jacob Romeyn -

I have a fast Internet connection to the school and host the Moodle server in the computer lab.

I have installed a DNS on the same server.

I point the school URL first to the local DNS  and  secondary  to an outside DNS server.

I than point  the school URL  to the local IP address 192.168.1.70  in Apache. .

In the router I forwarded the local address 192.168.1.70 to an external IP number.

From inside the school the server does not need an Internet access. If the Internet is down or slow, it does not effect Moodle.

This method is less confusion for the students. The URL is always the same, in or outside of the school.

In reply to Jacob Romeyn

Re: How to access Moodle from any computer in a small LAN or Intranet

by luciano biondo -
I need to use moodle both from inside the local network and from outside. I put, on my server, moodle in the root directory of mydomain.com. In DNS server I have set:
www.mydomain.com pointing to my internet fixed IP number
and
dev.mydomain.com pointing to 192.168.0.70 (my server IP number in the local network)
I have configured Apache with name virtual host.
Now I reach the same moodle, from LAN writing in the browser http://dev.mydomain.com and from outside writing http://www.mydomain.com. That easy to remember.
(of course everything works only if the local network is always connect to internet with a router, because the DNS server is not in the local network; practically a flat connection is needed)

This kind of configuration works well with many html and php domains, but not with moodle, because of the line:
$CFG->wwwroot = 'http://xxx';
in config.php
if write dev.mydomain.com instead of xxx, moodle works in the LAN but not from outside; if I write mydomain.com instead of xxx, moodle works from outside but not from the lan.

I'm interested in Jacob Romeyn's solution, but I have not understood it. Could, please, Jacob, explain it better (for dummies, if possible)? Thanks

Luciano
In reply to luciano biondo

Re: How to access Moodle from any computer in a small LAN or Intranet

by Jacob Romeyn -

I think the answer is in your statement "because the DNS server is not in the local network;"

I my case I have an DNS running on the same server as Moodle. With my server thekingsschool.net, set to address 192.168.1.70.

And because this is the first DNS choice from within the campus,  it will work at the school, even if the Internet is not functioning.

So the Name for :$CFG->wwwroot = 'http://xxx';   is always : http://thekingsschool.net

In reply to Jacob Romeyn

Re: How to access Moodle from any computer in a small LAN or Intranet

by Janne Mikkonen -

A little php lession:

if you set $CFG->wwwroot  like this:

$CFG->wwwroot = "http://". $_SERVER['HTTP_HOST'];

the hostname is set to whatever alias name is written to your browser location, eg:

moodle.mydomain.com has aliases:

dev.mydomain.com
www.mydomain.com

So you can use all of these addressess to get the same content, on the presumption that you have necessary dns records or host records.

Average of ratings: Useful (1)
In reply to Janne Mikkonen

Re: How to access Moodle from any computer in a small LAN or Intranet

by Alvaro Corugedo -
In BIND 9 there is a new feature called 'view'. The use of view allows the DNS Server to answer queries depending on the IP from the querier. That means that if you ask from a LAN computer ... you receive a Private (LAN) IP, but if the DNS is asked from outside the LAN then it receives a Public IP.

Let me know if it's useful for you
Salu2
In reply to David Delgado

Re: How to access Moodle from any computer in a small LAN or Intranet

by vonsh man -

thank you david you help me so much with these post

now i can access to my moodle intrnal from:

192.168.0.202/moodle

i want hide this ip from user to open dirctely as:

mymoodle

In reply to vonsh man

Re: How to access Moodle from any computer in a small LAN or Intranet

by Sam Mudle -

If you are using Windows XP/Vista/7 computer just type the computer's name and the NetBios feature of Windows will resolve it on your local network.

So say your computer's name is PC2341 then go to another computer and type
 \\PC2341\moodle

In reply to David Delgado

Re: How to access Moodle from any computer in a small LAN or Intranet

by John Gone -
I have a Moodle on a LAN (EasyPHP 1.7) and could access my Moodle homepage but I couldn't enter the site (connection refused) and then I found this page and this good info and fixed the problem. smile

Thanks for taking the time to make that post David. I used that information to access my Moodle on my LAN. Also thanks to all others who posted here with the tips and additional info.
In reply to John Gone

How to access Moodle from any computer in a small LAN or Intranet

by Somit Basak -

Hi friends,

Greetings!

Please help me out in addressing concerns regarding technical difficulties that I am facing in accessing Moodle from other computers in the Intranet of my company through LAN.

I have hosted the site on my personal computer(work-station) for testing and not on the server of the company.
I am using windows XP as the OS.


The problem is:

1) Even though access to Moodle site is possible through other computers, the objects are not appearing properly placed and not appearing also in the correct format.

2) Also, login to the site is not possible through other computers.

Please help me in step-by-step guideline as to how to rectify the problem.

Thanks a lot for your help in advance.

Am available in: somit.basak@gmail.com
Somit

In reply to Somit Basak

જઃ How to access Moodle from any computer in a small LAN or Intranet

by Dr. Amitkumar Mali -
Hi Somit

I had the same problem a year ago. I got some help from forums and solved the problem.

I think you just read the post http://moodle.org/mod/forum/discuss.php?d=2389 and from it three steps suggested by devid should be followed first. I infact I followed only first two steps )

I wanted to use moodle in my computer lab. I installed it on a pc. I found it's IP address. Then I replaced 127.0.0.1 with it in config.php $CFG->wwwroot = 'http://127.0.0.1'; ( you can find config.php in moodle directory) I modified it with notepad.

Then I can access moodle from other computers typing http://IP ( IP is the ip address which replaced 127.0.0.1).

I created my course on my laptop (i.e. at the time of course creation config.php has $CFG->wwwroot = 'http://127.0.0.1'; ). I copied created course backup and restore it in my Lab on a computer having IP address 192.0.0.50. After modifying config.php I could access moodle, login to the courses but Images and other media objects could not visible/accessible. If you are facing the same problem, the solution is easy. you just login as admin. the go to http://ipaddedinfonfig.php/admin/replace.php . I attach its screenshot.

In the replace.php page, type 127.0.0.1 in the textbox next to "Search whole database for" and type your IP which you entered instead of 127.0.0.1 in config.php ( in my example 192.168.0.50 ) in the textbox next to "Replace with this string:" and then hit the "yes do it now" button. It will replace 127.0.0.1 from your complete database with your new IP . Then you can see all the images and other inserted objects.

This post becomes too long but, by followng these steps I could solve my problem.
Hope this helps u.
Cheers
Attachment replace_php.jpg
In reply to Dr. Amitkumar Mali

Re: જઃ How to access Moodle from any computer in a small LAN or Intranet

by Eddie Caudill -

One important step missing from the first line is to add the following to the httpd.conf

Listen 127.0.0.1:80

Replace the "127.0.0.1:80" with your IP address and http port.

The step about replacing the 127.0.0.1 with my server's IP address helped to fix all of the broken link problems I was having.

Thank you.

In reply to David Delgado

જઃ How to access Moodle from any computer in a small LAN or Intranet

by Dr. Amitkumar Mali -
Hi David,
Thanks for your post. I am a teacher and know very less about networking and programming.
How important is the third step? I managed to run moodle in intranet by following firest two steps (i.e. 1) find ip, and 2) replace 127.0.0.1 with it in confrig.php)
Cheers
In reply to David Delgado

Re: How to access Moodle from any computer in a small LAN or Intranet

by Kavitha Sreelesh -

im facing the same problem..i cant access moodle form another system.it says tht the page cannot be displayed.

In reply to Kavitha Sreelesh

Re: How to access Moodle from any computer in a small LAN or Intranet

by Musie Meressa -

Even if I configure my httpd.config correctly 
        Listen 192.168.14.22:80

         ServerName 192.168.14.22:80 and 

and my config. php looks like this

<?php  // Moodle configuration file


unset($CFG);

global $CFG;

$CFG = new stdClass();


$CFG->dbtype    = 'mysqli';

$CFG->dblibrary = 'native';

$CFG->dbhost    = 'localhost';

$CFG->dbname    = 'moodle';

$CFG->dbuser    = 'root';

$CFG->dbpass    = 'toor';

$CFG->prefix    = 'mdl_';

$CFG->dboptions = array (

  'dbpersist' => 0,

  'dbport' => '',

  'dbsocket' => '',

);


$CFG->wwwroot   = 'http://192.168.14.22/moodle';

$CFG->dataroot  = 'C:\\moodle\\server\\moodledata';

$CFG->admin     = 'admin';


$CFG->directorypermissions = 0777;


$CFG->passwordsaltmain = 't/#3vbhG0Z:_]bmM;]+Te4PC6Q.6c';


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


// There is no php closing tag in this file,

// it is intentional because it prevents trailing whitespace problems!


But when type http://192.168.14.22/moodle I get the error, Please help 

Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.      

In reply to Musie Meressa

Re: How to access Moodle from any computer in a small LAN or Intranet

by Ulzii-Erdene Bulgan -

Dear Musie Meressa,


Have u solved below issue?

Would appreciate if u can provide your solution on this.


Best regards,