The Centos server supports PHP and JAVA.

Source: Internet
Author: User

The Centos server supports PHP and JAVA.
Recently, due to project requirements, it is necessary to run PHP on the Tomcat server. Obviously, PHP runs on an Apache server. Although Tomcat also belongs to Apache, there is no existing environment, and we need to manually configure it. By the way, the server environment we use is Centos6.4.

I am also the first time to build this environment. I have no experience and I have never integrated my colleagues. So the best way is to find du Niang.

However, I found that the online things are complicated and messy. I promise that you have read ten articles and you cannot build them successfully. The main reason is that there are too many reposted articles, and not all reposted articles are authors or experts. Therefore, it is too confusing to write a text or text.

After many references and repeated experiments, the configuration was successful (applause ). Therefore, I would like to share with you the hope that it will help you avoid detours.

There are at least three ways to integrate Apache and Tomcat. I really don't want to list them one by one. The following is a detailed address. For details, see: (Introduction to three Connection Methods for Apache HTTP Server and Tomcat ).


Here I use the ajp_proxy method, because the configuration is simple. The procedure is as follows.

I am not here to teach you how to install tomcat and Apache, so the specific steps are omitted here.

To start configuration, perform the following steps:

1. determine the path of the JAVA and PHP projects and the corresponding domain name.

Java project path:/var/data/www/m.qcai360.com/
The Java project domain name is m.qcai360.com.
PHP project path:/var/www/html/

The PHP project domain name is www.qcai360.com.

2. Configure the Apache configuration file httpd. conf.

[Root @ localhost ~] # Vi/etc/httpd/conf/httpd. conf
Open and edit the Apache configuration file, find the VirtualHost node, and remove the # comment. The core code is as follows:
[Html] view plaincopyprint?
  1. NameVirtualHost *: 80
  2. <VirtualHost *: 80>
  3. DocumentRoot/var/www/html
  4. ServerNamewww.qcai360.com
  5. ErrorLoglogs/www.qcai360.com-error_log
  6. Customlogs/www.qcai360.com-access_logcommon
  7. </VirtualHost>
  8. <VirtualHost *: 80>
  9. ServerNamem.qcai360.com
  10. ErrorLoglogs/m.qcai360.com-error_log
  11. Customlogs/m.qcai360.com-access_logcommon
  12. <Directory "/var/data/www/m.qcai360.com/">
  13. DirectoryIndexindex.htmindex.jspindex.html
  14. </Directory>
  15. DocumentRoot/var/data/www/m.qcai360.com/
  16. <IfModulemod_proxy.c>
  17. ProxyPass/ajp: // 127.0.0.1: 8009/
  18. ProxyPassReverse/ajp: // 127.0.0.1: 8009/
  19. </IfModule>
  20. </VirtualHost>
NameVirtualHost *:80<VirtualHost *:80>    DocumentRoot /var/www/html    ServerName www.qcai360.com    ErrorLog logs/www.qcai360.com-error_log    CustomLog logs/www.qcai360.com-access_log common</VirtualHost><VirtualHost *:80>    ServerName m.qcai360.com    ErrorLog logs/m.qcai360.com-error_log    CustomLog logs/m.qcai360.com-access_log common    <Directory "/var/data/www/m.qcai360.com/">    DirectoryIndex index.htm index.jsp index.html   </Directory>DocumentRoot /var/data/www/m.qcai360.com/<IfModule mod_proxy.c>ProxyPass /  ajp://127.0.0.1:8009/ProxyPassReverse / ajp://127.0.0.1:8009/</IfModule></VirtualHost>

3. Configure the Tomcat configuration file server. xml
[Root @ localhost ~] # Vi/usr/share/tomcat6/conf/server. xml

Open and edit the Tomcat configuration file. I will display the configuration of several core nodes, and there is almost no need to change the configuration of other nodes.

Connector node:

[Html] view plaincopyprint?
  1. <Connectorport = "8888" protocol = "HTTP/1.1"
  2. URIEncoding = "UTF-8"
  3. MinSpareThreads = "25"
  4. MaxSpareThreads = "75"
  5. EnableLookups = "false"
  6. DisableUploadTimeout = "true"
  7. ConnectionTimeout = "20000"
  8. AcceptCount = "300"
  9. MaxThreads = "300"
  10. MaxProcessors = "1000"
  11. MinProcessors = "5"
  12. UseURIValidationHack = "false"
  13. Compression = "on"
  14. CompressionMinSize = "2048"
  15. CompressableMimeType = "text/html, text/xml, text/javascript, text/css, text/plain"
  16. RedirectPort = "8443" type = "regxph" text = "yourobjectname"/>
<Connector port="8888" protocol="HTTP/1.1"          URIEncoding="UTF-8"    minSpareThreads="25"   maxSpareThreads="75"      enableLookups="false"   disableUploadTimeout="true"   connectionTimeout="20000"      acceptCount="300"    maxThreads="300"   maxProcessors="1000"   minProcessors="5"      useURIValidationHack="false"                                           compression="on"   compressionMinSize="2048"                       compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"  redirectPort="8443"/>
Host node:
[Html] view plaincopyprint?
  1. <Hostname = "m.qcai360.com" appBase = "/var/data/www/m.qcai360.com /"
  2. UnpackWARs = "true" autoDeploy = "true"
  3. XmlValidation = "false" xmlNamespaceAware = "false">
  4. <Contextpath = "/" docBase = "/var/data/www/m.qcai360.com/" reloadable = "true" caseSensitive = "false" debug = "0"> </Context>
  5. </Host>
<Host name="m.qcai360.com" appBase="/var/data/www/m.qcai360.com/"unpackWARs="true" autoDeploy="true"xmlValidation="false" xmlNamespaceAware="false"><Context path="/" docBase="/var/data/www/m.qcai360.com/" reloadable="true" caseSensitive="false" debug="0"></Context></Host>


4. Run the test
Enter: http://www.qcai360.com/
The running effect is as follows:

Enter: http://m.qcai360.com in the browser

The running effect is as follows:

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.