Oily Rag 1: CD Part 6

From The Uniform Server Wiki
Jump to navigation Jump to search

MPG UniCenter

MPG UniCenter

Oily Rag: Be prepared to get your hands dirty.

This final part looks at how to produce a self-contained CD using portable Firefox and a PAC file. For this example I chose to mimic UniCenter's web site and Uniform Server's Wiki (my contributions) these are static and dynamic sites respectively. We already have a development system were we can switch between US and CD modes the following explains how to bolt on extra components and modification required to support two virtually hosted sites.

Firefox Portable

Download Firefox Portable 3 from Portable Apps save to a folder of you choice.

Scroll down the page and click link Running From a CD (Firefox Portable Live) to pick up FirefoxPortable.ini alternative copy this text:

Save the file FirefoxPortable.ini to folder *\uni_cd\Uniform Server\udrive\plugins\uscd2\uscd

[FirefoxPortable]
FirefoxDirectory=App\firefox
ProfileDirectory=Data\profile
PluginsDirectory=Data\plugins
SettingsDirectory=Data\settings
FirefoxExecutable=firefox.exe
AdditionalParameters=
LocalHomepage=
DisableSplashScreen=false
DisableIntelligentStart=false
AllowMultipleInstances=false
SkipChromeFix=false
SkipCompregFix=false
WaitForFirefox=false
RunLocally=true

# The above options are explained in the included readme.txt
# This INI file is an example only and is not used unless 
# it is placed as described in the included readme.txt

Top

FirefoxPortable.ini switching

When burning a CD FirefoxPortable.ini needs to be placed in folder *\uni_cd\FirefoxPortable however because it restricts Firefox's functionality delete the file for development work.

The above can be tedious however we already have an automated process hence the reason for locating FirefoxPortable.ini in folder uscd. Using batch files this can be switched in and out as required. Two files need to be modified as follows:

Edit file us_mode.pl scroll down to section 5 and add the last two lines as shown below:

#=5 ============================================================
#Copy bat files to Uniform Server folder

coppy ("./uscd/old_Stop.bat","../../../Stop.bat");
coppy ("./uscd/old_Server_Start.bat","../../../Server_Start.bat");

#Delete Firefox ini file

unlink "../../../../FirefoxPortable/FirefoxPortable.ini"; # delete

Edit file cd_mode.pl scroll down to section 5 and add the last two lines as shown below:

#=5 ============================================================
#Copy bat files to Uniform Server folder

coppy ("./uscd/new_Stop.bat","../../../Stop.bat");
coppy ("./uscd/new_Server_Start.bat","../../../Server_Start.bat"); 

# Copy Firefox ini file to Firefox root folder
coppy ("./uscd/FirefoxPortable.ini","../../../../FirefoxPortable/FirefoxPortable.ini");

With the servers shutdown check cd_mode.bat and us_mode.bat copies and deletes FirefoxPortable.ini respectively.

Top

Index page

One minor irritation, starting our index page from Server_Start.bat will automatically run the default browser. This is because Windows mapps a file extension to an applications and runs the appropriate application automatically. This is easily resolvable, comment out the offending line and set Firefox to open the default page.

There are three versions of Server_Start.bat to change as follows:

  • Server_Start.bat Location: *\uni_cd\Uniform Server
  • new_Server_Start.bat Location: *\uni_cd\Uniform Server\udrive\plugins\uscd2\uscd
  • old_Server_Start.bat Location: *\uni_cd\Uniform Server\udrive\plugins\uscd2\uscd

Locate the following line (68!) in each file and comment it out using a rem

rem ### Start Apanel
rem start \home\admin\www\redirect.html
rem start \www\index.html

Top

Firefox install

Double click on the file downloaded (Firefox_Portable_3.0_en-us.paf.exe) this starts the installation process, when requested select uni_cd as the destination folder. On completion a folder FirefoxPortable is created, inside this folder is FirefoxPortable.exe this runs Firefox.

Top

Initial set-up

  • Run us_mode.bat to make sure its in development mode.
  • Run FirefoxPortable.exe this starts start Firefix
  • When prompted Disable Session Store
  • Close Firefox, when prompted check box "Don't ask next time" click Quit That completes initial set-up of Firefox. (Must be run once to automatically configure Firefox)

Top

Hard coding Firefox

When running in CD mode several user selectable options are not enabled although they may have been set in US mode. Home page and proxy settings require hard coding the default files as follows:

Home Page

Edit file: browserconfig.properties Located in folder: *\uni_cd\FirefoxPortable\App\firefox

Change these two lines:

browser.startup.homepage=http://en-US.start2.mozilla.com/firefox?client=firefox-a&rls=org.mozilla:en-US:official</nowiki>
browser.startup.homepage_reset=http://en-US.start2.mozilla.com/firefox?client=firefox-a&rls=org.mozilla:en-US:official

To:

browser.startup.homepage=http://localhost/
browser.startup.homepage_reset=http://localhost/

Proxy Settings

Edit file all.js located in folder *\uni_cd\FirefoxPortable\App\firefox\greprefs

Search for this line (785)

pref("network.proxy.type",                  0);

Change to:

pref("network.proxy.type",                  2);

Search for this line (811)

pref("network.proxy.autoconfig_url", "");

Change to:

pref("network.proxy.autoconfig_url", "http://localhost/my_sites.pac");

See section PAC for file details.

Top

Auto Run Configuration

Our current configuration for auto-run starts ucUniTray and Servers the file needs modifying to start Firefox.

Edit autorun.inf located in folder *\uni_cd as show bellow:

[Autorun]
open=AutoRunPro.exe
action=AutoRunPro.exe

[AutorunPro]
Run1="Uniform Server\Server_Start.bat"
Run2="Uniform Server\Start_ucUniTray.bat"
Run3="FirefoxPortable\FirefoxPortable.exe"

Note: The order is significant start servers first and browser last.

Mimic sites

Data to mimic sites all we need is the web address and site folder location as follows:

Web address Sites physical location

http://wiki.uniformserver.com/

*\uni_cd\Uniform Server\udrive\www\wiki

http://forum.uniformserver.com/

*\uni_cd\Uniform Server\udrive\www\unicenter

UniCenter is a static site using relative links hence will have no problems. Media Wiki however was installed as a local copy hence its configuration will be incorrect. Using a real web-address Media Wiki will fail I show how to resolve this later.

Top

Index or home page

When our CD is run the index page is displayed first, it contains two links linking our two sites. In reality its a splash page demonstrating the prowess of the web designer.

I have included my index page as an example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>UniCenter</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" > 
</head>
<body>
<h3 align="center"><a href="http://forum.uniformserver.com/" >UniCenter</a></h3>
<h3 align="center"><a href="http://wiki.uniformserver.com/" >Wiki</a></h3>
</body>
</html>

Running that page now the links will take me to their live sites and not local sites on the CD. These links need resolving and pointed to our local server.

Top

PAC

Proxy Auto-Configuration (PAC) file is an ideal solution to resolving the above links. Advantage of a PAC file it's interdependent of the host PC. I have covered the PAC file in detail on this page Virtual Hosting and PAC this CD can be considered a practical example of its use.

To resolve our two address the file looks like:

test2.pac File
function FindProxyForURL(url, host)
{
  if (shExpMatch(url,"*wiki.uniformserver.com/*")) return "PROXY 127.0.0.1";
  if (shExpMatch(url,"*forum.uniformserver.com/*")) return "PROXY 127.0.0.1";
  return "";
} 

Create a new file my_sites.pac copy the above and save it to folder *\uni_cd\Uniform Server\udrive\www

Note: PAC mimics what you would set in an host file during local development.

Top

Adding Virtual Hosts

Add virtual hosts to Apache's host file you can either do this manually or use Admin Virtual Host.

I prefer to do this manually open httpd.conf located in *\uni_cd\Uniform Server\udrive\usr\local\apache2\conf and add the appropriate sections to the end of the file, my Vhosts look like this:

NameVirtualHost *
<VirtualHost *>
 ServerName localhost:80
 DocumentRoot /www
</VirtualHost>

<VirtualHost *>
 ServerName center.uniformserver.com
 DocumentRoot /www/unicenter
</VirtualHost>

<VirtualHost *>
 ServerName wiki.uniformserver.com
 DocumentRoot /www/wiki
</VirtualHost>

With the Vhosts added almost ready to burn a CD. In this example I still need to resolve the Media Wiki issue.

Top

Media Wiki issue

Media Wiki works flawlessly I installed my copy for local use only (see Installing Media Wiki) to folder www/wiki. After mapping this folder using a vhost Media Wiki failed as expected.

I had already copied over the complete MySQL server and database, which works perfectly using http://localhost/wiki. The problem is one of incorrect paths, correctable by installing a fresh copy of Media Wiki.

Being lazy thought there must be an easier way, opened LocalSettings.php located in folder *\uni_cd\Uniform Server\udrive\www\wiki, had a rummage around and found this little gem:

# The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
$wgScriptPath       = "/wiki";

Changed the line to $wgScriptPath = ""; this changes the base path to root, what a time saver.

Test and Burn CD

Before burning test your servers are functional and site are accessible.

  1. Run CD mode using 'cd_mode.bat
  2. Close browsers and servers if running
  3. Double clicking on AutorunPro.EXE
  4. Check sites are accessible from the splash page.
  5. Check dynamic sites function
  6. If you are happy burn a CD:
    * Close down servers.
    * Copy contents of folder uni_cd to your CD.
    * Insert CD and check it works.
  7. Finished

Top

Conclusion

Creating a CD requires integrating a number of components surprisingly Uniform Server has be reduced to one of these. This write-up demonstrates Uniform Servers unique flexibility in this respect; with a few tweaks I turned it into a component.

I have shown my proposed plugin USCD2 is not the whole story you need to integrate other components to make a complete CD. Hence this final page assembles these into a CD development system. Its not a polished product merely a starting point.

Top


Uc small logo.gif Ric