Complete installation and configuration instructions for php to call java-php Tutorial

Source: Internet
Author: User
Complete installation and configuration instructions for php to call java 1. installation and configuration of Windows 1.1. installation and configuration of Apache and php

Apache and php can be decompressed, installed, and installed.

The following uses the decompressed version as an example:

1. you do not need to install the decompressed version. unzip the version and put it in any directory.

2. configure apache's support for php. for the configuration process, see Network.

3. the software versions used in the demo test are apache2.2.6, php5.3.5, and javabridge5.4.4. the software versions can be selected by yourself, but must be compatible with each other.

1.2. Javabridge configuration

1. after confirming that the php and apache environments are configured, configure javabridge so that php supports java calls.

Put the jar package of JavaBridge and the corresponding java directory in any directory.

2. introduce the java directory in the php project. inc (including Java. inc and JavaProxy. php), such as: require_once (".. /java/Java. inc ");

Pay attention to the introduced path, that is, the ../java/Java. inc section. refer to the demo's secUtil. php page introduction method.

3. Place the jar package called by php to ext under the lib of the jre used by the system, for example, C: \ Java \ jdk1.6.0 _ 20 \ jre \ lib \ ext

4. start JavaBridge.

There are three methods to start Javabridge:

(1) double-click to start the jar package.

(2) run the start java-jar JavaBridge. jar SERVLET_LOCAL: 8080 command in the cmd command (in the ext directory)

(3) you can use batch processing to run the second method (batch processing is in the same directory as the jar package)

1.3. run phpDemo

1. verify that javabridge is normal. you can call java api for testing, such as test. php.

Require_once ("java/Java. inc ");

Header ("content-type: text/html; charset = utf-8 ");

// Get instance of Java class java. lang. System in PHP

$ System = new Java ('Java. lang. system ');

$ S = new Java ("java. lang. String", "php-java-bridge config...

");

Echo $ s;

// Demonstrate property access

Print 'Java version = '. $ system-> getProperty ('Java. version ').'
';

Print 'Java vendor = '. $ system-> getProperty ('Java. upload ').'
';

Print 'OS ='. $ system-> getProperty ('OS. name ').''.

$ System-> getProperty ('OS. version'). 'on '.

$ System-> getProperty ('OS. arch ').'
';

// Java. util. Date example

$ Formatter = new Java ('Java. text. simpledateformat ',

"EEEE, MMMM dd, yyyy 'at' h: mm: ss a zzzz ");

Print $ formatter-> format (new Java ('Java. util. date '));

?>

Note: modify the import path.

2. if javabridge is used, start apache and javabridge. access index. php of phpDemo.

Note:

1. if the access error NOTICE is used to modify the php. ini configuration file, error_reporting = E_ALL &~ E_NOTICE

2. ensure that the JavaBridge and Java. inc versions are consistent.

3. if any errors occur during java calling, the javabridge window and Page are displayed. for example, the called method name does not exist.


2. Linux installation and configuration process 2.1. Apache installation 2.1.1. installation version

Httpd-2.2.29.tar.gz

2.1.2. installation steps

Tar? Zxvf httpd-2.2.29.tar.gz

./Configure

Make

Make install

2.1.3. start apache

After successful installation, start apache:/usr/local/apache2/bin/apachectl start

Check whether the startup is successful: after executing ps-ef | grep httpd, the startup is successful as follows.

2.1.4. Apache FAQ

Note:

1. the following prompt appears when./configure is installed (if the gcc compiler is not installed ):

Configure: error: in '/usr/local/tongSoftware/httpd-2.2.29/srclib/APR ':

Configure: error: no acceptable C compiler found in $ PATHSee 'config. log' for more detailsconfigure failed for srclib/apr

If the system prompts that the gcc compiler is not installed, install the compiler: yum-y install gcc.

2. make and make install are successfully installed as follows:

......

Mkdir/usr/local/apache2/man

Mkdir/usr/local/apache2/man/man1

Mkdir/usr/local/apache2/man/man8

Mkdir/usr/local/apache2/manual

Make [1]: Leaving directory '/root/aphp/httpd-2.2.29'

[Root @ device httpd-2.2.29] #

Find the installation path and start apache.

3rd, if the app is installed with a high level or other versions, such as httpd-2.4.12.tar.gz, the following error message will appear during compilation:

........

Checking for APR... no

Configure: error: APR not found. Please read the documentation.

The installation solution is as follows:

The solution is as follows:

#./Configure -- prefix ...... When checking the editing environment:

Checking for APR... no

Configure: error: APR not found. Please read the documentation.

Can I use./configure? Help | grep apr view help.

-- With-permission Ded-apr Use bundled copies of APR/APR-Util

-- With-apr = PATH prefix for installed APR or the full path to apr-config

-- With-apr-util = PATH prefix for installed APU or the full path

Install APR (Apache Portable Runtime)

[Root @ localhost ~] # Cd/tmp/52 lamp // source code storage location

[Root @ localhost 52 lamp] # tar-zxvf apr-1.4.2.tar.gz // unzip-o apr-1.4.2.zip

[Root @ localhost 52 lamp] # cd apr-1.4.2

[Root @ localhost apr-1.4.2] #./configure

[Root @ localhost apr-1.4.2] # make

[Root @ localhost apr-1.4.2] # make install

Check the compilation environment again

Checking for APR-util... no

Configure: error: APR-util not found. Please read the documentation.

[Root @ localhost httpd-2.2.16] #./configure? Help | grep apr-util

-- With-apr-util = PATH prefix for installed APU or the full path

[Root @ localhost 52 lamp] # tar-zxvf apr-util-1.3.9.tar.gz

[Root @ localhost 52 lamp] # cd apr-util-1.3.9

[Root @ localhost apr-util-1.3.9] #./configure -- prefix =/usr/local/apr-util -- with-apr =/usr/local/apr

[Root @ localhost apr-util-1.3.9] # make

[Root @ localhost apr-util-1.3.9] # make install

./Configure still prompts APR-util not found. add -- with-apr =/usr/local/apr -- with-apr-util =/usr/local/apr-util.

Configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

[Root @ localhost httpd-2.2.16] #./configure? Help | grep pcre

-- With-pcre = PATH Use external PCRE library

[Root @ localhost 52 lamp] # unzip-o pcre-8.10.zip

[Root @ localhost 52 lamp] # cd pcre-8.10

[Root @ localhost cd pcre-8.10] #./configure -- prefix =/usr/local/pcre

[Root @ localhost cd pcre-8.10] # make

[Root @ localhost cd pcre-8.10] # make install

Continue to install Apache/httpd ,. add the parameter -- with-apr =/usr/local/apr/-- with-apr-util =/usr/local/apr-util/-- with-pcre =/usr /local/pcre, this problem is solved.

Note: Installation of httpd-2.4.12.tar.gz this process is not a close test.

2.2. install php 2.2.1.

Php-5.4.40.tar.gz

2.2.2. installation steps

Tar? Zxvf php-5.4.40.tar.gz

. /Configure -- prefix =/usr/local/php/-- with-apxs2 =/usr/local/apache2/bin/apxs (note that the apache module must be compiled here, and -- with-apxs2 =/usr/local/apache2/bin/apxs)

Make

Make install

2.2.3. Php FAQ

Note:

1. if libxml2-python and libxml2-devel packages are not installed, the following error occurs during compilation:

Configure: error: xml2-config not found. Please check your libxml2 installation

J solution: install the libxml2-python and libxml2-devel package: yum-y install libxml2-python libxml2-devel

2. the following error occurs during make.

1. Perl is not installed

2. apxs was not found. Try to pass the path using -- with-apxs2 =/path/to/apxs

3. Apache was not built using -- enable-so (the apxs usage page is displayed)

The output of/usr/local/apache/bin/apxs follows:./configure: line 6669:/usr/local/apache/bin/apxs: Permission denied

Solution: 1. install the perl package first; 2. add the executable permission to the apxs permission;

2.2.4. configure php

Create a configuration file to the specified configuration file directory

# Cp php. ini-dist/usr/local/php/lib/php. ini

2.2.5. Add Apache support for PHP

[Root @ localhost php-5.4.40] # vi/usr/local/php/lib/php. ini

Find AddType application/x-gzip. gz. tgz and add a line below

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

Restart apache.

Write the index. php file to test whether the support is normal.

Phpinfo ();

?>

2.3. install and configure javabridge 2.3.1. configure javabridge without installation

1. place javabridge. jar in any location, usually in the php folder, such as/usr/local/php/etc.

2. the javabridge. place the java folder supporting ja r in any location of the file, usually in the php folder, such as/usr/local/php/etc, and pay attention to the referenced path.

For example: require_once ("/usr/local/php/etc/java/Java. inc ");

3. place the required jar package under jre (/usr/java/jdk1.6.0 _ 20/jre/lib/ext), and then reference the project

// Linux

Java_require ('/usr/java/jdk1.6.0 _ 20/jre/lib/ext/SVSClient. jar ');

Java_require ('/usr/java/jdk1.6.0 _ 20/jre/lib/ext/BJCA_LOG.jar ');

4. start javabridge

Java-jar JavaBridge. jar SERVLET_LOCAL: 8080 this command cannot close the window during startup and does not run in the background.

Java-jar JavaBridge. jar SERVLET_LOCAL: 8080 & this command can close the window and run in the background at startup (sometimes ctrl + c is required to interrupt the window before closing the window)

5. check whether the instance is successfully started. ps-ef | grep 8080:

6. verify that javabridge is normal. you can call java api for testing, such as test. php.

Require_once ("java/Java. inc ");

Header ("content-type: text/html; charset = utf-8 ");

// Get instance of Java class java. lang. System in PHP

$ System = new Java ('Java. lang. system ');

$ S = new Java ("java. lang. String", "php-java-bridge config...

");

Echo $ s;

// Demonstrate property access

Print 'Java version = '. $ system-> getProperty ('Java. version ').'
';

Print 'Java vendor = '. $ system-> getProperty ('Java. upload ').'
';

Print 'OS ='. $ system-> getProperty ('OS. name ').''.

$ System-> getProperty ('OS. version'). 'on '.

$ System-> getProperty ('OS. arch ').'
';

// Java. util. Date example

$ Formatter = new Java ('Java. text. simpledateformat ',

"EEEE, MMMM dd, yyyy 'at' h: mm: ss a zzzz ");

Print $ formatter-> format (new Java ('Java. util. date '));

?>

Note: modify the import path.

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.