Configuring for the X Window System (Unix only)
There are special problems associated with running the
Mathematica front end under X from within a web server. This is because, typically, the web server is run as a special account, such as
tomcat. This means that when web
Mathematica runs the front end, it is running as this account. For the front end to operate, it must connect to an X server; this could be achieved by logging into the console of the web server machine with this special account running an X server. There are a few problems with this approach: first, you may not want to leave the machine with an open login on the console; secondly, every time the front end does something, a window will appear on the screen, which may be distracting for someone using the machine.
If a different user logs into the console and runs an X server, the front end (which is run by the special web
Mathematica account) will not be able to connect to this server at all under the standard authentication system of X. While it is possible to configure the server to allow these connections, it is not satisfactory because web
Mathematica will be displaying windows on the screen every time it does something with the front end. This topic is discussed in greater length in a later
section.
These problems are solved by running a virtual X server, such as Xvnc, as described in the following
section. Running a virtual server prevents the windows created by the
Mathematica front end from displaying on the screen console of the computer running
Mathematica.
Configuring Xvnc and webMathematica
Xvnc is the Unix VNC server. It provides a virtual X server that can be used by applications, such as the
Mathematica front end, when it is running for web
Mathematica. It also provides a VNC server so that a VNC viewer can connect to view and control any applications running in the server. This can be useful since it can help track down problems in running the front end.
Xvnc comes with a number of Unix distributions. It can also be ovtained from RealVNC,
http://www.realvnc.com/, and TightVNC,
http://www.tightvnc.com.
Install Xvnc
Installation of Xvnc is quite straightforward; you unpack the archive and then copy the relevant files into some local
bin directory, for example,
/usr/local/bin. (Note that some modern Linux distributions already have
Xvnc installed.) Copying of the
Xvnc binaries is shown below.
[server1]$ cp vncviewer vncserver vncpasswd vncconnect Xvnc /usr/local/bin
Launch Xvnc
Launching Xvnc is also quite straightforward; this should be done as the user that will be running web
Mathematica, for example, the user
tomcat. The first time Xvnc is launched, it asks for a password. In the example below, the server is launched as display :1.
[server1]$ su tomcat
[server1]$ vncserver
You will require a password to access your desktops.
Password:
Verify:
New'X' desktop is server1:1
Creating default startup script /home/tomcat/.vnc/xstartup
Starting applications specified in /home/tomcat/.vnc/xstartup
Log file is /home/tomcat/.vnc/server1.wolfram.com:1.log
Test Xvnc
Once it is launched, it is a good idea to test the server by running an application to use it, for example, the
Mathematica front end. This is shown below.
[server1]$ su tomcat
[server1]$ mathematica -display :1
Of course, when this is done, you do not see an actual window on your screen; this is because it is a virtual server. To see the window from the
Mathematica front end, you can run the
vncviewer. This can be done as shown below.
This should show you a screen with the front end window visible. You should be able to type into the front end and see it working. At any time web
Mathematica is running, you can view the desktop with
vncviewer.
Configure webMathematica
The final step is to modify your
MSPConfiguration.xml file to instruct the front end to use this server. The setting of
FrontEndLaunchFlags is described in the
Appendix: Site Configuration. Here is a sample setting that connects to the X server on display
:1.
<FrontEndLaunchFlags>
-display :1 -nogui -geometry 1000x500+10+10
</FrontEndLaunchFlags>
Now your Unix server should be ready to run web
Mathematica.
If you find that the front end does not launch correctly, it may help to add the name of the server in the configuration file. An example is shown below; here,
myserver is the name of the machine on which web
Mathematica and
Xvnc are running.
<FrontEndLaunchFlags>
-display myserver:1 -nogui -geometry 1000x500+10+10
</FrontEndLaunchFlags>
Other X Related Issues
The following section describes a number of further issues that relate to using web
Mathematica in conjunction with an X server. If you have set up an Xvnc server as described
above it should not be necessary to study these.
Connecting to the X Server
When the
Mathematica front end runs, it must connect to an X server. If the X server is being run by a different user than the user running the front end, the X server will reject the connection, as shown below.
[root]# su tomcat
bash$ mathematica
Xlib:connection to ":0.0" refused by server
Xlib:Client is not authorized to connect to Server
xset:unable to open display ":0.0"
Xlib:connection to ":0.0" refused by server
Xlib:Client is not authorized to connect to Server
xset:unable to open display ":0.0"
Xlib:connection to ":0.0" refused by server
Xlib:Client is not authorized to connect to Server
xset:unable to open display ":0.0"
Xlib:connection to ":0.0" refused by server
Xlib:Client is not authorized to connect to Server
XMathematica:can't open display:0.0,exiting...
bash$
One way to avoid this problem is to allow all connections from the local machine.
[root]# xhost +localhost
localhost being added to access control list
[root]# su tomcat
bash$ mathematica
bash$
This is not a good technique since there is a potential for security problems. These are probably limited since it is only connections from the same machine that are allowed. Another problem is that every time the front end is used, a window will be drawn on the screen, which may be annoying to a user of the system.
A more satisfactory alternative is to run a virtual X server, such as
Xvnc.
Xvfb
Xvfb is a virtual frame buffer server described at
http://www.xfree86.org/4.3.0/Xvfb.1.html. It can be used as an alternative to Xvnc, but typically we have found Xvnc to be easier to use and provide more functionality.
For Linux, you can download an RPM archive from
http://www.redhat.com. After installation, you can launch it as follows (you will probably run this as
root).
su tomcat -c "/usr/X11R6/bin/Xvfb :1 -fp
unix/:7100,/usr/local/Wolfram/Mathematica/4.2/SystemFiles/Fonts/Type1,
/usr/local/Wolfram/Mathematica/4.2/SystemFiles/Fonts/BDF -screen 0 800x600x24 " &
This command launches
Xvfb referencing a font server on port 7100 and adding directories that contain the
Mathematica fonts. Note that if you install
Mathematica in some alternative location, you should modify these directories. Under some
Mathematica installations the location of
Mathematica fonts is added to the font server configuration; in this case the
Mathematica fonts do not need to be referenced when
Xvfb is launched.
Xvfb could then be launched as shown here.
su tomcat -c "/usr/X11R6/bin/Xvfb :1 -fp unix/:7100" &
In these examples,
Xvfb expects to use port 7100 on the local machine for the font server. The actual setting may need to be modified if some alternative configuration of font server is used. For example, under Redhat 6 the font server uses a local Unix socket and
Xvfb should be launched as follows.
su tomcat -c "/usr/X11R6/bin/Xvfb :1 -fp
unix/:-1,/usr/local/Wolfram/Mathematica/4.2/SystemFiles/Fonts/Type1,
/usr/local/Wolfram/Mathematica/4.2/SystemFiles/Fonts/BDF -screen 0 800x600x24 " &
If you are not running a font server, you may need to launch
Xvfb with no font server reference. In this case, it may be necessary to copy the
Mathematica fonts into the X distribution layout as described in the section below on manual font installation.
su tomcat -c "/usr/X11R6/bin/Xvfb :1 -screen 0 800x600x24 "&
Once you have launched the virtual frame buffer server, you can test that it is running. You will probably run this as
root.
[root]# su tomcat
bash$ mathematica -display :1
Of course, one problem with confirming that the front end is running correctly with this server is that you cannot see it on the screen! This makes it hard to see a dialog box indicating an error. One way to see what the front end is displaying is to inspect a dump of the server with
xwd and
xwud, which you can do with the following.
xwd -display :1 -root | xwud
This will show what the front end is displaying. For example, if you see a message about not finding the password, you may need to add a
pwfile command-line option.
When you are running the virtual frame buffer X server, you will need to modify your
MSPConfiguration.xml file to instruct the front end to use this server. The setting of
FrontEndLaunchFlags is described in
Appendix: Configuration. Here is a sample setting.
<FrontEndLaunchFlags>
-display :1 -nogui -geometry 1000x500+10+10
</FrontEndLaunchFlags>
On some systems, such as Sun/Solaris, the X server has problems when being launched by the user
tomcat since the permissions to the
/tmp/.X11 directories have been restricted for security reasons. The problem manifests itself with a message that says the system cannot establish any listening sockets. One solution would be to modify the directories so that
tomcat can write to them. For more detail, see
http://www.faqs.org/faqs/Solaris2/FAQ/.
Manual Font Installation
The front end cannot run without access to the
Mathematica fonts. If you notice from the output of the X server with
vncviewer or
xwd that the front end is displaying a dialog box indicating that it cannot find its fonts, you will have to take some further steps to locate the fonts. One solution that is simple but drastic is to copy the
Mathematica fonts into your X distribution.
cd /usr/X11R6/lib/X11/fonts
cp -r 75dpi 75dpi.orig
cd 75dpi
cp /usr/local/Wolfram/Mathematica/5.1/SystemFiles/Fonts/X/*.bdf .
mkfontdir
This is really a poor solution to be avoided if possible. One deficiency is that if you update your copy of
Mathematica, you will have to remember to copy the new fonts. The proper solution is to launch
Xvfb so it either uses a font server or a font path setting, as described above. Remember that this is not a problem when working under Windows.