Wednesday, December 30, 2009

how to install Wt on Mac OS

What is Wt?
Wt (pronounced 'witty') is a C++ library for developing interactive web applications.

In July 2009, I tried installing Wt 2.99.2.  Right away I realized this was not going to be a simple task. I had to retry installing it a few times, so I kept notes of what I tried so that I would know what I did once I finally got it working. After a few days, I still hadn't got it working. I had trouble getting Wt to find my boost installation. The problem turned out to be that I did not do an 'install' command. Several different ways and options were given for installing and I did not understand the differences. Such as the difference between the build and the install.

Finally, at the end of December, I tried again. There was a new version of Wt (3.0.0), so I downloaded it.

The following shows you what I saved as my successful steps to installing Wt on Mac OS X version 10.5.8.  These steps could be improved and are not meant to be the ideal path, but are here to help anyone like me who searched the web to find how to install Wt on Mac OS.



Hopefully, someone can make an installer for Wt. Until then, I hope my experience can benefit a few people who might take the time to lay out a better path and share it with us. I may be missing a few steps in my list below.

Here are links to the pages I used for resources:
Boost Getting Started on Unix Variants
Installing Wt on Mac OS X Leopard
Downloading ICU (ICU - International Components for Unicode)
FastCGI

For editing files, I am using TextWrangler which is free!

For your reference, I unzipped and moved the software components to the following directory:
/usr/local/

The way to open this folder in your Mac OS finder is to use the Go menu,
Go to Folder...
and type the path in the prompt box.

You also need to use the Terminal. I have colored my Terminal prompt blue and my commands in red below.

Here is what I did:

  • I installed ICU for international text, sot that Boost could be built with it.
Here are the commands I saved when I installed ICU.
First, in the Terminal window, I changed to the source directory where I put ICU.
mini:~ keith$ cd /usr/local/icu/source

mini:source keith$ ./runConfigureICU MacOSX

mini:source keith$ make

mini:source keith$ sudo make install

  • Next, I installed Boost like this:

mini:boost_1_39_0 keith$ ./bootstrap.sh --prefix=/usr/local --with-libraries=date_time,regex,program_options,signals,system,thread --with-icu --exec-prefix=/usr/local --libdir=/usr/local/lib --with-toolset=darwin

mini:boost_1_39_0 keith$ sudo ./bjam
Password:

mini:boost_1_39_0 keith$ sudo ./bjam install
Password:

  • Then I installed Wt this way:

mini:wt-3.0.0 keith$ mkdir build
mini:wt-3.0.0 keith$ cd build

mini:build keith$ cmake -DBOOST_VERSION=1_39 -DBOOST_COMPILER=xgcc40 -DBOOST_DIR=/usr/local ../

If you have a different version of Boost or Compiler, you'll have to change those! You may also be using a different directory.

mini:build keith$ make

mini:build keith$ sudo make install

There is one failure in the script. It had tried to change the owner of the /usr/wt/run folder to apache, however that user does not exist. Apache runs under the www user for Mac, so do this:

mini:~ keith$ sudo chown www:www /usr/wt/run
  • Next, to install the examples, I did this:
mini:build keith$ make -C examples

mini:build keith$ cd examples/treeview-dragdrop
mini:treeview-dragdrop keith$ sudo ./deploy.sh

  • Then, to install FastCGI, I did this:
Go to the FastCGI Servers page: http://www.fastcgi.com/drupal/?q=node/3
Click on download: http://www.fastcgi.com/dist/
And click mod_fastcgi-current.tar.gz to get the latest module for Apache.

Then I unzipped that file and it created a folder called, mod_fastcgi-2.4.6.
So I decided to move that folder to my /usr/local/ directory.
After reading the README file, I needed to read the instructions in the file called INSTALL.AP2.

My Apache2 installation isn't in /usr/local/apache2 so I needed to use top_dir=/usr/share/httpd
This is where I found the build/special.mk file. Is this wrong?

So then, following the instructions:

mini:treeview-dragdrop keith$ cd /usr/local/mod_fastcgi-2.4.6
mini:mod_fastcgi-2.4.6 keith$ cp Makefile.AP2 Makefile
mini:mod_fastcgi-2.4.6 keith$ make top_dir=/usr/share/httpd


mini:mod_fastcgi-2.4.6 keith$ sudo make install top_dir=/usr/share/httpd

Next, open /private/etc/apach2/httpd.conf
Do a search to find fastcgi. It is commented out and looks like the line below.
#LoadModule fastcgi_module     libexec/apache2/mod_fastcgi.so
You need to remove # to uncomment the line.


At the bottom of that httpd.conf, there was this line
Include /private/etc/apache2/other/*.conf

So in that folder, I created a mod_fastcgi.conf file with the following:


<ifmodule mod_fastcgi.c="">
  # Start a "static" server at httpd initialization 

  #     inside the scope of the AddHandler
  FastCgiServer /var/www/localhost/htdocs/wt-examples/treeviewdragdrop/treeviewdragdrop.wt
</ifmodule>


  • How to restart Apache web server in Mac OS

Next, restart Apache server by going to System Preferences,
If you have it in your doc, it looks like this:

If not, you can open System Preferences from the apple menu.

 Click Sharing,





uncheck Web Sharing to stop the web server and then check the box again to start.

FastCgi is not working with my Apache. I may need to upgrade my Apache version. I have the latest FastCgi but the same Apache2 that was pre-installed on my computer 2 years ago.

  • Next step, try the built-in webserver.
I already ran the

$ make -C examples

 along with the deploy line, in the step above with fastcgi.
So, then I started from here:

 

mini:~ keith$ cd /private/var/www/localhost/htdocs/wt-examples/treeviewdragdrop

The next instruction was this line:
$ ln -s ../../resources . # include standard Wt resource files
This creates a link, but when I tried it, 
I received a message about it already existing.

mini:treeviewdragdrop keith$ sudo ./treeviewdragdrop.wt --docroot . --http-address 0.0.0.0 --http-port 8080
[2009-Dec-29 23:52:56.228379] 702 - [notice] "Wt: initializing built-in httpd"
[2009-Dec-29 23:52:56.229847] 702 - [notice] "Reading Wt config file: /etc/wt/wt_config.xml (location = './treeviewdragdrop.wt')"
[2009-Dec-29 23:52:56.286445] 702 - [notice] "Starting server: http://0.0.0.0:8080"

After it says it is starting the server, it doesn't output any more until you go to the web page and look at the example. As per the instructions, the address was: http://127.0.0.1:8080/

  • Improving the steps
You may want to install FastCGI before Wt. I noticed my Wt installation had installed without support for FastCGI. So even if I can get FastCGI working with Apache, I will need to fix my Wt installation. Probably by reinstalling it! I don't know if Wt checks for FastCGI or if you will need to set the option for it.

When you install Wt, you may be able to set the user of the web server.  It seems there may be a configuration option which could be added to the cmake command. Look for WEBUSER and WEBGROUP.

There are also some options that I haven't installed. Check the Wt generic instructions page for those.


OK, now all I have to do is learn how to program C++! I know the basics though. I installed Wt so I could create something in C++ and be able to show it on the web from a web address. So I hope I will be able to also get everything working with my shared host provider. Also, I don't like dealing with html divs and different browsers, so I hope Wt takes care of the presentation layer.

If this blog post has helped you, please leave a comment. Thanks!

2 comments:

Anonymous said...

SUPER HELPFUL!

Richard L said...

SUPER HELPFUL. Ran across your blog while trying to install WT myself