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

Source: Internet
Author: User
Tags fpm net openssl php file php and php download php source code
The introduction and working principle of fastcgi first briefly introduces the following fastcgi:   fastcgi is a language-independent, scalable 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 interpreters is the main reason for the low performance of CGI, and if the CGI interpreter remains in memory and accepts FASTCGI process manager scheduling, it can provide good performance, scalability, fail-over characteristics, and so on. The work of   fastcgi is:   (1) fastcgi the process Manager itself, initiating multiple CGI interpreter processes (multiple php-cgi processes) and waiting for connections from the Web server. In the text, use the PHP-FPM process Manager to start multiple php-cgi fastcgi processes. When you start the php-cgi fastcgi process, you can configure both TCP and UNIX sockets to start up.   (2) When a client request reaches a Web server (Nginx), the Web server forwards the request to the FASTCGI main process using either a TCP protocol or a UNIX socket, fastcgi the main process to select and connect to a CGI interpreter (subprocess). The Web server sends CGI environment variables and standard input to the fastcgi subprocess php-cgi.   (3) returns the standard output and error information from the same connection to the Web server (Nginx) after the fastcgi process finishes processing. When the fastcgi process closes the connection, the request tells the processing to complete. The fastcgi process then waits and processes the next connection from the FASTCGI process management. In the general CGI model, php-cgi here.   PHP-FPM php-fpm is a PHP fastcgi manager that is used only in PHP and can be http://cn2.php.net/ downloads.php download. PHP-FPM is actually a patch of PHP source code, designed to integrate FASTCGI process management into the PHP package. It must be patch to your PHP source code and can be used only after compiling and installing PHP.   New PHP has been integrated PHP-FPM, no longer a third party package, recommended use. PHP-FPM provides a better way to manage PHP processes, can effectively control memory and process, can smooth overload PHP configuration, than spawn-fcgi has more advantages, so by the official PHP included. With the –ENABLE-FPM parameter when the./configureCan open php-fpm, the other parameters are configured PHP, the specific meaning of the options can be viewed here.   Pre-installation:     yum-y install gcc automake autoconf libtool make   yum-y install gcc gcc-c++ glibc &n Bsp Yum-y Install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype Freetype-dev El libxml2 libxml2-devel \ zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \ ncurses ncurses-devel C URL curl-devel e2fsprogs e2fsprogs-devel \ krb5 krb5-devel libidn libidn-devel OpenSSL new Openssl-devel installation (recommended installation method)     wget http://us1.php.net/get/php-5.5.10.tar.gz/from/this/mirror tar zvxf php-5.5.10.tar.gz cd php-5.5.10. /configure--prefix=/usr/local/php  --enable-fpm--with-mcrypt--enable-mbstring--disable-pdo- 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-mysql--with-mysqli \--with-gd--with-jpeg-dir   make all install after completing the PHP-FPM, configure the user to run it:   cd/usr/local/php CP Etc/php-fpm.conf.default etc/php-fpm.conf VI etc/php-fpm.conf   Modify: User = Nginx Group = nginx   If Nginx user does not save In, then first add nginx user groupadd nginx useradd-g nginx Nginx profile to support Nginx     # Pass the PHP php-fpm to scripts GI Server listening on 127.0.0.1:9000 location ~ \.php$ {    root html;     Fastcgi_pass 127.0.0.1:90 00;     Fastcgi_index index.php;     Fastcgi_param script_filename $document _root$fastcgi_script_name;     include fastcgi_params; Create a test php file   Create a index.php file under/usr/local/nginx/html, enter the following     <?php     echo phpinfo ();   Gt Start PHP-FPM and nginx   1 2/usr/local/php/sbin/php-fpm /usr/local/nginx/nginx  

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.