PHP installation, configuration and extension summary

Source: Internet
Author: User
Tags php language php cli php download php software phpinfo sapi zts nginx server

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

PHP installation, configuration and extension summary:

This article mainly summarizes the PHP installation, configuration, expansion of the library to add and verify, the implementation platform for Unix/linux/mac OS X, which also includes future technical articles, only the PHP language as a server-side script and the use of command script to summarize, which does not involve the processing of desktop applications.

· How to Install

· How to configure

· How to expand

· How to verify

· Encounter problems

. Additional content

First, how to install

1. Download the installation package

: http://php.net/downloads.php Download the latest PHP software installation package to Local.

2. Unpack the installation package

$ TAR–XVF Php-5.6.20.tar

3. Configure and install

$ CD php-5.6.20

$./configure--ENABLE-FPM--with-mysql//Turn on PHP-FPM and MySQL support

$ make

$ make Install

4. Create a configuration file

$ CD php-5.6.20

$ CP Php.ini-development/usr/local/php/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 the configuration file and copy it to the correct location to take effect oh.

Second, how to configure

1. PHP.ini Configuration

For the configuration section of PHP, most of us only need to configure the php.ini configuration file. Here we basically maintain the default configuration in php.ini, we will continue to configure and optimize this file. If the file does not exist, in order to prevent malicious script injection attack problem, need to prevent the Nginx server request sent to PHP-FPM, so you need to php.ini in the comments and modify the following:

Cgi.fix_pathinfo=0

2, the configuration involved

PHP-FPM configuration:

Reference:

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

Nginx Configuration:

Reference:

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

MySQL configuration:

Reference:

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

Third, how to expand

In PHP development, a lot of commonly used functions are in the form of third-party libraries to provide extension support, so need to add extension library support for PHP, currently supports three ways to add extension, can refer to the official note:

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

And here, I prefer to use the phpize low-level compiler installation extension support, generated dynamic. So library file storage path:/usr/local/lib/php/extensions/no-debug-non-zts-20131226, as follows:

PS: After modifying the php.ini configuration, remember to restart FPM Oh, otherwise the modification does not take effect.

1, Xcache

$ TAR-XVF Xcache-3.2.0.tar

$ CD xcache-3.2.0

$ sudo phpize

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

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

$ sudo make

$ sudo make install

Note:

--enable-xcache: includes support for XCache;

--enable-xcache-coverager: Additional characteristics of the indicator containing the measurement accelerator;

--enable-xcache-optimizer: Includes operation code optimization support;

Configuration:

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=1024m

Xcache.count =16

Xcache.slots =8k

Xcache.ttl=0

Xcache.gc_interval =0

xcache.var_size=16m

Xcache.var_count =1

Xcache.var_slots =8k

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 Open

Opcache.enable=1

; Open CLI

Opcache.enable_cli=1

; Available memory, as appropriate, in megabytes: Mb

opcache.memory_consumption=128

; Zend Optimizer + The total memory of the string in the staging pool. (Unit: MB)

Opcache.interned_strings_buffer=8

; For multiple cache file limits, you can try to increase this value by less than 100% of the hit rate.

opcache.max_accelerated_files=4000

; Opcache will check the file modification time within a certain time, here set the check time period, the default is 2, positioning for seconds

Opcache.revalidate_freq=60

; Turn on quick close to open this the memory recovery rate will increase when PHP Request shutdown

Opcache.fast_shutdown=1

Note:

After a lot of optimization processing and to ensure that the program itself is not a problem, just because too many operations can not be optimized, then consider using Xache, APC and other PHP accelerator to reduce the CPU parsing PHP file performance consumption problems

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:

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 do I monitor and debug my PHP program? The Xdebug extension library support is used here.

3, Mcrypt

$ tar libmcrypt-2.5.8.tar.gz

$ CD libmcrypt-2.5.8

$ 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:

Ini:

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

Iv. How to verify

1. Verifying PHP

Php–v

2. Verifying PHP Extension

There are two ways to verify the development of PHP:

Phpinfo () and php–m, here is an example of phpinfo () to illustrate the validation.

Xcache:

Xdebug:

Mcrypt:

V. Encounter problems

1, PHP Extension has been installed successfully, and has added php.ini configuration, also restarted fpm, but php–m or phpinfo () is not always displayed.

Workaround:

<? Phpinfo ()?> View configuration File (php.ini) path, which is the path that is currently in effect for the php.ini, then the problem is likely that you configured the php.ini path wrong.

2, PHP extension XCache has been installed and configured to complete, also restarted the FPM, but php–m or phpinfo () is not always displayed.

Workaround:

Modify Zend_extension=xxx to Extension=xxx because XCache is no longer supported with Zend_ after 3.0 Extension load xcache.so, but use extension load, that is, only xcache as an expansion of the library, for the acceleration of PHP is the use of zend_extension=xxx/opcache.so.

Note:

For the above PHP extension, it will be summarized in the following summary articles and instructions.

Vi. Additional content

We can use Php-config to view the relevant installation and configuration information for the current PHP:

$php-config--help

Description of the option (from the official website):

Options

Description

--prefix

Path prefixes installed by PHP, such as/usr/local

--includes

List all files included with-i option

--ldflags

The LD flag used by PHP at compile time

--libs

Libraries that are attached to PHP at compile time

--extension-dir

Default path for extension libraries

--include-dir

Default path prefix for header files

--php-binary

Full path to the PHP CLI or CGI executable file

--php-sapis

List all available SAPI modules

--configure-options

Reproduce the current PHP configuration options at compile time

--version

PHP Version number

--vernum

The PHP version number, expressed as an integer

In addition, sometimes we need to know whether the installation of the expansion requires installation dependencies or startup support, then you can use the following command query:

$./configure--help | grep extname (extended name)

PHP installation, configuration and extension summary

Related Article

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.