Linux PHP FastCGI

Source: Internet
Author: User
Tags apc fpm install openssl soap pear php server php script xsl

Linux PHP FastCGI

1 FastCGI
FastCGI: The Fast Universal Gateway Interface (Fast Common gateway interface/fastcgi) is a protocol that lets an interactive program communicate with a Web server.
FastCGI is like a resident (long-live) CGI, which can be executed all the time, so long as it is activated, it will not take a moment to fork it every time. It also supports distributed operations where the FastCGI program can execute and accept requests from other Web servers on hosts other than the Web server.
FASTCGI has the advantages of stability, safety, high performance and convenient expansion.
With Nginx, spawn-fcgi and fcgi, we can build a fastcgi framework with high concurrency and high performance. This article will analyze the frame construction process.

Summary of key features of fastcgi:
FastCGI is an interface or tool for communicating between HTTP servers and dynamic scripting languages
FastCGI the advantage of separating dynamic language parsing from the HTTP server
Nginx Apache and most dynamic languages support fastcgi
FastCGI interface mode with C/S Architecture, client (HTTP server), Service country side (Dynamic language resolution Server)
The PHP Dynamic Language service can initiate multiple fastcgi daemons, for example: PHP-FPM
The HTTP server communicates through (for example, Nginx Fastcgi_pass) FastCGI client and dynamic language FastCGI service-side communication, for example: PHP-FPM

Operating principle of fastcgi:
Nginx does not support direct invocation or parsing of external programs, and all external programs (including PHP) must be called through the FastCGI interface. The FastCGI interface is a socket under Linux (the socket can be either a file socket or an IP socket). In order to invoke a CGI program, you also need a fastcgi wrapper (wrapper can be understood as the program used to start another program), which is bound to a fixed socket, such as a port or a file socket. When Nginx sends the CGI request to the socket, through the FastCGI interface, the wrapper receives the request, and then derives a new thread, which invokes the interpreter or the external program to process the script and reads the return data; The wrapper then passes the returned data through the FastCGI interface, passing it to nginx along a fixed socket, and finally, Nginx sends the returned data to the client. This is the whole process of NGINX+FASTCGI's operation.

PHP Installation

2.1 PHP Source Installation
? Installation dependencies
First install the extension source yum install Epel-release-y
Yum install openssl-devel zlib-devel libjpeg-devel freetype-devel gd-devel libcurl-devel libxml2 libxml2-devel mcrypt Lib Mcrypt-devel Mhash-devel Libxslt-devel Libxslt–y

? Installing Libiconv-devel
Wget-c Http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz;tar XF libiconv-1.14.tar.gz &&\
CD libiconv-1.14;. /configure--prefix=/usr/local/libiconv&&make&&make Install

? Installing the Libmcrypt Library
Wget-c ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
Tar zxvf libmcrypt-2.5.7.tar.gz;cd libmcrypt-2.5.7/;. /configure &&make && make install &&/sbin/ldconfig

Compiling Ltdl
Wget-c ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
Tar zxvf libmcrypt-2.5.7.tar.gz;cd libmcrypt-2.5.7/libltdl/;. /configure--enable-ltdl-install &&make && make install

Modify so file reference location
echo "/usr/local/lib" >>/etc/ld.so.conf
Execution: Ldconfig

Wget-o/etc/yum.repo.d/epel.epo/HTTP

? Installing the Mhash Encryption Extension Library
wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
./configure;make;make Install

Yum Install Mhash mhash-devel-y

Rm-f/usr/local/libmcrypt.
Rm-f/usr/local/libmhash

? Install PHP 5.3.28

wget http://mirrors.sohu.com/php/php-5.3.28.tar.bz2; tar jxf php-5.3.28.tar.bz2
./configure--PREFIX=/USR/LOCAL/PHP5--with-config-file-path=/usr/local/php5/etc--with-apxs2=/usr/local/apache/ BIN/APXS--with-mysql=/usr/local/mysql/&&make &&make Install

? PHP 5.3 Configuration Parameters

./configure--prefix=/usr/local/php \
-WITH-MYSQL=MYSQLND \
-WITH-PDO-MYSQL=MYSQLND \
-with-iconv-dir=/usr/local/libiconv \
-with-freetype-dir \
-with-jpeg-dir \
-with-png-dir \
-with-zlib \
-with-libxml-dir=/usr/\
-enable-xml \
-enable-rpath \
-enable-safe-mode \
-enable-bcmath \
-ENABLE-SHMOP \
-enable-sysvsem \
-enable-inline-optimization \
-with-curl \
-with-curlwrappers \
-enable-mbregex \
-ENABLE-FPM \
enable-mbstring \
-with-mcrypt \
-WITH-GD \
-ENABLE-GD-NATIVE-TTF \
-WITH-OPENSSL \
-with-mhash \
-ENABLE-PCNTL \
-enable-sockets \
-WITH-XMLRPC \
-enable-zip \
-ENABLE-SOAP \
-enable-short-tags \
-enable-zend-multibyte \
-enable-static \
-with-xsl \
-with-fpm-user=nginx \
-with-fpm-group=nginx \
-ENABLE-CGI \
-ENABLE-FTP \
-with-ncurses

? Php5.5 Parameters:

./configure--prefix=/usr/local/php \
-WITH-MYSQL=MYSQLND \
-WITH-PDO-MYSQL=MYSQLND \
-with-iconv-dir \
-with-freetype-dir \
-with-jpeg-dir \
-with-png-dir \
-with-zlib \
-with-libxml-dir=/usr/\
-enable-xml \
-enable-rpath \
-enable-bcmath \
-ENABLE-SHMOP \
-enable-sysvsem \
-enable-inline-optimization \
-with-curl \
-enable-mbregex \
-ENABLE-FPM \
-enable-mbstring \
-with-mcrypt \
-WITH-GD \
-ENABLE-GD-NATIVE-TTF \
-WITH-OPENSSL \
-with-mhash \
-ENABLE-PCNTL \
-enable-sockets \
-WITH-XMLRPC \
-ENABLE-SOAP \
-enable-short-tags \
-enable-static \
-with-xsl \
-with-fpm-user=nginx \
-with-fpm-group=nginx \
-ENABLE-FTP \
-ENABLE-CGI \
-enable-opcache=no
&&make &&make Install

2.2 PHP Yum Installation

Yum List Installed | grep php

Delete the existing PHP version, execute the following command to delete PHP

Yum Remove Php-common

And then, like the installation, ask if you want to continue, enter Yes.

Add Yum Source

Source for CentOS 6.x

RPM-UVH http://download.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
RPM-UVH http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Source for CentOS 7.x

RPM-UVH http://ftp.iij.ad.jp/pub/linux/fedora/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
RPM-UVH http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

Install PHP

Yum Install--enablerepo=remi,remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysql Php-phpunit-phpunit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process PHP-GD Php-common

Note: Install version 5.6 for REMI-PHP56 and install version 5.5 for Remi-php55

View PHP version

3 PHP Services and Ports

Start:/USR/LOCAL/PHP/SBIN/PHP-FPM

Port: 127.0.0.1:9000

4 PHP configuration file

-------php-fpm.conf Master Process profile----------------------------------------------------------------------------

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

PID =/var/logs/php/php-fpm.pid
Error_log=/var/logs/php-fpm.log
Log_level=error
File Descriptor Size
rlimit_file=32768
Events.mechanism=epoll
Listen.owner=nginx
Listen.group=nginx
Number of child processes
pm.max_children=1024
Pm.start_servers=16
Idle Process
Pa.min_spare_servers=5
Pa.max_spare_servers=20
Free time
Pm.process_idle_timeout=15s
Maximum requests per child process
pm.max_requests=2048;
Access.format = "%R-%u%t \"%m%r%q%q\ "%s%f%{mili}d%{kilo}m%c%%"
slowlog=/var/log/php/$spool. Log.slow
request_slowlog_timeout=10
Php_admin_value[sendmail_path] =/usr/sbin/sendmail-t-i-f [email protected]

-----------php.ini Parsing Configuration------------------------------------------------------------------
CP Php-5.3.28/php.ini-production/usr/local/lib/php.ini

5 Optimizing the PHP server
Eaccelerator, APC, Xcache, Zend belong to a free open source php acceleration, optimization, compilation and dynamic cache project, similar to APC, by caching php compiled opcode code to improve the performance of PHP script execution.
The latest version available:
Https://codeload.github.com/eaccelerator/eaccelerator/legacy.tar.gz/master
TAR-XZF Master; cd
eaccelerator-eaccelerator-42067ac/;p hpize;
./configure--enable-eaccelerator=shared--with-php-config=/usr/bin/php-config
Make && make install
Then add the following code at the end of the/etc/php.ini:
extension= "/usr/lib64/php/modules/eaccelerator.so"

Eaccelerator.shm_size= "64"
Specifies the amount of shared memory that Eaccelerator can use, in megabytes.
"0" represents the operating system default, the default value is "0" and is generally set to 64 or 128

Eaccelerator.cache_dir= "/data/eaccelerator"
Directory of user disk caches. Eaccelerator stores pre-compiled code, session data, content, and so on in this directory. Same
Data can also be stored in shared memory (for faster access). The default value is "/tmp/eaccelerator".

eaccelerator.enable= "1"
Turn eaccelerator on or off. "1" is on, "0" is off. The default value is "1".

Eaccelerator.optimizer= "1"
Turning on or off the internal optimizer can improve code execution speed. "1" is on, "0" is off. The default value is "1".

Eaccelerator.check_mtime= "1"
Turn PHP file change checking on or off. "1" is on, "0" is off. If you want to recompile after a modification
The PHP program needs to be set to "1". The default value is "1".

eaccelerator.debug= "0"
Turn debug logging on or off. "1" is on, "0" is off. The default value is "0".

Eaccelerator.filter= ""
Determine which PHP files must be cached. You can specify the cached and non-cached file types (such as ". php . phtml", etc.), and if the arguments start with "!", the files that match those parameters are ignored by the cache. The default value is "", that is, all PHP files will be cached.

eaccelerator.shm_max= "0"
When you use the "eaccelerator_put ()" function, it is forbidden to store too large files in shared memory. This parameter specifies the maximum value that is allowed to be stored in bytes (10240, 10K, 1M). "0" is not limited. The default value is "0".

Eaccelerator.shm_ttl= "0"
When Eaccelerator gets the shared memory size of a new script fails, it removes all script caches that cannot be accessed in the last "Shm_ttl" seconds from shared memory. The default value is "0", which is: Do not delete any cache files from the share inner spring.

eaccelerator.shm_only= "0"
Allows or disables the caching of compiled scripts on disk. This option is not valid for session data and content caching. The default value is "0", which is: Use disk and shared memory for caching.

eaccelerator.compress= "1"
Allows or disables the compression of the content cache. The default value is "1", which is: Allow compression.

Eaccelerator.compress_level= "9"
Specifies the compression level of the content cache. The default value is "9", which is the highest level.

6 PHP Upgrade

下载源:

Follow the steps below.
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm-uvh remi-release-6. RPM epel-release-6. rpm
Set Source:
Vim/etc/yum.repos.d/remi.repo
To change all the enabled parameters to 1.
Execute command: Yum–enablerepo=remi update php mysql
Install PHP
Yum-y Update php*

7 PHP Fault Handling

7.1 Error:xslt-config not found. Please reinstall the LIBXSLT >= 1.1.0 distribution

Workaround: Yum Install Libxslt-devel

7.2 Error while loading shared Libraries:xxx.so.0:cannot open Shared object file:no such file or directory
Reason:
I can't find the libmysqlclient.so.18.
Ln-s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib64/

Workaround:
php-5.3.28]# Touch Ext/phar/phar.phar

In general, there are many so files that are/usr/local/lib this, so adding/usr/local/lib to the/etc/ld.so.conf can solve this problem.

After you/etc/ld.so.conf the file, you have to perform "/sbin/ldconfig–v" to update it before it takes effect.

Method 2:echo "/usr/local/lib" >>/etc/ld.so.conf
Execution: Ldconfig

7.3/usr/bin/ld:cannot Find-lltdl
Collect2:ld returned 1 exit status
Make: * * [SAPI/FPM/PHP-FPM] Error 1

Workaround: Install the Libmcrypt that implements the encryption feature. If you already have Yum installed, there is a Ltdl installation directory in this package that is compiled into this directory
Tar zxvf libmcrypt-2.5.8.tar.gz
CD libmcrypt-2.5.8/libltdl/
./configure--enable-ltdl-install
Make
Make install

7.4/data/tools/php-5.3.28/sapi/cli/php:error while loading shared Libraries:libltdl.so.3:cannot open Shared object fil E:no such file or directory
MAKE[1]: [Install-pear-installer] Error 127
Make:
[Install-pear] Error 2

Ln-s/usr/local/lib/libltdl.so.3/usr/lib/libltdl.so.3

echo "/usr/local/lib" >>/etc/ld.so.conf
Execution: Ldconfig

※※※※※※※※※ ※※※※※※※※※※※ cut ※※※※※※※※※※ line ※※※※※※

Linux PHP FastCGI

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.