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?
- NameVirtualHost *: 80
- <VirtualHost *: 80>
- DocumentRoot/var/www/html
- ServerNamewww.qcai360.com
- ErrorLoglogs/www.qcai360.com-error_log
- Customlogs/www.qcai360.com-access_logcommon
- </VirtualHost>
- <VirtualHost *: 80>
- ServerNamem.qcai360.com
- ErrorLoglogs/m.qcai360.com-error_log
- Customlogs/m.qcai360.com-access_logcommon
- <Directory "/var/data/www/m.qcai360.com/">
- DirectoryIndexindex.htmindex.jspindex.html
- </Directory>
- DocumentRoot/var/data/www/m.qcai360.com/
- <IfModulemod_proxy.c>
- ProxyPass/ajp: // 127.0.0.1: 8009/
- ProxyPassReverse/ajp: // 127.0.0.1: 8009/
- </IfModule>
- </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?
- <Connectorport = "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" 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?
- <Hostname = "m.qcai360.com" appBase = "/var/data/www/m.qcai360.com /"
- UnpackWARs = "true" autoDeploy = "true"
- XmlValidation = "false" xmlNamespaceAware = "false">
- <Contextpath = "/" docBase = "/var/data/www/m.qcai360.com/" reloadable = "true" caseSensitive = "false" debug = "0"> </Context>
- </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: