In recent years, Linux's share of the server market has been increasing, not only because Linux is free and secure, but also because the application services on Linux are increasingly abundant. Most common services have better solutions on Linux. For the most widely used Web services on the Internet, Linux's performance is even better. No one can tell how many websites there are on the Internet, but among many websites, websites developed using PHP and JSP undoubtedly occupy a huge market share. Let's introduce how to set up a web server that supports JSP+PHP+MySQL on Linux.
For web services, apache is undoubtedly the first choice. For the database, MySQL is used, which is sufficient for general applications. Of course, large databases such as Oracle and DB2 can also be installed under Linux, but they are expensive. As for support for development languages, JSP and PHP are undoubtedly the most mainstream and widely used web development languages. All these software we can find from the following website:
Resin: http://www.caucho.com/
JDK: http://java.sun.com/
Apache: http://www.apache.org
MySQL: http://www.mysql.com
PHP: http://www.php.net
MM.MySQL: http://mmmysql.sourceforge.net/
Download the corresponding software from the above website. The software I downloaded is as follows:
mysql-4.0.15.tar.gz
apache_1.3.28.tar.gz
php-4.3.3.tar.gz
resin-3.0.3.tar.gz
mysql-connector-java-3.1.0-alpha.tar.gz
j2sdk-1_4_2_01-linux-i586.bin
1. Install MySQL
The installation of MySQL is relatively simple, but the compilation process may be a bit long. The specific steps are as follows:
# tar -xzpvf mysql-4.0.15.tar.gz
# adduser -s /bin/false mysql
# ./configure --prefix=/usr/local/terry_yu/mysql --enable-assembler
--with-innodb --with-charset=gb2312
#make
# make install
# /usr/local/terry_yu/mysql/bin/mysql_install_db
# chown -R root /usr/local/terry_yu/mysql/
# chown -R mysql /usr/local/terry_yu/mysql/var
# chgrp -R mysql /usr/local/terry_yu/mysql/
# /usr/local/terry_yu/mysql/bin/mysql_install_dbModify
/etc/ld.so.conf and add the following line at the end:
/usr/local/terry_yu/mysql/lib/mysql/lib
Then execute the following command:
# ldconfig
Use the following command to start MySQL
/usr/local/terry_yu/mysql/bin/mysqld_safe &
use the following command to modify the root password of MySQL:
/usr/local/terry_yu/mysql/bin/mysqladmin -uroot password abcdefg
Use the following command to enter the MySQL command line:
[root@terry root]# /usr/local/terry_yu/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1 to server version: 4.0.15
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> quit
Bye
the above information appears indicating that MySQL has been successfully run.
2. Install JDK
# chmod 755 j2sdk-1_4_2_01-linux-i586.bin
# ./j2sdk-1_4_2_01-linux-i586.bin
# mv j2sdk1.4.2_01/ /usr/local/terry_yu/
# cd /usr/local/terry_yu/
# ln -s j2sdk1.4.2_01/ jdk
# ln -s jdk/jre/ jre
# vi /etc/profile
JAVA_HOME=/usr/local/terry_yu/jdk
RESIN_HOME=/usr/local/terry_yu/resin
CLASSPATH=.:../$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$RESIN_HOME/lib:/usr/ local/terry_yu/jdbc
PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
Exit the current login environment and log in again so that the environment variables just set will take effect. Then use the following command to test:
[root@terry root]# java -version
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot (TM) Client VM (build 1.4.2_01-b06, mixed mode)
If you see similar information, it means that the JDK environment is ready. In fact, in the above /etc/profile, we not only set the JDK environment variables, but also set the Resin and JDBC environment variables. These are the settings necessary for the subsequent installation of Resin.
3. Install MySQL’s JDBC.
The related environment variables of MySQL’s JDBC have been set previously, so the rest is just to install according to the following command:
# tar -xzpvf mysql-connector-java-3.1.0-alpha.tar.gz
# mv mysql-connector-java-3.1.0-alpha /usr/local/terry_yu/
# cd /usr/local/terry_yu/
# ln -s mysql-connector-java-3.1.0-alpha/ jdbc
4. Install Apache
The downloaded resin installation package should be able to be run directly after being unpacked. The author unzipped it and placed it in the /usr/local/terry_yu directory
# tar -xzpvf resin-3.0.3.tar.gz
# mv resin-3.0.3 /usr/local/terry_yu/
# cd /usr/local/terry_yu/
# ln -s resin-3.0.3/ resin
start resin
# /usr/local/terry_yu/resin/bin/httpd.sh start
If you have set the relevant environment variables when you installed the JDK before, you can see the resin page from http://localhost:8080/. This is also This means that the individual resin runs successfully. Then, in order to integrate resin and apache, we need to recompile it to generate mod_caucho for Apache to call.
# cd /usr/local/terry_yu/resin
# ./configure --with-apache=/usr/local/terry_yu/apache
#make
# make install
Modify /usr/local/terry_yu/resin/conf/resin.conf, about line 159 (the installed resin version is different, the content of the configuration file may be different), modify <document-directory> to your own The value of apache's DocumentRoot.
<resin xmlns=http://caucho.com/ns/resin>
<server>
<host id="">
<document-directory>/usr/local/terry_yu/apache/htdocs</document-directory> ##Change here to /usr/local/terry_yu/apache/htdocs
...
</host>
</server>
</resin>
Modify /usr/local/terry_yu/apache/conf/httpd.conf. When compiling resin, the installation program has modified httpd.conf, but it is not completely correct. It should be changed to a configuration similar to the following. If you An installation that follows this article can directly copy these contents:
LoadModule caucho_module libexec/mod_caucho.so
AddModule mod_caucho.c
<IfModule mod_caucho.c>
ResinConfigServer localhost 6802
<Location /caucho-status>
SetHandlercaucho-status
</Location>
</IfModule>
After modification, it will take effect after restarting resin:
/usr/local/terry_yu/resin/bin/httpd.sh restart
/usr/local/terry_yu/apache/bin/apachectl restart
Go to http://localhost/caucho-status/ through the browser. If the following page appears, it means that resin and apache have been successfully integrated.
Then test JSP's access to the database. Use jsp to write a simple jsp file under /usr/local/apache/htdocs/ to connect to the local MySQL database:
vi /usr/local/terry_yu/apache/htdocs/testdb .jsp
enter the following content, you can paste it directly:
<html>
<head>
<title>Test JDBC For MySQL</title>
</head>
<body>
<%@ page contentType="text/html;charset=gb2312" %>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection conn;
conn =
java.sql.DriverManager.getConnection("jdbc:mysql://localhost/mysql?user=root&password=abcdefg");
%>
</body>
</html>
Access http://localhost/testdb through the browser. If you see a blank page without any error message, it means that jsp has successfully connected to the local MySQL database. At this point, we have completed a project that supports JSP+ PHP+MySQL web server.
Note: All the above installations were completed on Red Hat Linux 9.0, and the software used is the latest version currently (September 2003).
This article introduces how to set up a Web Server that supports both JSP and PHP on Linux, and demonstrates the installation and simple testing process of MySQL, JDK, JDBC, Apache, PHP, and Resin.