FastCGI and PHP, FastCGIPHP

Source: Internet
Author: User

FastCGI and PHP, FastCGIPHP
What is CGI?

CGI is short for "Common Gateway Interface". It is a tool used for communication between HTTP servers and program services on other machines. CGI programs must run on network servers.

The main disadvantage of the traditional CGI interface method is poor performance, because every time the HTTP server encounters a dynamic program, it needs to restart the parser to execute the resolution, and then the result is returned to the HTTP server. This is almost impossible to handle high-concurrency access, so FastCGI was born. In addition, the security of traditional CGI interfaces is also poor.

What is FastCGI?

FastCGI is a scalable and fast interface for communication between the HTTP server and dynamic scripting language (FastCGI interface is socket in Linux (it can be a file socket, can also be an ip socket), the main advantage is to separate the dynamic language from the HTTP server. Most popular HTTP servers support FastCGI, including Apache, Nginx, and lightpd.

FastCGI is also supported by many scripting languages. One of the most popular scripting languages is PHP. FastCGI interface adopts the C/S architecture, which can separate the HTTP server and the script parsing server, and start one or more script parsing Daemon Processes on the script parsing server. When the HTTP server encounters a dynamic program, it can be directly delivered to the FastCGI process for execution, and then the structure is returned to the browser. This method allows the HTTP server to process static requests or return the results of the dynamic script server to the client, which greatly improves the performance of the entire application system.

Important features of FastCGI:

1. FastCGI is an interface or tool for communication between HTTP servers and dynamic scripting languages.

2. FastCGI separates Dynamic Language resolution from HTTP servers.

3. Nginx, Apache, Lighttpd, and most dynamic Languages Support FastCGI.

4. FastCGI interface adopts the C/S architecture, which can be divided into the client (HTTP server) and server (Dynamic Language Resolution Server ).

5. the PHP Dynamic Language server can start multiple FastCGI daemon processes.

6. The HTTP Server communicates with the dynamic language FastCGI server through the FastCGI client.

How Nginx FastCGI works

Nginx does not support direct calling or parsing of external dynamic programs. All external programs (including PHP) must be called through the FastCGI interface. In Linux, the FastCGI interface is a socket (either a file socket or an ip socket ). To call the CGI program, you also need a FastCGI wrapper, which is bound to a fixed socket, such as a port or file socket. When Nginx sends a CGI request to this socket, through the FastCGI interface, wrapper receives the request and then derives a new thread, this thread calls the interpreter or external program to process the script and read the returned data. Then, wrapper transmits the returned data to Nginx through the FastCGI interface along a fixed socket. Finally, nginx sends the returned data to the client, which is the entire operation process of Nginx + FastCGI.

The main advantage of FastCGI is to separate the dynamic language from the HTTP server, Nginx specifically handles static requests and forwards dynamic requests back, while the PHP/PHP-FPM server specifically parses PHP dynamic requests.

Check the lib library required for PHP installation

Php programs call some zlib and gb function libraries during development and running. Therefore, you need to install the following libraries.

Install libmcrypt library in libiconv library that cannot be installed on yum quick installation method: Install epel source install PHP dependency package install libicov

Same as above.

Install libmcrypt to install the mhash encryption extension Library

Mhash is an extension library based on discrete mathematics that cannot be reversed in php encryption mode. It is disabled by default. Mhash can be used to create verification values, message digests, message authentication codes, and key information persistence (such as passwords) in the original text.

Install the mcrypt encrypted extension Library

When writing a code program, PHP programmers should ensure the high performance of the code, but also ensure the security of the program. In addition to several built-in encryption functions, PHP also provides a more comprehensive PHP encryption extension library, mcrypt and mhash.

Install the PHPlnmp Server

Compile and install

 

The cannot find-lltdl solution requires the installation of libltdl.

Return to the PHP installation directory to query and compile PHP.

Create a soft connection

Mysql Server

Compile and install

 

Create a soft connection

Configure PHP engine configuration file php. ini configure PHP Service (FastCGI mode) profile php-fpm.conf

Specify pid path: pid =/app/logs/php-fpm.pid

Error Log Path for process management: error_log =/app/logs/php-fpm.log

Error Log Level: log_level = error

Main Process file descriptor: rlimit_files = 32768

Model: events. Mechanic = epoll

Users and groups:

Listen. owner = nginx

Listen. group = nginx

Maximum process count: pm. max_children = 1024

Number of started processes: pm. start_servers = 16

Minimum number of idle processes: pm. min_spare_servers = 5

Maximum number of idle processes: pm. max_spare_servers = 20

Timeout: pm. process_idle_timeout = 15 s;

Maximum request per process: pm. max_requests = 2048

Slow query: slowlog =/app/logs/$ pool. log. slow

Timeout: request_slowlog_timeout = 10

Email Address: php_admin_value [sendmail_path] =/usr/sbin/sendmail-t-I-f xxxxxxx@xxx.com

Start PHP

View port

Configure PHP and Nginx

Browser access

Configure PHP and MySQL

Deploy a BLOG program service

Https://cn.wordpress.org/

WordPress is an open-source free Blog (Blog, website) program developed using the PHP language and MySQL database. You can create a Blog site on a server that supports the PHP environment and MySQL database.

WordPress is a very powerful Blog system with many plug-ins, which is easy to expand. Installation and use are very convenient. Currently, WordPress has become a mainstream Blog building platform, and many publishing platforms are developed based on WordPress.

Create a dedicated database WordPress to store blog data.

Create a managed database WordPress user wordpress.

Deploy WordPress

Permission settings

Default directory permission: dir 755 root

Default file permission: file 644 root

User directory permission: dir nginx 755

User file Permission: file nginx 644

Browser http://blog.etiantian.org/index.php access

Follow the prompts to create a wp-config.php and then click "Install ".

View the installation result in the database

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.