Linux Apache PHP Compilation configuration

Source: Internet
Author: User
Tags apache php php source code

1. Download the Apache Web server source code and related dependent libraries

Enter http://www.apache.org, select a server to download the relevant source code. Please note: Apache is actually a foundation name, there are many open source projects, Apache Web server is just one of the Apache Foundation project, so many friends on the Apache home page, it is difficult to find Apache Web server download Place, Apache Web Server has a name of httpd-xxx (XXX version) in its source library. The basic steps are: Home Click Download, enter the download page, select a server, the general choice of domestic server can (. cn domain name or labeled as a server in China), here we choose:http://mirrors.hust.edu.cn/ apache/, enter the server, click the httpd directory, select a stable version of the latest download (such as: http://mirrors.hust.edu.cn/apache/httpd/ HTTPD-2.4.10.TAR.BZ2); After downloading the Web server source code, return to the parent directory (ie:http://mirrors.hust.edu.cn/apache/), Download httpd dependent library Apr (Apr seems to be the abbreviation for Apache Portalble runtime, which is Apache's portable runtime, many open source software is built on this library, such as PHP, which provides some cross-platform system functions, such as memory management, etc.), Click the Apr folder to 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).

Apache, in addition to relying on Apr and apr-util, but also rely on the Pcre library, this library is a cross-platform regular expression processing library, the official URL is http://www.pcre.org/, enter the homepage, select a server, download a latest version of the source code can (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 Pcre Library, compile simple, classic configure, make, do install, here we specify its installation directory as/opt/pcre, and compile 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(may require root privileges)

The following compiles Apache, where we specify the installation directory as/opt/apache:

Unzip the relevant 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 latter two command function is to extract APR and Apr-util source code httpd-2.4.10/srclib directory.

After the decompression is complete, go to the Httpd-2.4.10/srclib directory, rename the apr-1.5.1 directory to Apr, rename apr-util-1.5.4 to Apr-util (Execute command mv Srclib Apr under apr-1.5.1) and mv apr-util-1.5.4 apr-util ).

Here the APR and Apr-util source extracted in the Srclib and renamed mainly to the Apache compiler configuration options --with-included-apr Specify the location of APR, so as to avoid installing the two libraries separately.

httpd-2.4.10 Directory Execution:

./configure--prefix=/opt/apache--with-pcre=/opt/pcre--with-included-apr--enable-so
Make
Make install(may require root privileges)

After the installation is complete, the Apache server is started; Apache Basic operations (note that the following operations require root privileges):

/opt/apache/bin/apachectrl start(start)
/opt/apache/bin/apachectrl Restart(restart)
/opt/apache/bin/apachectrl Stop(stop)

If you do not configure the server name, at startup, there will be a warning message, open apache/conf/httpd.conf, set:

ServerName localhost

Can. After you start Apache, use your browser to enter 127.0.0.1 if it appears

It works!

Indicates that Apache has successfully started.

3, PHP source code and dependent library download

PHP relies on the LIBXML2 library, LIBXML2 official address is: http://www.xmlsoft.org/, go to the download page (ftp://xmlsoft.org/libxml2/), download the latest version of LIBXML2, Here we choose (ftp://xmlsoft.org/libxml2/libxml2-sources-2.9.0.tar.gz);

PHP official address for http://www.php.net/, go to download page http://www.php.net/downloads.php, download the latest stable version of the source code, here we choose (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, and the Pcre library, as well as the static 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(may require root privileges)

Compile PHP below:

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

where option --with-apxs2 is specifying the Apache APXS tool location, specifying this option will automatically search for the APR configuration when PHP is configured, and when installing PHP, Libphp5.so will be installed in the Apache Dynamic Module directory, and automatically modify the Apache configuration loading libphp5.so, etc.--with-config-file-path is the search directory for the specified PHP configuration file php.ini.

Make
Make install

After the installation is complete, copy the Php-5.4.36/php.ini-production to/opt/php/php.ini (Run command CP Php.ini-production/opt/php/php.ini ), After the copy is complete, open the Apache configuration file apache/conf/httpd.conf and add the following between <ifmodule mime_module></ifmodule> Otherwise Apache cannot parse PHP files:

AddType application/x-httpd-php. php

Search for index.html, add index.php after

After the configuration is complete, restart Apache (Run command:/opt/apache/bin/apachectrl Restart < requires root privileges >).

5. Simple Test

Create the index.php file under/opt/apache/htdocs/and enter the PHP Classic test content:

<?php
Phpinfo ();
?>

Open Browser, enter 127.0.0.1/index.php

Linux Apache PHP Compilation configuration

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.