Linux Apache PHP compilation configuration, linuxapache
1. Download the Apache Web Server Source Code and related dependent Libraries
Go to the http://www.apache.org and select a server to download the relevant source code. Note: apache is actually the name of a foundation, which has many open-source projects. apache web server is only one of the projects of the apache Foundation. Therefore, many friends visit the apache homepage, it is difficult to find the place where apache web server is downloaded. In its source code library, apache web server is called httpd-xxx (version xxx is used ). The basic steps are as follows: Click download on the homepage to go To the download page. Select a server. Generally, select a domestic server (. cn domain name or a server marked as China). Here we choose:Http://mirrors.hust.edu.cn/apache/, Enter the server, click httpd directory, select a latest stable version to download (such as: http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.10.tar.bz2); download the web server Source Code, return to the parent directory (namely:Http://mirrors.hust.edu.cn/apache/), Download the httpd dependent database apr (apr seems to be short for apache portalble runtime, that is, apache's Portable runtime Library. Many open source software are built on this library, such as PHP, this library provides some cross-platform system functions, such as memory management, etc.), click the apr folder, download apr and apr-uitl source code (such as: http://mirrors.hust.edu.cn/apache/apr/apr-1.5.1.tar.bz2,http://mirrors.hust.edu.cn/apache/apr/apr-util-1.5.4.tar.bz2 ).
In addition to apr and apr-util, apache depends on the pcre Library, which is a cross-platform Regular Expression Processing library. The official website is http://www.pcre.org/. after entering the main page, select a server and download the latest source code (such as ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.bz2 ).
2. Apache Web Server Compilation
Compile and install the pcre Library. The compilation is relatively simple. For the classic configure, make, and make install, here we specify its installation directory as/opt/pcre and compile it as a static Library:
Tar-jxvf pcre-8.36.tar.bz2
Cd pcre-8.36
./Configure -- prefix =/opt/pcre -- disable-shared -- enable-static
Make
Make install (root permission may be required)
Compile apache below. Here we specify the installation directory as/opt/apache:
Decompress the source code:
Tar-jxvf httpd-2.4.10.tar.bz2
Tar-jxvf apr-1.5.1.tar.bz2-C httpd-2.4.10/srclib
Tar-jxvf apr-util-1.5.4.tar.bz2-C httpd-2.4.10/srclib
The last two command functions are to extract the apr and apr-util source code under the httpd-2.4.10/srclib directory.
After decompression, go to the httpd-2.4.10/srclib directory, rename the apr-1.5.1 directory to apr, rename the apr-util-1.5.4 to apr-util (execute the command mv apr-1.5.1 apr and mv apr-util-1.5.4 apr-util under srclib ).
Here, we extract the apr and apr-util source code in srclib and rename it mainly through the apache compilation configuration option -- with-embedded ded-apr to specify the location of the apr, to avoid separate installation of these two libraries.
Execute under the httpd-2.4.10 directory:
./Configure -- prefix =/opt/apache -- with-pcre =/opt/pcre -- with-defined ded-apr -- enable-so
Make
Make install (root permission may be required)
After the installation is complete, start the apache server. The basic operations of apache (note that the following operations require the root permission ):
/Opt/apache/bin/apachectrl start (start)
/Opt/apache/bin/apachectrl restart (restart)
/Opt/apache/bin/apachectrl stop (stop)
If the server name is not configured, a warning will be generated at startup. Open apache/conf/httpd. conf and set:
ServerName localhost
You can. After apache is started, enter 127.0.0.1 in the browser.
It works!
Indicates that apache has been started successfully.
3. Download PHP source code and dependent Libraries
Php depends on libxml2 library, libxml2 official address: http://www.xmlsoft.org/, enter the download page (ftp://xmlsoft.org/libxml2/), download the latest version of libxml2 can be, here we choose (ftp://xmlsoft.org/libxml2/libxml2-sources-2.9.0.tar.gz );
PHP official address is login (http://cn2.php.net/distributions/php-5.4.36.tar.bz2 );
4. PHP Compilation
Compile libxml2. Here we specify the installation directory as/opt/libxml2, which is also compiled as a static library like the pcre Library:
Tar-jxvf libxml2-sources-2.9.0.tar.gz
Cd libxml2-2.9.0
./Configure -- prefix =/opt/libxml2 -- enable-static -- disable-shared
Make
Make install (root permission may be required)
Compile PHP as follows:
Tar-jxvf php-5.4.36.tar.bz2
Cd php-5.4.36
. /Configure -- prefix =/opt/php/-- with-apxs2 =/opt/apache/bin/apxs -- with-pcre-dir =/opt/pcre/-- with-libxml-dir = /opt/libxml2 -- with-config-file-path =/opt/php
The option -- with-apxs2 specifies the location of the apache apxs tool, which is automatically searched for related configurations of apr when php is configured, and when php is installed, libphp5.so will be installed in the apache dynamic module directory, and automatically modify apache configuration to load libphp5.so; -- with-config-file-path is the PHP configuration file specified by php. ini search directory.
Make
Make install
After the installation is complete, the php-5.4.36/php. ini-production copy to/opt/php. ini (run the command cp php. ini-production/opt/php. ini). After copying, open the apache configuration file apache/conf/httpd. conf: Add the following content between <IfModule mime_module> </IfModule>; otherwise, apache cannot parse the PHP file:
AddType application/x-httpd-php. php
Search for index.html and add index. php
After the configuration is complete, restart apache (run the command:/opt/apache/bin/apachectrl restart to <root permission required> ).
5. Simple Test
Create the index. php file under/opt/apache/htdocs/and enter the php classic test content:
<? Php
Phpinfo ();
?>
Open your browser and enter 127.0.0.1/index. php