How do I install and configure web Mathematica on Linux?
Read this article in: Deutsch, Español, Français, 日本語, 한국어, Português, Русский, 中文
web Mathematica requires that Java, a Servlet container and Mathematica are installed on the system. Certain functionality in Mathematica, and hence web Mathematica, requires the use of Mathematica's front end. The front end, in turn, requires an X Window System on Linux. The steps to install web Mathematica are as follows:
- Setting Up Java
- Setting Up Tomcat
- Setting Up Mathematica
- Making Licensing Files Accessible to web Mathematica
- Installing and Setting Up web Mathematica
- Configuring Xvnc for Minimal or Server Editions of Linux
Setting Up Java
Java is required not only for web Mathematica but also for any Java Servlet container. You can access Oracle’s Java from http://www.oracle.com/us/downloads/index.html.
In several Linux distributions, Java packages can also be installed via either the command line or through their software centers:
sudo yum install java-1.8.0-openjdk sudo yum install java-1.8.0-openjdk-devel
sudo apt install openjdk-8-jre sudo apt install openjdk-8-jdk
To verify the successful installation, on the command line, execute:
Setting Up Tomcat
web Mathematica is designed to operate from within a Java Servlet container. Among various available Servlet containers, we provide limited guidance with Apache Tomcat only.
- Go to http://tomcat.apache.org/download-80.cgi.
- Download the installer in the format of tar.gz.
- Change to the location where you wish to install the server. For example, if you wanted to install at
- Unpack the installer in the current location:
tar -xvzf apache-tomcat-<version>.tar.gz
- To start the Tomcat server, in the Tomcat installation directory, execute:
- Open a web browser and submit “localhost:8080”. If Tomcat has been set up correctly, a page similar to the following one appears:
- To shut down the Tomcat server for now, in the same directory, execute:
Common possible issues:
- The computer’s firewall is blocking requests to Tomcat. Tomcat, by default, runs on port 8080. Ensure that the port is open to accept tcp packets on the system running the Tomcat server.
- If you downloaded Java from Oracle’s website, the Tomcat server may not be able to find the Java installation. In such a case, set the system variable JAVA_HOME to Java’s installation directory, e.g. by executing the following on a bash command line or by adding these lines to .bashrc, if your Java was installed in
JAVA_HOME=/usr/local/jdk1.8.0 export JAVA_HOME
Creating a Tomcat Account (Recommended)
It is recommended that you set up a dedicated user account to run the Tomcat server, typically called “tomcat”. This account needs the permissions to run the Tomcat server.
- To create the account, execute in the terminal:
sudo useradd tomcat sudo passwd tomcat
- Change the ownership and group of the Tomcat installation directory to the “tomcat” user by executing these commands from the parent directory of where you installed the apache-tomcat server:
sudo chown -R tomcat apache-tomcat-<version> sudo chgrp -R tomcat apache-tomcat-<version>
- Using the new account, start the server:
su tomcat cd apache-tomcat-<version>/bin ./startup.sh
- Open a web browser and submit “localhost:8080”. If the user has been set up correctly, this Tomcat landing page appears again:
Setting Up Mathematica
Setting up Mathematica requires installing the program, activating it with your activation key and moving the generated licensing information into a location that makes it accessible globally on the machine in question.
Follow the instructions for installing Mathematica on Linux.
Ensure you use the appropriate file name:
sudo sh Mathematica_12.x_LINUX.sh
Take note of the installation directory you choose if you do not use the default.
Activate Mathematica using online or manual activation.
On Linux systems without X Window installed, the Mathematica front end will not be available. Instead, activate Mathematica through the kernel.
- Execute the following command:
- Enter your activation key. Note the activation key has the form XXXX-XXXX-XXXXXX.
Making Licensing Files Accessible to web Mathematica
By default, Mathematica places its licensing information in a mathpass file in a user-specific location. To make your licensing information accessible to your web Mathematica, copy the mathpass file into the globally accessible base directory of Mathematica and set its permission so that any account can read the file.
- To identify the location of your mathpass file, evaluate in Mathematica:
- To identify the base directory location, evaluate:
In:= $PasswordFile Out= /home/user/.Mathematica/Licensing/mathpass In:= $BaseDirectory Out= /usr/share/Mathematica
These folder locations are used in the following instructions.
- The Licensing directory may not yet exist. If so, create it by executing the following command:
sudo mkdir -p /usr/share/Mathematica/Licensing
- Copy the mathpass file to the Licensing directory of the base directory:
sudo cp /home/user/.Mathematica/Licensing/mathpass /usr/share/Mathematica/Licensing/.
- Grant read access to the mathpass file for all accounts:
sudo chmod a+r /usr/share/Mathematica/Licensing/mathpass
Installing and Setting Up web Mathematica
- Download web Mathematica’s installation file from your User Portal and unzip it to ensure it is opened and unpacked.
- Place the unzipped web Mathematica directory into the webapps directory of your Apache Tomcat server, where
$TOMCAT_INSTALLis the installation directory of your Tomcat server:
sudo mv webMathematica $TOMCAT_INSTALL/webapps/
- If you created a tomcat user to run the server, also change the ownership of the web Mathematica folder:
sudo chown -R tomcat $TOMCAT_INSTALL/webapps/webMathematica sudo chgrp -R tomcat $TOMCAT_INSTALL/webapps/webMathematica
- Restart the server from the account that owns the folder:
su tomcat cd $TOMCAT_INSTALL/bin ./shutdown.sh ./startup.sh
Testing and Troubleshooting
The web Mathematica package comes with some default pages that can be used to test the setup of web Mathematica.
- Access the base page by pointing a browser to “localhost:8080/webMathematica”.
- As a first test, click the Hello World example. The Hello World page providing the current time and date appears.
- If Hello World is not working, check the log file by executing:
Common possible issue:
Search the above log file for error
....com.wolfram.kerneltools.state.StateMachine [ERROR] Could not find MathLink executable. In such a case, web Mathematica could not find the executable of the Mathematica kernel. This can occur if you have installed Mathematica in a non-standard location or if your web Mathematica is not paired with its recommended Mathematica version, e.g. web Mathematica 3.5.3 with Mathematica 12.3. For the recommended pairings of other currently supported product versions, see here.
To point to the correctly paired version of Mathematica, configure web Mathematica.
- On the command line, go to
$TOMCAT_INSTALL/webapps/webMathematica/WEB-INF/and locate the file MSPConfiguration.xml.
- Open MSPConfiguration.xml in a text editor and locate the following section:
<KernelPool> <KernelPoolName>General</KernelPoolName> <URLPattern>/*</URLPattern> </KernelPool>
- Edit and change this section to:
<KernelPool> <KernelPoolName>General</KernelPoolName> <KernelExecutable> /usr/local/Wolfram/Mathematica/12.x/Executables/MathKernel </KernelExecutable> <URLPattern>/*</URLPattern> </KernelPool>
Note: These instructions assume Mathematica 12.x was installed to
/usr/local/Mathematica/12.x/. If you have a different installation directory, substitute the
installation directory you used.
Configuring Xvnc for Minimal or Server Editions of Linux
Many “Server” or “Minimal” distributions of Linux do not include an X Window server by default. Some Mathematica functionality and thus some web Mathematica functionality requires an X Window server to be available. For instance, the Plot Example cannot execute properly without an X Window system of some sort. For these purposes, it is recommended that you run an Xvnc server.
- Install an Xvnc server, which can commonly be obtained through command line install applications like yum or apt.
- Launch a vnc display with the command “vncserver”. This will initially require you to provide a display number (typically 1).
- Configure web Mathematica to use the display by editing the file
$TOMCAT_INSTALL/webapps/webMathematica/WEB-INF/MSPConfiguration.xmlto include the following code:
<KernelPool> .... <FrontEndLaunchFlags> -display :1 -nogui 1000x500+10+10 </FrontEndLaunchFlags> .... </KernelPool>
Whether you have a question about billing, activation or something more technical, we are ready to help you.
1-800-WOLFRAM (+1-217-398-0700 for international callers)
8am–5pm US Central Time
- Product registration or activation
- Pre-sales information and ordering
- Help with installation and first launch
Advanced Technical Support (for eligible customers)
8am–5pm US Central Time
8:30–10am & 11am–5pm US Central Time
- Priority technical support
- Product assistance from Wolfram experts
- Help with Wolfram Language programming
- Advanced installation support