The following is that I am installing Apache under Red Hat Linux 8.0, allowing it to support PHP and JSP, and as a complete process of the background database with MySQL.
Now sort out, for your reference, time rush, if it is wrong, hope to correct.
(Testing on Red Hat Linux 8.0)
The software you need:
J2SDK-1.3.1_04-linux-i586.bin
Apache_1.3.12.tar.gz
PHP-4.03PL1.TAR.GZ
mysql-3.22.27.tar.gz
JAKARTA-TOMCAT-3.1.1.tar.gz
MOD_JSERV.SO
mm.mysql.jdbc-1.2c.tar.gz
(Note: When installing RH8.0, select custom installation, no need, unsettled, the above software installation directory is / usr / local)
(1) Software installation and related configuration
1: Install JDK
Copy J2SDK-1.3.1_04-Linux-i586.bin file to / usr / local directory,
#CHMOD X J2SDK-1.3.1_04-Linux-i586.bin (Change file properties is available)
#. / j2sdk-1.3.1_04-linux-i586.bin
Generate /usr/local/jdk1.3.1_04 directory
2: Install MySQL
Since the relevant parameters for MySQL are used when installing the PHP, the mysql database should be installed first before installing PHP, Apache.
#tar vfxz mysql-3.22.27.tar.gz (extract the database compression package, and create a directory named "mysql-3.22.27")
#CD MYSQL-3.22.27 (Enter the top and directory of unpack distribution)
#. / configure --prefix = / usr / local / mysql (parameter configuration before compiling, parameter prefix corresponds to the corresponding installation directory)
#make (compilation of the source code for configuring the mysql of the installation parameter)
#make install (Start installing MySQL, you need root users to run this command)
# Scripts / mysql_install_db (Create a MySQL Authorization Form)
The mysql database can be successfully installed through the above steps.
After the installation is complete, you need to start the MySQL server.
# / usr / local / mysql / bin / safe_mysqld & (Start Mysql Server)
3: Install Apache and PHP
#tar vfxz apache_1.3.12.tar.gz (Unpack Apache, and create a directory called "apache_1.3.12")
#TAR VFXZ PHP-4.03PL1.TAR.GZ
#CD Apache_1.3.12
#. / configure --prefix = / usr / local / wwww
#cd ../php-4.03pl1
#. / configure --with-mysql --with-apache = .. / apache_1.3.12 --enable-track-vars
(Parameter with-mysql means supports the MySQL database, with-apache corresponds to the path of the Apache source file)
#make
#make install
#cd ../apache_1.3.12
#. / configure --prefix = / usr / local / www --activate-modules = src / modules / php4 / libphp4.a --enable-module = SO
(Add a PHP module in the Apache source file directory, where --Nable-module = SO is added to MOD_JSERV.SOSo)
#make
#make install
#cd ../php-4.03pl1
#CP php.ini-dist /usr/local/lib/php.ini
4: Copy MOD_JSERV.SO
Copy MOD_JSERV.so to Apache's libexec directory
#CP MOD_JSERV.SO / USR / local / www / libexec
5: Install Tomcat
Copy JAKARTA-TOMCAT-3.1.1.tar.gz file to / usr / local directory, perform the following command:
#TAR VFXZ JAKARTA-TOMCAT-3.1.1.tar.gz
Generate / usr / local / jakarta-tomcat directory
6: Install the JDBC driver of mysql
Copy mm.mysql.jdbc-1.2c.tar.gz file to / usr / local directory
#tar vfxz mm.mysql.jdbc-1.2c.tar.gz
Generate /usr/local/mm.mysql.jdbc-1.2c directory
7: Configure system variables
#vi / etc / profile (edit / etc / profile file)
Add:
Java_Home = / usr / local / jdk1.3.1_04
JRE_HOME = / usr / local / jdk1.3.1_04 / jre
Tomcat_home = / usr / local / jakarta-tomcat
ClassPath = $ java_home / lib / Tools.jar: $ java_home / lib / dt.jar:.: $ Jre_home / lib: /usr/local/mm.mysql.jdbc-1.2c
PATH = $ PATH: $ java_home / bin: $ jre_home / bin: $ TOMCAT_HOME / BIN
Export java_home jre_home Tomcat_home classpath path
(Note: Configuring system variables, re-login after logging out, to make the settings take effect)
8: Configure the httpd.conf of apache
Copy Tomcat.conf file to Apache's confed
#cp /usr/local/jakarta-tomcat/conf/tomcat.conf / usr / local / www / confed
Edit Apache httpd.conf file
Remove the comments in front of the following two lines:
AddType Application / X-httpd-php .php
AddType Application / X-httpd-source .phps
Tell the Apache server, the extension .php is a special program file.
Add:
Include /usr/local/www/conf/tomcat.conf
(About Apache's detailed configuration, you can refer to other information)
9: Start Apache and Tomcat
#CD / USR / LOCAL / WWW / BIN
#. / apachectl start (Start an Apache server, close usage ./apachectl stop)
#CD / USR / LOCAL / JAKARTA-TOMCAT / BIN
#. / tomcat.sh start (Start Tomcat, close Using ./TOMCAT.SH STOP)
After the above steps, the Linux Apache PHP / JSP MYSQL environment has been basically established, which can test PHP / JSP.
(2) Test PHP and JSP, and connect to the MySQL database
1: Mysql preparation
In the mysql previously installed, the root password is not set. Create a test database now, name my_test:
#mysql -u root -p
MySQL> CREATE DATABASE MY_TEST; (Create Database MY_TEST)
Mysql> USE_TEST; (Go to my_test database)
MySQL> CREATE TABLE MY_TEST_TABLE (Test_Column Char (20) NULL); (Create a Data Table in my_test database MY_TEST_TABLE) mysql> INSERT my_test_table value ('Welcome to MySQL!'); (Add a line in my_test_table table)
Mysql> EXIT
#
2: (1) Test PHP
#CD / USR / LOCAL / WWW / HTDOCS
#vi info.php
Wherein, the content in Info.php is as follows:
phpinfo ();?>
Save exit, open your browser, type http://localhost/info.php at address bar
If you can see a long PHP information list, it indicates that PHP is integrated with apache.
(2) Test PHP connection mysql
PHP connection MySQL is simple and does not require any settings.
Create a new file mysqltest.php in the HTDOCS directory of the Apache installation directory:
hEAD>
$ dbcnx = mysql_connect ("localhost", "root", "");
MySQL_SELECT_DB ("My_TEST");
$ Result = mysql_query ("Select * from my_test_table", $ dbcnx);
While ($ row = mysql_fetch_array ($ result))
ECHO ("
?>
body>
html>
Where mysql_connect () is used to connect to the database server;
MySQL_SELECT_DB () is used to select a job database;
MySQL_QUERY () is used to perform SQL queries;
MySQL_FETCH_ARRAY () is used to get the result set of SELECT
Open the browser, enter http://localhost/mysqltest.php at the address bar
You should be able to see Welcome to MySQL! This information.
3: (1) Test JSP
Open the browser, type http: // localhost / example in the address bar
It can be seen to see the JSP, servlet directory, indicating that Apache and Tomcat have been successfully connected, and you can use JSP and servlet.
(2) Test JSP connection mysql
JSP connection Mysql requires a third-party JDBC driver,
Here is mm.mysql.jdbc-1.2c.tar.gz (system variables already configured in front)
Create a JavaBean, named dbconn.java, create under Tomcat's WebApps / Examples / Web-INF / CLASSES
The mysqltest directory saved the file in this directory, and dbconn.java is used to encapsulate the operation of the database link.
The content of dbconn.java is as follows:
Package mysqltest;
Import java.sql. *;
Public class dbconn {string dbdriver = "org.gjt.mm.mysql.driver";
String connStr = "jdbc: mysql: // localhost / my_test";
String myuser = "root";
String mypassword = ""
Connection conn = NULL;
ResultSet RS = NULL;
Public dbconn ()
{TRY
{Class.Forname (dbdriver);
}
Catch (java.lang.classnotfoundexception e)
{System.err.Println ("dbconn ():" E.GetMessage ());
}
}
Public ResultSet ExecuteQuery (String SQL)
{RS = NULL;
Try
{conn = drivermanager.getConnection (connStr, myuser, mypassword);
Statement Stmt = conn.createstatement ();
RS = stmt.executequery (SQL);
}
Catch (SQLException EX)
{System.err.println ("AQ.ExecuteQuery:" ex.getMessage ());
}
Return RS;
}
}
Compile DBCONN.JAVA with JDK Javac command
#javac dbconn.java
Form a corresponding Class file.
Built mysqltest.jsp files in Tomcat's WebApps / Examples / JSP directory, as follows:
<% @ Page ContentType = "text / html; charset = GB2312"%>
hEAD>
<% @ page language = "java" import = "java.sql. *"%>
<%
ResultSet RS = DBCONN1.EXECUTEQUERY
("SELECT * from my_test_table");
While (rs.next ()) {
Out.print ("
}
Rs.close ();
%>
body>
html>
Enter http://localhost/examples/jsp/mysqltest.jsp //localhost/examples/jsp/mysqltest.jsp
You should be able to see Welcome to Mysql! Information.
At this point, all installation configurations have been completed, and PHP MySQL and JSP MySQL can be run simultaneously on Linux.