Article
JSP Quick-Start Guide for Linux
Downloading and Installing Apache Server
While there are some great commercial servers out there for testing JSP pages (including IBM WebSphere, BEA WebLogic, and others), these can be beyond the reach of the average Web developer who just wants to add a new skill to his or her repertoire. For this reason, the server I recommend for people getting started with JSP is Apache Server. By hooking it up to the Jakarta Project's Tomcat Server (which we'll install in the next section), we can give it the ability to handle JSP pages, as well as related technologies like Java Servlets and Enterprise Java Beans (EJBs)!
Now, if you've already got Apache running (as most Linux users do), you don't have to reinstall it. This will be good news to people who are already using Apache to run PHP scripts or whatnot, because you'll be able to simply add JSP support to your existing server without disrupting whatever else you have set up.
If you don't have Apache installed, now is the time to do it. Just use your distribution's package manager to install Apache. When you're done, you can skip ahead to the next section. If you're not sure how to use your distribution's package manager, or if you prefer installing software yourself to letting the package manager do it, read on.
You'll need to go to The Apache HTTP Server Project's Web site to download the latest stable source release of Apache Server for Unix. As of this writing, the current version is 2.0.44 (the filename is httpd-2.0.44.tar.gz), and can be downloaded from the following address: http://www.apache.org/dist/httpd/.
Once you've downloaded the file, extract it to your home directory (or wherever you find convenient) to create a directory called httpd-2.0.44:
[kevin@sp kevin]$ tar xfz httpd-2.0.44.tar.gz
[kevin@sp kevin]$ cd httpd-2.0.44/
[kevin@sp httpd-2.0.44]$
Note, the [kevin@sp kevin]$ portion of the above represents the command prompt. You only need to type the commands shown in bold.
Next, you need to configure Apache so that it will be compiled with the features you need and installed where you want it to go. The following command (which should be typed all on one line) sets up Apache to be installed in /usr/local/apache2 and enables dynamic module support (which we'll need to interface with Tomcat) and the mod_rewrite module (which is not important for this article, but is a useful feature you'll probably want at some point):
[kevin@sp httpd-2.0.44]$ ./configure --with-prefix=/usr/local/apache2
--enable-so --enable-rewrite
After all the diagnostic messages have scrolled by, you should return to the command prompt. Now type the make command to compile Apache server:
[kevin@sp httpd-2.0.44]$ make
Again, pages of messages will scroll by. When they're done, the last step is to install Apache. Unless you specified a target directory beneath your home directory above, you'll need to log in as the root user (type su to do this) before you can proceed:
[kevin@sp httpd-2.0.44]$ su
Password: ********
[root@sp httpd-2.0.44]# make install
With Apache installed, you can run it by logging in as root and running the apachectl program in the /usr/local/apache2/bin directory with the start argument:
[root@sp /]# /usr/local/apache2/bin/apachectl start
Open your Web browser and type http://localhost/ in the address field and press Enter. A Web page with the Powered by Apache logo at the bottom should appear, explaining that Apache is correctly installed. Congratulations, you've successfully installed Apache!
Running Apache Automatically
Obviously, you don't want to have to start Apache manually every time you start your computer. To get Linux to launch Apache at start-up, you need to place a link to the apachectl program in the start-up folder for each runlevel (or operating system mode) where you want Apache to run.
Here's the series of commands that will set up Apache to run automatically in runlevels 2, 3, 4, and 5 (all the normal operating modes of Linux systems), and shut down when the computer shuts down:
[root@sp /]# cd /etc
[root@sp etc]# ln -s /usr/local/apache2/bin/apachectl init.d/apache2
[root@sp etc]# ln -s init.d/apache2 rc2.d/S91apache2
[root@sp etc]# ln -s init.d/apache2 rc3.d/S91apache2
[root@sp etc]# ln -s init.d/apache2 rc4.d/S91apache2
[root@sp etc]# ln -s init.d/apache2 rc5.d/S91apache2
[root@sp etc]# ln -s init.d/apache2 rc0.d/K20apache2
That should do it! To try it out, shut down your computer, start it back up again, and see if you can still access the Apache server at http://localhost/.