RH8.0 + APACHE + PHPJSP + MYSQL Integration Example

xiaoxiao2021-03-06  38

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:

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:

PHP connection mysql </ title></p> <p><meta http-equiv = "Content-type" content = "text / html" charset = GB2312 "></p> <p></ hEAD></p> <p><body></p> <p><?</p> <p>$ dbcnx = mysql_connect ("localhost", "root", "");</p> <p>MySQL_SELECT_DB ("My_TEST");</p> <p>$ Result = mysql_query ("Select * from my_test_table", $ dbcnx);</p> <p>While ($ row = mysql_fetch_array ($ result))</p> <p>ECHO ("<p> <h1>". $ row ["test_column"]. "</ h1> </ p>");</p> <p>?></p> <p></ body></p> <p></ html></p> <p>Where mysql_connect () is used to connect to the database server;</p> <p>MySQL_SELECT_DB () is used to select a job database;</p> <p>MySQL_QUERY () is used to perform SQL queries;</p> <p>MySQL_FETCH_ARRAY () is used to get the result set of SELECT</p> <p>Open the browser, enter http://localhost/mysqltest.php at the address bar</p> <p>You should be able to see Welcome to MySQL! This information.</p> <p>3: (1) Test JSP</p> <p>Open the browser, type http: // localhost / example in the address bar</p> <p>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.</p> <p>(2) Test JSP connection mysql</p> <p>JSP connection Mysql requires a third-party JDBC driver,</p> <p>Here is mm.mysql.jdbc-1.2c.tar.gz (system variables already configured in front)</p> <p>Create a JavaBean, named dbconn.java, create under Tomcat's WebApps / Examples / Web-INF / CLASSES</p> <p>The mysqltest directory saved the file in this directory, and dbconn.java is used to encapsulate the operation of the database link.</p> <p>The content of dbconn.java is as follows:</p> <p>Package mysqltest;</p> <p>Import java.sql. *;</p> <p>Public class dbconn {string dbdriver = "org.gjt.mm.mysql.driver";</p> <p>String connStr = "jdbc: mysql: // localhost / my_test";</p> <p>String myuser = "root";</p> <p>String mypassword = ""</p> <p>Connection conn = NULL;</p> <p>ResultSet RS = NULL;</p> <p>Public dbconn ()</p> <p>{TRY</p> <p>{Class.Forname (dbdriver);</p> <p>}</p> <p>Catch (java.lang.classnotfoundexception e)</p> <p>{System.err.Println ("dbconn ():" E.GetMessage ());</p> <p>}</p> <p>}</p> <p>Public ResultSet ExecuteQuery (String SQL)</p> <p>{RS = NULL;</p> <p>Try</p> <p>{conn = drivermanager.getConnection (connStr, myuser, mypassword);</p> <p>Statement Stmt = conn.createstatement ();</p> <p>RS = stmt.executequery (SQL);</p> <p>}</p> <p>Catch (SQLException EX)</p> <p>{System.err.println ("AQ.ExecuteQuery:" ex.getMessage ());</p> <p>}</p> <p>Return RS;</p> <p>}</p> <p>}</p> <p>Compile DBCONN.JAVA with JDK Javac command</p> <p>#javac dbconn.java</p> <p>Form a corresponding Class file.</p> <p>Built mysqltest.jsp files in Tomcat's WebApps / Examples / JSP directory, as follows:</p> <p><% @ Page ContentType = "text / html; charset = GB2312"%></p> <p><html></p> <p><HEAD></p> <p><title> JSP connection mysql </ title></p> <p></ hEAD></p> <p><body></p> <p><% @ page language = "java" import = "java.sql. *"%></p> <p><jsp: usebean id = "dbconn1" scope = "page" class = "mysqltest.dbconn" /></p> <p><%</p> <p>ResultSet RS = DBCONN1.EXECUTEQUERY</p> <p>("SELECT * from my_test_table");</p> <p>While (rs.next ()) {</p> <p>Out.print ("<h1>" rs.getstring ("Test_Column") "</ h1>");</p> <p>}</p> <p>Rs.close ();</p> <p>%></p> <p></ body></p> <p></ html></p> <p>Enter http://localhost/examples/jsp/mysqltest.jsp //localhost/examples/jsp/mysqltest.jsp</p> <p>You should be able to see Welcome to Mysql! Information.</p> <p>At this point, all installation configurations have been completed, and PHP MySQL and JSP MySQL can be run simultaneously on Linux.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-79225.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="79225" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.034</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'bpegyNFK_2BqiEnVzm1eIICRww3Xditz9eie_2FUilbcVkl7NFcTcYo_2BSLrPExfIa5jTnIb2YPEeKbyhicUDTEjckQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>