- Root of this topic
- Debian Webserver
- Learn Emacs
- GUI vs. Prompt
- ruQueue
- Iron Key
An easy way to configure a webserver with Debian GNU/Linux This informal document reflects my opinion on how to setup a webserver that is easy to maintain and uses some of my favorite software. I am about to install Apache, PHP, and MySQL on a new server. I am also going to include PHP's LDAP and GD modules. The LDAP module will allow my webserver to connect to the Rugters Directory Service, which is useful for retrieving adminstrative data. The GD module will allow my PHP scripts to create images dynamically. I am also going to install an implementation of JavaServer Pages just for fun to try it out with Debian. I actually think that PHP is much better than JSP and mixing both on the same server is a little odd (so you might want to skip this step). I recomend the Debian GNU/Linux Operating System, particularly for this case because of its package management tools. If you would prefer to use the RPM package managment system there are similar apt utitlies avaialable. However, the package names won't be directly mapable. Why am I using a Package Manager? It is a good experience to install packages from source (downloading the source tree tarball and doing a make && make install), but there are problems with doing things that way. The traditional way to install software on a Unix system is to download the source code, compile it, and then install it on your system. Installing software in this manner can be a good learning experience, but it introduces the following problems:
- Dependencies are not managed. For example a piece of software that you are trying to install could need another piece software, and in turn that piece of software could have the same problem.
- There is no clean way to uninstall the software. For example, installing your software could have put files in lots of places on your system, and it could be tricky to track down and remove those files.
- There is no consistent interface for installing the software. A lot of source based software packages have a consistent method of installation, but this is not necessarily the case, and you might have to take time to learn the installation process behind each piece of software that you are interested in.
- There is no automatic way to keep track of what software has been installed on your system.
- As root execute the command apt-get install mysql-server.
The above should have installed the MySQL server on your system.
It is important that you set a MySQL client password next.
To do this:
- Start a MySQL client with the command mysql -u root. This should give you the 'mysql>' prompt.
- Execute the following command at the 'mysql>' prompt, such
that the string 'new_password' is the password that you want to set:
SET PASSWORD FOR root@localhost=PASSWORD('new_password'); - As you create databases that you want to be manipulated
via PHP scripts you will need to grant
MySQL privileges. In general this will involve typing something
along the lines of the following at the 'mysql>' prompt:
- create database x;
- use x;
- grant select, insert, update, delete on x.* to 'www-data'@localhost;
- As root execute the command apt-get install apache. You can test the success of this by pointing a browser at 'yourhostname.yourdomain', where you should see the appropriate welcome page. Again, apt should have also put symbolic links into the apprpriate /etc/rc* directory so that service will start and stop as the machine goes up and down.
- As root execute the command apt-get install php4.
- You will be prompted with a question about adding the following line:
LoadModule php4_module /usr/lib/apache/1.3/libphp4.so to your /etc/apache/httpd.conf file. Type y as in 'yes'.
- When you are returned to the root prompt, open your /etc/apache/httpd.conf file with your favorite editor and find the "LoadModule" line from above. If it is commented, remove the # symbol so that it will be executed.
- You can make additonal configurations to your /etc/apache/srm.conf file according to your preferences. One thing that I like to do is to change this line: DirectoryIndex index.html to this: DirectoryIndex index.html index.php Which allows index.php to executed like index.html files. By default Debian should have given your users to ability to publish home pages with a public_html directory. You can verify this by seeing that the this file should contain this line: UserDir public_html
- Restart apache with the command apachectl restart.
-
You can test the success of this by creating a tiny PHP script.
I recomend that you create a file in /var/www/ called
info.php whose content is the following line:
<? phpinfo(); ?>
and point your browser to 'yourhostname.yourdomain/info.php'. The phpinfo function should output information about your PHP configuration. - You could also become a normal user and create a public_html directory and see if an index.php file is able to be loaded by default.
- You will be prompted with a question about adding the following line:
- As root execute the command apt-get install php4-mysql. When asked if you want apt to update your /etc/php4/apache/php.ini file so that it has the line extension=mysql.so type y as in 'yes' and restart apache with the command apachectl restart. This is the module that allows PHP to talk to MySQL. To test to see if it worked you will have to create a MySQL database and a PHP script which attempts to talk to it. Don't forget to "grant privs to 'www-data'@localhost" when trying to use PHP/MySQL.
- As root execute the command apt-get install php4-ldap. When asked if you want apt to update your /etc/php4/apache/php.ini file so that it has the line extension=ldap.so type y as in 'yes' and restart apache with the command apachectl restart. To test if you LDAP module was installed corectly use this test code (Example 1 from the PHP Manual on LDAP functions). If you get an error message that says "Unable to connect to LDAP server" (assuming you are not running an LDAP server since it targets localhost), then it should be working. If you get an error message that says something along the lines of "Call to undefined function: ldap_connect()" then something is wrong with your PHP LDAP module.
- As root execute the command apt-get install php4-gd.
When asked if you want apt to update your
/etc/php4/apache/php.ini file so that it
has the line extension=gd.so type y as in 'yes'
and restart apache with the command apachectl restart.
You might want to stop here. I am only installing jserv to show how it might be done. Running both PHP and JSP on the same machine might not be necessary.
- As root execute the command apt-get install jserv.
As apt finishes its installation you should see the following:
By default, the servlet repository should be in /usr/share/java/servlets and should include two .class files:Setting up jserv (1.1-3) ... Starting JServ servlet engine: jserv. done. Reloading apache configuration. /usr/sbin/apachectl graceful: httpd gracefully restarted
To get a feel for how to use servlets with HTML and test that JServ is working with the above files you can create a file that contains this code, which contains this:$ ls -l total 8 -rw-r--r-- 1 root root 1132 May 10 2000 Hello.class -rw-r--r-- 1 root root 2119 May 10 2000 IsItWorking.class $
The above line of HTML causes the file Hello.class to be executed. The code should point your broswer at a page called 'yourhostname.yourdomain/servlets/Hello?' where you should see the output of Hello.class. The configuration files for the servlet engine can be found inside of /etc/jserv/. You can find information on how to change the configuration of the servlet engine here You can also find links on to use servlets here.<form method=get action="/servlets/Hello">
- As root execute the command apt-get install gnujsp.
As apt finishes its installation you should see the following:
A directory called /usr/share/doc/gnujsp will be created which will contain a directory called examples. To test that JSP is working you can copy the examples to your own public_html directory:Setting up gnujsp (1.0.0-5) ... Stopping JServ servlet engine: jserv. Starting JServ servlet engine: jserv. Reloading apache configuration. /usr/sbin/apachectl graceful: httpd gracefully restarted
and point your browser at 'yourhostname.yourdomain/~username/jsp/' to run them. For more information you can see some JSP tutorials and the GNUJSP website is here.cp -r /usr/share/doc/gnujsp/examples/ ~/public_html/jsp/

