Install php5.5 on Apache 2.x in Linux and UNIX

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

Web: http://www.php.net/manual/zh/install.unix.apache2.php

This section describes instructions and tips for installing PHP under Apache 2.x on the UNIX platform.

Warning

We do not recommend that you use threaded MPM in Apache 2 products. Pre-branch mpm, Apache 2.0 and 2.2 default MPM should be used. The reason is that related entries in the FAQ use The apache2 thread-based MPM.

Recommended reading
» Apache documentation: Learn about the Apache 2.x server and detailed installation parameters.

You can download the latest version of Apache from the Apache download site, and select the appropriate version of PHP to download. This wizard only contains the most basic content and can only make Apache 2.x and PHP work normally. For more information, see the Apache documentation. All version numbers are omitted here to ensure the correctness of this article. Replace the "Nn" in this article with the corresponding version number.

Currently, Apache 2.x has two popular versions-2.0 and 2.2. Although there are various reasons to select a version, we recommend that you use the latest Apache 2.2 version if you can consider it. Of course, the following introduction is also applicable to Apache 2.0 and 2.2.

  1. Obtain the Apache source code package from the list above and decompress the package:

    gzip -d httpd-2_x_NN.tar.gztar -xf httpd-2_x_NN.tar
  2. Similarly, obtain and decompress the PHP source code package:

    gunzip php-NN.tar.gztar -xf php-NN.tar
  3. Compile and install Apache. For more details about how to compile Apache, see the Apache installation documentation.

    cd httpd-2_x_NN./configure --enable-somakemake install
  4. You have installed Apache 2.x. nn in/usr/local/apache2. This installation supports the loadable module and standard MPM prefork. Then, run the following command to start the Apache server:

    /usr/local/apache2/bin/apachectl start

    If the installation succeeds, you can stop the Apache server and continue to install PHP:

    /usr/local/apache2/bin/apachectl stop
  5. Now you need to configure and compile PHP. Various parameters can be used to customize PHP, for example, which extended feature packages are supported. You can use the./configure -- Help Command to list all currently available parameters. In this example, an example of configuration on Apache 2 supported by MySQL is provided.

    If Apache is compiled from the source code according to the above instructions, the following example will match the apxs path correctly. If Apache is installed in other ways, you need to adjust the apxs path accordingly. Note: In some release versions, you may change apxs to apxs2.

    cd ../php-NN./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqlmakemake install

    If you decide to change the configuration option after installation, repeat the last three steps configure, make, and make install, and then restart Apache to make the new module take effect. Apache does not need to be re-compiled.

    Note that, unless explicitly indicated, the "make install" command will install pear, various PHP tools such as phpize and php cli.

  6. Configure PHP. ini

    cp php.ini-development /usr/local/lib/php.ini

    You can edit PHP. ini to set the PHP runtime options. To place the file in another location, add the -- with-config-file-Path =/path option in step 5.

    If you select PHP. ini-production, be sure to read the change list, which affects PHP Execution.

  7. Edit the httpd. conf file to call the PHP module. The path to the right of the loadmodule expression must point to the PHP module in the system. The above make install command may have completed these, but it is necessary to check.

    LoadModule php5_module modules/libphp5.so
  8. Tell Apache to parse a specific extension into PHP. For example, ask Apache to parse the extension. php into PHP. In order to avoid potential danger, the example uploads and creates a file named exploit.php.jpg and runs it as PHP. We will not use the Apache addtype command to set it. For the following example, you can simply interpret the required extension as PHP. We will demonstrate how to add. php.

    <FilesMatch \.php$>    SetHandler application/x-httpd-php</FilesMatch>

    Or, you want. PHP ,. phP2 ,. php3 ,. phP4 ,. phP5 ,. phP6, and. all phtml files are run as PHP files. We don't need to set them any more. We just need to follow the following steps:

    <FilesMatch "\.ph(p[2-6]?|tml)$">    SetHandler application/x-httpd-php</FilesMatch>

    Then, the. PHPs file can be processed by the PHP source code filter so that it can highlight the source code During display. The settings are as follows:

    <FilesMatch "\.phps$">    SetHandler application/x-httpd-php-source</FilesMatch>

    Mod_rewrite also helps to highlight the source code of. php files that do not need to be run without renaming them to. PHPs files:

    RewriteEngine OnRewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]

    Do not start the PHP source code filter on a system that is officially produced and operated, as this may expose sensitive information in system secrets or embedded code.

  9. Start the apache service as follows:

    /usr/local/apache2/bin/apachectl start

    Or

    service httpd restart

Follow the steps above to make Apache 2.x Use PHPSAPIModule. Of course, Apache and PHP have many configuration options, which can be used in the corresponding source code directory../Configure -- HelpFor more information.

If you want to compile a multi-threaded version of Apache, you can choose to useWorkerMPM to replace the standardPreforkMPM. You only need to use the following code in Step 1:

-- With-MPM = worker

If you do not have a clear understanding of the consequences of doing so, it is best not to proceed with this step. For more information, see
» MPM-modules section.

Note:

The use of Multiviews in PHP is discussed in the Apache Multiviews FAQ.

Note:

To compile a multi-threaded version of Apache, the system must support multiple threads. This also means that PHP needs to be compiled into Zend thread safety (ZTS) in the test phase, so not all extensions can be used. It is recommended to compile Apache to use standardPreforkMPM-module.

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.