Build a Web site and connect to a database in a Linux environment

Source: Internet
Author: User

Note: All the content is sister paper I personally set up a successful operation, if there is a problem, please email to communicate. [Email protected] (this QQ is only used to receive mail, under normal circumstances will not login, all have problems can send e-mail Oh ~ I will reply)

In my last article, I have already told the pro how to build a complete TOMCAT+MYSQL+JDK environment, this article focuses on how to release the war package, build a test environment. Follow one step at a to.

"Publish Test Site: War package"

1. First of all to popularize a little, we generally publish the Java project inside the war package, to publish is directly uploaded into the tomcat package inside the WebApps folder inside

2. We provide a war package here, http://yunpan.cn/cckiSSUd8RbKq access password c97e can directly access the download, This is a fake when a site. Upload the war pack xftp to the WebApps folder: Look carefully, this is the source package provided.

Here is the upload succeeded, but is a compressed package form. When we restart the Tomcat service, we can unzip it.

3. Enter the command:

Cd/usr/local/tomcat6/bin

./startup.sh

Then go to see the path of the WebApps, there is an unpacked folder, which indicates that the decompression was successful. You can access the site page directly.

4. Visit the Site page with the IP address:

http://192.168.111.128:8080/dangdang_dk/main/main.jsp

5. See below, then the successful decompression, access to the Web page success:

Note: Other website release is the same step, can imitate to try.

"Connect to Database"

Problem: see above, see the page has been loading, do not see the data, can judge the reason is no data, because we have not connected to the database, so the next thing we want to say is to connect the database. If this is not possible, consider executing the./catalina.sh run under Tomcat's Bin path to view the log.

Next say the specific data connection problem:

1. First find the data file inside the war package and download to local (here is my war package, so there is this database file, but your war package may not be OH), the path is:/usr/local/tomcat6/webapps/dangdang_dk/ Web-inf/classes

2. Use the MySQL database tool to connect to the LINUXMYSQL environment, but you will encounter problems with connection failures, as follows:

This needs to involve another problem, we need to open MySQL connection authorization, the specific steps are as follows:

1) in the Xshell into MySQL, the command is: Mysql-u root-p, and then enter into the MySQL.

2) then enter the command: Use MySQL, switch to the MySQL database as follows:, the switch is successful.

3) then enter the following command to query all user tables that can log in to the database: select Host,user,password from User; Be sure to remember that each SQL statement is preceded by a corresponding semicolon. As shown in the following:

Here can be seen only native access to MySQL, if you want to external access to MySQL, then host should be displayed in%, so here we can choose to recreate a user and grant the highest permissions, the statement is as follows:

Grant all privileges on * * to ' root ' @ '% ' identified by ' 220220 ' with GRANT option; This is the password to the root account is set to 220220 and the host is%, that is, any external host can be accessed. * * This is intended to be the database name. Table name, we do not write any table name here or write the database name, meaning that all databases can be accessed with this root account

Flush privileges;//Make the permissions you just modified take effect

Then the next step is to restart the MySQL service and go back to MySQL and use the query to view the user table as follows:

To keep up with the face, is that we added the last root with the password of the user, this time again with the MySQL tool to access

The connection is successful as shown below:

3. Next, we will first create a database named Dangdang, and then we directly copy the Dang.sql file inside the SQL statements directly into the new query, directly run, you can build tables and import data successfully. When the disconnection is reopened, the following data can be seen;

4. At this point we go to the Web page, found that the page is still loading, even if we have added data and set up a database, here is a problem, that is, we built the data is not connected, and then to tell you, how to connect we have created a good database.

1) First find the path where the war package is located: Cd/usr/local/tomcat6/webapps

2) then to find the folder path where the data connection settings are located, locate the path where the Dbcp.properties file is located: cd/dangdang_dk/web-inf/classes

3) Open the Dbcp.properties file with a command to view the contents of the file as follows:

Found three things need to sit change, localhost to fill in the corresponding to our own set up the Linux environment IP address; Dangdang This is the database name, changed to the database name we just above, if the test is changed to test, if it is the same name when the change to when the , corresponding login database username and password, changed to just the root account and password we created above: Username=root passwrod=220220

4) Edit complete, exit Save: esc+: Wq

5) Restart Tomcat

5. Now go to visit our webpage, found that there is already data, indicating that the database configuration is successful and the connection is successful!

Question 1: After rebooting Tomcat, we find that the page still has no data, so we can consider killing the tomcat process and restarting it. Because I also encounter this situation, kill the Tomcat process and then restart, you can see the data, the problem of the pro can follow. The command line is as follows:

Ps-ef|grep Tomcat or Ps-ef|grep Java, see the following:

And then kill the Tomcat process with a command: Kill-9 26257 (by using: kill-9 port number)

Finally reboot Tomcat to see the data!

Issue 2: Every time you restart Tomcat, it is not simple./startup.sh run, we have to kill the process first, and then restart, so that less encounter errors.

Issue 3: When you start Tomcat, be sure to turn on the log at the same time to view it. is to open a new window, run./catalina.sh run, you can see the log, and can quickly locate the error.

Build a Web site and connect to a database in a Linux environment

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.