TurnKey Linux Virtual Appliance Library

Add new application to an appliance

Hi,

I installed the moodle appliance, and now I want to serve my own web application from the same installation. Now, when I examine it, I see that you arrange it so that different applications will be served from different ports. E.g. port 80 serves moodle, port 12123 or st. serves phpmyadmin, and port 12121 or st. serves the webmin. So the port decides the application to serve.

What I want is to switch to a url based (same port for all) configuration: http:/somebaseurl/moodle should serve moodle, http:/somebaseurl/phpmyadmin should serve phpmyadmin, http:/somebaseurl/myapp should serve my custom app. How can I do this?

I know this question is mostly about Apache configuration, but I think other users can benefit from the answer. I don't know how to configure Apache, I usually edit the conf file that comes with the installation.

Thanks In advance.

Ps: In your appliance you use /usr/share/mooodle, /usr/share/phpmyadmin ... for local files, and under the /etc/apache2/available-sites, you make these directories the documentroot for the corresponding application. The way I usually do this is to just put moodle, phpmyadmin, and myapp folders under the same documentroot, and there you go... Is this not secure?

Jeremy's picture

I'm not 100% sure

I'm not 100% sure what the motivation of the TKL devs was for using different ports for the different functions but my first assumption would be to make securing the server much easier. ATM all you need to do to pretty much lock a TKL server down is to block all remote access to any port other than 80 (and 443 for https). Even if you want to retain remote access you can relatively easily allow only certain IP addresses.

I am also unsure of your motivations for wanting to change the defaults. What is your reasoning and/or usage scenario requiring this? It should be pretty easy to set it up for Moodle, phpMyAdmin and your new app but Webmin and Shell-in-a-box (SIAB) will require a little more tweaking (as by default they run with their own servers - not Apache, I think they may use Lighttpd?). As you may or may not be aware, only one process can listen on any given port, so you will need to get them running under Apache. Here is a webpage explaining how to get Webmin running under Apache. Not sure about SIAB.

As you suspect, for Moodle, phpMyAdmin and 'myapp' you will need to adjust apache configs. I am no expert on this so I won't go into details but basically all the files you'll need to play with are in /etc/apache2. The ports.conf file controls the ports apache listens on and the folder /etc/apache2/sites-enabled controls the available sites. Common practice (and the desireable way to do things) is to create the actual config files in /etc/apache2/sites-available and create symlinks in sites-available. These symlinks are created using the a2ensite tool; eg a2ensite myapp would create a symlink to the myapp config file in /etc/apache2/sites-available.

I suggest that you have a good read of this and backup any config files prior to playing with your appliance (eg cp conf.file conf.file.backup). You can use other site-available files as templates for your new ones by copying them, similar to creating backup files. Also remember that you need to restart apache for your config changes to be applied (/etc/init.d/apache2 restart).

Hope thats of some help. Post back and let us know how you go.

restating the question

Well,

I asked in a wrong way. Your are right, it is better if phpmyadmin, webmin, and SIAB stay in their own ports, safe and secure.

I just want to add another app, say "myapp", that will run in port 80. But , if I understand right, the way the conf files is setup, port 80 is reserved just for moodle. 

This is the contents of /etc/apache/sites-available/moodle:

--------------------------------------------

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
    UseCanonicalName Off
    ServerAdmin  webmaster@localhost
    DocumentRoot /usr/share/moodle/
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/cert.pem
    ServerAdmin  webmaster@localhost
    DocumentRoot /usr/share/moodle/
</VirtualHost>

<Directory /usr/share/moodle/>
    Options +FollowSymLinks
    AllowOverride All
    order allow,deny
    allow from all
</Directory>
-----------------------------------------------

Assuming I put myapp to /usr/share/myapp, how could I arrange it so that it will be served from http://....:80/myapp, while moodle is served from http://....:80/moodle

Thanks again.


Jeremy's picture

Currently it is setup for just moodle...

But that can easily be changed so you can use Apache for other content (easy being a relative word!).

Now assuming you want Moodle at http://<appliance-ip>/moodle and a new web app to http://<appliance-ip>/new-webapp look below. If you do it this way, you can also put a landing page at http://<appliance-ip>/index.htm.

As you probably know, there are often many different ways to do the same or similar thing, this is not a definitive how-to, its just how I'd do it. My rationale is that doing it this way, allows for you to add additional LAMP content easily (just add it to /var/www/). Now I warn you that I am a bit of a newb when it come to Apache config, so I'm hoping this works :)

Firstly backup the moodle sites-available file (in case it doesn't work) and use it to create a new template file:

cp /etc/apache/sites-available/moodle /etc/apache/sites-available/moodle.backup
cp /etc/apache/sites-available/moodle /etc/apache/sites-available/new-default

Edit your new file:

nano /etc/apache/sites-available/new-default

and make it look like this (changes in bold):

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
    UseCanonicalName Off
    ServerAdmin  webmaster@localhost
    DocumentRoot /var/www/
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/cert.pem
    ServerAdmin  webmaster@localhost
    DocumentRoot /var/www/
</VirtualHost>

<Directory /var/www/>
    Options +FollowSymLinks
    AllowOverride All
    order allow,deny
    allow from all
</Directory>

<Ctrl><x> to exit and save.

Now edit /etc/apache/sites-available/moodle

nano /etc/apache/sites-available/moodle

Delete everything in there and replace it with this:

Alias /moodle /usr/share/moodle/
<Directory /usr/share/moodle/>
    Options +FollowSymLinks
    AllowOverride All
    order allow,deny
    allow from all
 </Directory>

<Ctrl><x> to exit and save again.

Now enable your new-default site and restart Apache. Fingers crossed it all works!

a2ensite new-default
/etc/init.d/apache2 restart

Now any new content can go straight to /var/www/ as this is your default document root (like a default LAMP install) eg, your new web app can go at /var/www/new-webapp and will be availabel at http://<appliance-ip>/new-webapp. Moodle obviously still comes from its default doc root.

Let me know how you go. Also anyone else with more Apache experience who would like to crtique my suggestions please feel free to chip in!

[edit] To make this work also requires editing the Moodle config (see comment & link below).

first page comes but..

The first page of the moodle comes at .../moodle, but page layout isbad, I think CSS were not found. Also the login page is still directed to the old url ...


Jeremy's picture

Hmmm that's a pain

Well perhaps revert it to what it was and just add an alias for /new-webapp. It won't quite do quite what you want because Moodle with still be at you http doc root rather than /moodle but it should solve the other issues.

If you're determined to set it up how you first said then perhaps try having a good read of the link I posted before. I don't know enough about Apache to help you more. I think we're missing some arguments in what I posted above.

Another option (if you don't want to read the Apache docs and learn about that) is to take a completely different tack and start again from scratch, but with TKL LAMP appliance this time and install Moodle on top of that. That may make it easier to set up exactly how you want? A quick google turned up this document which looks like it'd be pretty handy if you go that direction. Just keep in mind that the current stable TKL appliances are based on Ubuntu Hardy/8.04 server.

If you do get the Apache setting worked out your current setup, please post back, so the answer is here. For now I will strike out the above, so someone doesn't come across it and blindly follow it expecting it to work (now that you've confirmed it doesn't). Sorr yI don't have the exact answer you want/need.

Thanks a lot.

Thanks a lot.

I will post here if I find a solution.


It seems to be working now

Your advice did work, after I ask to a forum in moodle.org and did moodle specific changes described in this page referred by them:

http://docs.moodle.org/en/Moodle_migration

Thx. again...


Jeremy's picture

Excellent!

I didn't consider changes that needed to be made to Moodle config. Good work on putting the last pieces of the puzzle together to set it up how you wanted. We both learn something :)

I'll remove the strike-through from my earlier post. Thanks for posting back.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)