PHP installation, configuration and expansion summary, php configuration expansion Summary

Source: Internet
Author: User
Tags mcrypt php cli php software sapi zts nginx server

PHP installation, configuration and expansion summary, php configuration expansion Summary

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

PHP installation, configuration, and expansion summary:

This article mainly summarizes the installation, configuration, and addition and verification of the extended library of PHP. The implementation platform is Unix, Linux, and Mac OS X. It also includes future technical articles, only the PHP language is used as the server script and command script, which does not involve the processing of desktop applications.

 

· How to install

· How to configure

· How to expand

· How to verify

· Problems Encountered

. Additional content

 

I. How to install

1. Download the installation package

: The http://php.net/downloads.php downloads the latest PHP software installation package locally.

 

2. Unzip the installation package

$ Tar-xvf php-5.6.20.tar

 

3. Configure and install

$ Php-5.6.20 cd

$./Configure -- enable-fpm -- with-mysql // enable php-fpm and mysql support

$ Make

$ Make install

 

4. Create a configuration file

$ Php-5.6.20 cd

$ Cp php. ini-development/usr/local/php. ini

$ Cp/usr/local/etc/php-fpm.conf.default/usr/local/etc/php-fpm.conf

$ Cp sapi/fpm/php-fpm/usr/local/bin

 

NOTE:

Create a configuration file and copy it to the correct location.

 

Ii. how to configure

1. php. ini configuration

For most PHP configurations, you only need to configure the php. ini configuration file. Here, we basically keep the default configuration in php. ini, and will continue to describe and optimize the configuration of this file in the future. If the file does not exist, in order to prevent malicious script injection attacks, you need to prevent Nginx server requests from being sent to php-fpm. Therefore, you need to describe and modify the content in php. ini as follows:

Cgi. fix_pathinfo = 0

 

2. Configuration involved

 

Php-fpm Configuration:

Refer:

Http://www.cnblogs.com/quanzhiguo/p/7520576.html

 

Nginx Configuration:

Refer:

Http://www.cnblogs.com/quanzhiguo/p/7520620.html

 

Mysql Configuration:

Refer:

Http://www.cnblogs.com/quanzhiguo/p/7520658.html

 

Iii. How to expand

In PHP development, many common functions provide expansion support in the form of third-party libraries. Therefore, you need to add extension library support for php. Currently, three extension methods are supported. For details, refer to official instructions:

Http://php.net/manual/zh/install.pecl.pear.php

 

Here, I prefer to use the PHPIZE underlying compilation, installation, and expansion support to generate dynamic. so library file storage path:/usr/local/lib/php/extensions/no-debug-non-zts-20131226, specific as follows:

PS: After modifying the php. ini configuration, remember to restart fpm. Otherwise, the modification will not take effect.

 

1. Xcache

$ Tar-xvf xcache-3.2.0.tar

$ Xcache-3.2.0 cd

$ Sudo phpize

$ Sudo./configure -- enable-xcache-coverager

-- Enable-opcache -- enable-xcache-optimizer

$ Sudo make

$ Sudo make install

 

NOTE:

-- Enable-xcache: supports xcache;

-- Enable-xcache-coverager: additional features that contain the metrics of the measurement accelerator;

-- Enable-xcache-optimizer: including support for operating code optimization;

 

Configuration:

Php. ini:

[Xcache-common]

Extension =/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xcache. so

 

[Xcache. admin]

Xcache. admin. enable_auth = On

Xcache. admin. user = "admin"

Xcache. admin. pass = ""

 

[Xcache]

Xcache. shm_scheme = "mmap"

Xcache. size = 1024 M

Xcache. count = 16

Xcache. slots = 8 K

Xcache. ttl = 0

Xcache. gc_interval = 0

Xcache. var_size = 16 M

Xcache. var_count = 1

Xcache. var_slots = 8 K

Xcache. var_ttl = 0

Xcache. var_maxttl = 0

Xcache. var_gc_interval = 300

Xcache. test = Off

Xcache. readonly_protection = On

; Xcache. mmap_path = "/dev/zero"

Xcache. mmap_path = "/tmp/xcache"

Xcache. coredump_directory = ""

Xcache. cacher = On

Xcache. stat = On

Xcache. optimizer = Off

 

[Xcache. coverager]

Xcache. coverager = On

Xcache. coveragedump_directory = ""

 

[Opcache]

; So address

Zend_extension =/usr/local/lib/php/extensions/no-debug-non-zts-20131226/opcache. so

; Switch on

Opcache. enable = 1

; Enable CLI

Opcache. enable_cli = 1

; Available memory, depending on the unit: Mb

Opcache. memory_consumption = 128

; Zend Optimizer + total memory occupied by strings in the temporary storage pool (unit: MB)

Opcache. interned_strings_buffer = 8

Multi-cache file limit. If the hit rate is less than 100%, you can try to increase this value.

Opcache. max_accelerated_files = 4000

; Opcache will check the file modification time within a certain period of time. Here, the check time period is set. The default value is 2, and the position is second.

Opcache. revalidate_freq = 60

; Enable quick close. Enabling this will increase the memory reclaim speed when the PHP Request Shutdown is enabled.

Opcache. fast_shutdown = 1

 

NOTE:

After a lot of optimization processing and ensuring that the program itself is no problem, it is only because there are too many operations to be optimized. In this case, you can consider using PHP accelerators such as xache and apc to reduce the performance consumption of cpu resolution PHP files.

 

2. Xdebug

$ Tar-xvf xdebug-2.4.0.tar

$ Cd debug-2.4.0

$ Phpize

$ Sudo./configure-prefix =/usr/local/xdebug

$ Sudo make

$ Sudo make install

 

Configuration:

Php. ini:

[Xdebug]

Xdebug. auto_trace = off

Xdebug. auto_profile = off

Xdebug. collect_params = on

Xdebug. collect_return = on

Xdebug. profiler_enable = on

Xdebug. remote_enable = off

Xdebug. trace_output_dir = "/tmp"

Xdebug. profiler_output_dir = "/tmp"

 

Zend_extension =/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug. so

 

NOTE:

How to monitor and debug PHP programs? Xdebug extended library support is used here.

 

3. Mcrypt

$ Tar libmcrypt-2.5.8.tar.gz

$ Libmcrypt-2.5.8 cd

$ Sudo./configure-disable-posix-threads-enable-static

$ Sudo make

$ Sudo make install

$ Cd php-5.6.20/ext/mycrypt

$ Sudo phpize

$ Sudo./configure

$ Sudo make

$ Sudo make install

 

Configuration:

Php. ini:

Extension =/usr/local/lib/php/extensions/no-debug-non-zts-20131226/mcrypt. so

 

4. How to verify

1. Verify PHP

Php-v

 

2. Verify PHP Expansion

There are two methods to verify PHP extension:

Phpinfo () and php-m. phpinfo () is used as an example for verification.

 

Xcache:

 

Xdebug:

 

Mcrypt:

 

5. Problems Encountered

1. PHP extension has been installed successfully, php. ini configuration has been added, and fpm has been restarted. However, php-m or phpinfo () is not displayed at all.

Solution:

<? Phpinfo ()?> View the Configuration File (php. ini) Path, which is the Path for storing the currently active php. ini File. The problem is probably that the php. ini Path you configured is incorrect.

 

2. PHP extension xcache has been installed and configured, and fpm has been restarted, but php-m or phpinfo () is never displayed.

Solution:

Modify zend_extension = xxx to extension = xxx because xcache does not support loading xcache with zend_extension after 3.0. so, instead, it uses extension to load, that is, it only treats xcache as an extended library, and zend_extension = xxx/opcache is used for PHP acceleration. so.

 

 

NOTE:

For the above PHP expansion, we will summarize the introduction and usage instructions in the following summary article.

 

 

6. Additional content

We can use php-config to view the current PHP installation and configuration information:

$ Php-config -- help

 

Option description (from the official website ):

Option

Description

-- Prefix

PHP installation path prefix, such as/usr/local

-- Regiondes

List all files included with the-I Option

-- Ldflags

LD flag used during PHP Compilation

-- Libs

Library appended during PHP Compilation

-- Extension-dir

Default extension LIBRARY PATH

-- Include-dir

Default path prefix of the header file

-- Php-binary

Full path of php cli or CGI executable files

-- Php-sapis

List all available SAPI modules

-- Configure-options

Reproduce the current PHP configuration options during compilation

-- Version

PHP version

-- Vernum

PHP version number, expressed as an integer

 

In addition, sometimes we need to know whether the installed extension requires installation dependencies or startup support. You can use the following command to query:

$./Configure -- help | grep extname (Extended name)

 

 

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.