installation, configuration and optimization of Nginx and PHP (FastCGI) _php Tutorials

Source: Internet
Author: User
Tags php source code
Introduction and working principle of fastcgi the first simple introduction of the fastcgi:fastcgi is a language-independent, scalable structure of the CGI open extension, the main behavior is to keep the CGI interpreter in memory and thus achieve higher performance.   As we all know, the repeated loading of CGI interpreter is the main reason of poor CGI performance, if the CGI interpreter remains in memory and accepts the FASTCGI process manager scheduling, it can provide good performance, scalability, fail-over characteristics and so on. FastCGI works by: (1) The FASTCGI process Manager itself initializes, initiates multiple CGI interpreter processes (multiple php-cgi processes) and waits for a connection from the Web server. In the text, start multiple php-cgi fastcgi processes with the PHP-FPM process Manager.   When you start the php-cgi fastcgi process, you can configure both TCP and UNIX sockets to start. (2) When the client requests to reach the Web server (Nginx), the Web server forwards the request to the FASTCGI master process using TCP protocol or UNIX sockets, fastcgi the main process to select and connect to a CGI interpreter (child process).   The Web server sends CGI environment variables and standard input to the FASTCGI child process php-cgi. (3) fastcgi the standard output and error information back to the Web server (Nginx) from the same connection after the processing of the child process is complete. When the fastcgi child process closes the connection, the request tells the processing to complete. The fastcgi child process then waits and processes the next connection from the FASTCGI process management. In general CGI mode, php-cgi exits here. PHP-FPM php-fpm is a PHP fastcgi manager that is only for PHP and can be used in http://cn2.php.net/ downloads.php downloaded. PHP-FPM is actually a patch of PHP source code that is designed to integrate FASTCGI process management into a PHP package.   It must be patch into your PHP source code and can be used after compiling and installing PHP. The new version of PHP has been integrated PHP-FPM, is no longer a third-party package, recommended to use. PHP-FPM provides a better way to manage the PHP process, can effectively control memory and process, can be smooth overloaded PHP configuration, more than spawn-fcgi has more advantages, so by the official PHP included.   In./configure with the –ENABLE-FPM parameter can be opened PHP-FPM, the other parameters are configured PHP, the meaning of the specific options can be viewed here. Preparation before installation: Yum-y install gcc automake autoconf libtool make yum-y install gcc gcc-c++ glibc yum-y install Libmcrypt-devel mhash-devel Libxslt-devel \libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \zlib zlib-devel g libc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \ncurses ncurses-devel Curl curl-devel e2fsprogs e2fsprogs-devel \KRB 5 krb5-devel libidn libidn-devel OpenSSL openssl-devel new PHP-FPM installation (recommended installation method) Wget http://us1.php.net/get/ Php-5.5.10.tar.gz/from/this/mirrortar zvxf php-5.5.10.tar.gzcd php-5.5.10./configure--prefix=/usr/local/php-- ENABLE-FPM--with-mcrypt \--enable-mbstring--disable-pdo--with-curl--disable-debug--disable-rpath \-- Enable-inline-optimization--with-bz2--with-zlib--enable-sockets \--enable-sysvsem--enable-sysvshm--enable-pcntl --enable-mbregex \--with-mhash--enable-zip--with-pcre-regex--with-mysql--with-mysqli \--with-gd--with-jpeg-dir Make all install after completing PHP-FPM, configure the user to run it: CD/USR/LOCAL/PHPCP Etc/php-fpm.conf.defaUlt etc/php-fpm.confvi etc/php-fpm.conf Modify: User = Nginxgroup = Nginx If the Nginx user does not exist, then add the Nginx user Groupadd nginxuseradd-g ng first Inx nginx Modify nginx config file to support PHP-FPM # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000location ~ \.php$ {R Oot html; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_param script_filename $document _root$fastcgi_script_name;  Include Fastcgi_params;} Create the test PHP file to create the index.php file under/usr/local/nginx/html, enter the following: Start php-fpm and Nginx 12/usr/local/php/sbin/php-fpm/usr/local/nginx/nginx

http://www.bkjia.com/PHPjc/755758.html www.bkjia.com true http://www.bkjia.com/PHPjc/755758.html techarticle Introduction and working principle of fastcgi the first simple introduction of the fastcgi:fastcgi is a language-independent, scalable structure of the CGI open extension, the main behavior is to keep the CGI interpreter in memory ...

  • 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.