Setting up a Web server that supports jsp+php on Linux

Source: Internet
Author: User
Tags install php mysql variables php file php and variable web services mysql database
Js|web|web Service |web Server In recent years, Linux in the server market accounted for a growing proportion, in addition to Linux for free and security, but also because of the increasingly rich application services on Linux. Most common services have a better solution on Linux. Linux has done even better with the most widely used Web services on intenet. No one can say how many Web sites there are on the Internet, but in many sites, the use of PHP and JSP development site undoubtedly occupies a great market share. Here's how to set up a Web server that supports Jsp+php+mysql on Linux.

For Web services, Apache is undoubtedly the preferred choice. Database to choose MySQL, which is enough for the general application, of course, Linux can also install Oracle, DB2 and other large databases, but they are expensive. As for the development of language support, JSP and PHP is undoubtedly the most mainstream and most widely used web development language. All of these software can be found on the following websites:

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 author downloads the following software:

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

First, install MySQL

MySQL installation is simpler, but the compilation process may be a bit long, the following steps:

# 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_db

Modify the/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

Start MySQL with the following command

/usr/local/terry_yu/mysql/bin/mysqld_safe &

Modify the MySQL root password with the following command:

/usr/local/terry_yu/mysql/bin/mysqladmin-uroot Password ABCDEFG

Use the following command to enter the command line for MySQL:

[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 indicates that MySQL has successfully run.

Second, the installation of 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 currently logged on environment and log back in so that the environment variable you just set will take effect, and then test with the following command:

[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)

Seeing similar information indicates that the JDK environment is good. 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 following installation resin necessary settings.

Third, the installation of MySQL JDBC

MySQL's JDBC related environment variables are already set up in the front, so the rest is only installed with 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

Four, install Apache

Http://apache.linuxforum.net/dist/httpd/apache_1.3.28.tar.gz

It should be noted that when compiling Apache must join the DSO support, if not, please add the--ENABLE-MODULE=SO option to recompile Apache

# TAR-XZPVF Apache_1.3.28.tar.gz
# CD apache_1.3.28/
#./configure--prefix=/usr/local/terry_yu/apache--enable-module=most
--enable-shared=max
# make
# make Install

View the modules compiled into Apache:

#/usr/local/terry_yu/apache/bin/httpd-l
Compiled-in Modules:
Http_core.c
Mod_so.c

See the above information indicates Apache support DSO mode. This can use the way of DSO to the PHP and resin modules added in.

V. Installation of PHP

Install PHP is simpler, we first installed PHP.

# TAR-XZPVF Php-4.3.3.tar.gz
# CD PHP-4.3.3/
#./configure--with-mysql=/usr/local/terry_yu/mysql
--with-apxs=/usr/local/terry_yu/apache/bin/apxs
# make
# make Install
# CP Php.ini-dist/usr/local/lib/php.ini

The configuration file for editing PHP is/usr/local/lib/php.ini, which modifies the register_globals variable to on and the default is off. You need to change it to on. Otherwise, PHP can not read directly to the post or get data phenomenon.

Edit Apache's configuration file/usr/local/terry_yu/apache/conf/httpd.conf, and add the following line at the end of the file:

AddType application/x-httpd-php. php. php3

Start Apache:

#/usr/local/terry_yu/apache/bin/apachectl Start

You can then test the installation of PHP with a simple PHP file that contains the following line:

? Phpinfo ();?>

Save it as a/usr/local/terry_yu/apache/htdocs/info.php, and then browse through the browser, and if you view the page with the "PHP Version4.3.3" title, it means that the integration of PHP and Apache is successful. And you can see PHP-related options on this page, which should have subkeys about MySQL, indicating that PHP has built-in support for MySQL. This means that the Php+mysql+apache environment has been successful, followed by the installation of resin to support the JSP environment.

Six. Install resin

Http://www.caucho.com/download/resin-3.0.3.tar.gz

The downloaded resin installation package should be able to run directly when it is untied. The author will untie it and put 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 set up the relevant environment variables before installing the JDK, you will be able to see the resin page from the http://localhost:8080/, which means that the individual resin is running successfully. Then, in order to integrate resin and Apache, we need to recompile to generate the Mod_caucho call to Apache.

# 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, approximately on line 159th (the resin version of the installation is different, the contents of the configuration file may vary), the <document-directory> Modified to its own Apache DocumentRoot value.

<resin xmlns=http://caucho.com/ns/resin>
<server>

<document-directory>/usr/local/terry_yu/apache/htdocs</document-directory> # #这里修改成/usr/local/terry_ Yu/apache/htdocs

...
</server>
</resin>

Modify/usr/local/terry_yu/apache/conf/ httpd.conf, when compiling resin, the installer has modified httpd.conf, but not quite right, it should be changed to a configuration similar to the following, if you complete the installation by this article can copy the content directly:

LoadModule Caucho_module libexec/mod_caucho.so
Addmodule mod_caucho.c

<ifmodule mod_caucho.c>
Resinconfigserver localhost 6802
<Location/caucho-status>
SetHandler Caucho-status
</Location>
</IfModule>
After the modification, after restarting the resin, it takes effect:

/usr/local/terry_yu/resin/bin/httpd.sh restart
/usr/local/terry_yu/apache/bin/apachectl restart

Access to http://localhost/caucho-status/through the browser, if the following page shows that resin and Apache have been successfully integrated.






Then test the JSP access to the database, under the/usr/local/apache/htdocs/with JSP to write a simple JSP file to connect the MySQL database of this computer:

vi/usr/local/terry_yu/apache/htdocs/testdb.jsp

You can paste it directly by entering the following:

<title>test JDBC for Mysql</title>
<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&AMP;PASSWORD=ABCDEFG");
%>
</body>

Through the browser to access Http://localhost/testdb, if you see a blank page without any error messages, it means that the MySQL database of JSP connected to this computer is successful, so we have completed a Web server supporting Jsp+php+mysql.

Note: All of the above installations are done on red Hat Linux9.0, and the software used is currently (September 2003) the latest version.

This article describes how to set up a web Server that supports both JSP and PHP on Linux, demonstrating the installation and simple testing process for MySQL, JDK, JDBC, Apache, PHP, resin, and so on.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.